L4-ReactNativeLayout
L4-ReactNativeLayout
• https://github.com/anhhna/learning-react-native
Download Exercise
• https://github.com/anhhna/learning-react-native/
tree/master/solutions/l4_flexbox
Prepare ENV for making Android App by
React-Native on Windows
<Text>Hello World!</Text>
<Image
style={{height:100, width:100}}
source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
/>
<Text>Hello World!</Text>
<Image
style={{height:100, width:100}}
source={{uri: 'https://facebook.
github.io/react/img/logo_og.png'}}
/>
<Switch />
Basic Elements
iOS
<TextInput
style={{height:40, borderColor:
'gray', borderWidth: 1}}
value='Useless TextInput’
/>
<TextInput Android
multiLine={true}
numberOfLine={4}
style={{height:100, borderColor:
'gray', borderWidth: 1}}
value='Useless MultiLine TextInput’
/>
Basic Elements
iOS & Android: Default
<TouchableOpacity onPress={()=>{}}
style={{borderColor:'#f00',
backgroundColor:'#faa', borderWidth:
1, padding:10}}>
<Text>Touch me for Opacity!</Text>
</TouchableOpacity>
20 40
80 40 40 80
Height: 200
Margin
40 Padding
80
Width: 200
View: Red Box+ Text
40
Flex:1
Exercise I (5 min)
More CSS for
View
More CSS for Text
Flexbox Layout
• Flexbox => CSS Flexible Box Layout (in W3C Last Call
Working Draft)
Containers Items
• flexDirection • flex
• justifyContent • alignSelf
• alignItems
• flexWrap
Containers
• flexDirection
• justifyContent
• alignItems
• flexWrap
(Container)
FlexDirection
Horizontally
flexDirection: row;
Vertically
flexDirection: column;
Default flexDirection in React Native is column
(Container)
Justify Content
• Adding justifyContent to a
component's style determines
the distribution of children
along the primary axis.
• Default is flex-start
flexDirection: ‘column’,
justifyContent: ‘space-between’
(Container)
Align Items
• Adding alignItems to a
component's style determines
the alignment of children along
the secondary axis (if the
primary axis is row, then the
secondary is column, and vice
versa).
• Default is nowrap
nowrap vs wrap
Items
• flex
• alignSelf
(Item)
Fle
x
• “Flex” CSS syntax applied to item elements to tell how much they
can stretches inside their container by compares with its siblings.
• They equally divide all container’s space by the sum of flex values of
their children, then allocate space according to each child’s flex
score.
(Item)
Align
Self
https://facebook.github.io/react-native/docs/colors.html
Exercise II (10 min)
Exercise III (15 min)
Exercise IV (15 min)
Q/A