concept alignitem in category react native

This is an excerpt from Manning's book React Native in Action.
5.3.4 Aligning children in a container with alignItems
alignItemsdefines how to align children along the secondary axis of their container. This property is declared on the parent view and affects its flex children just asflexDirectiondid. There are four possible values foralignItems:stretch,center,flex-start, andflex-end.
stretchis the default, used in figures 5.17 and 5.18. Each example component is stretched to fill its parent container. Figure 5.19 revisits figure 5.16 and shows what happens with the other options:center,flex-start, andflex-end. Because a precise width isn’t specified for the example components, they only take up as much space horizontally as is necessary to render their contents rather than stretching to fill the space. In the first case,alignItemsis set to'center'. In the second case,alignItemsis set to'flex-start'. And lastalignItemsis set to'flex-end'. Use listing 5.8 to change the alignments on each of the examples from listing 5.5.Listing 5.8 Using non-default
alignItemspropertiesrender() { return ( <View style={styles.container}> <View style={[styles.flexContainer, {alignItems: 'center'}]}> #1 <Example style={[styles.darkgrey]}>A 50%</Example> <Example>B 50%</Example> </View> <View style={[styles.flexContainer, {alignItems: 'flex-start'}]}> #2 <Example style={[styles.darkgrey]}>C 33%</Example> <Example style={{flex: 2}}>D 66%</Example> </View> <View style={[styles.flexContainer, {alignItems: 'flex-end'}]}> #3 <Example style={[styles.darkgrey]}>E 25%</Example> <Example style={{flex: 3}}>F 75%</Example> </View> </View> ); } #1 Changes the alignItems property to center #2 Changes alignItems to flex-start #3 Changes alignItems to flex-end !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":4,\"ch\":19},{\"line\":4,\"ch\":41}],[{\"line\":9,\"ch\":19},{\"line\":9,\"ch\":45}],[{\"line\":14,\"ch\":19},{\"line\":14,\"ch\":43}]]"} !@%STYLE%@!
With
alignSelf, you can access thealignItemsproperty for individual elements within the container. In essence,alignSelfgives you the ability to override whatever alignment was set on the parent container, so a child object can be aligned independently of its peers. The available options areauto,stretch,center,flex-start, andflex-end. The default value isauto, which takes the value from the parent container’salignItemssetting. The remaining properties affect the layout in the same way as their corresponding properties onalignItems.In figure 5.20, the parent container doesn’t have
alignItemsset, so it defaults tostretch. In the first example, theautovalue inheritsstretchfrom its parent container. The next four examples lay out exactly as you’d expect. The final example has noalignSelfproperty set, so it defaults toautoand is laid out the same as the first example.