Search code examples
cssreact-nativeflexboxreact-native-flexbox

Make an item stick to the bottom using flex in react-native


Suppose this is the layout:

<View style={styles.container}>
    <View style={styles.titleWrapper}>
        ...
        ...
    </View>
    <View style={styles.inputWrapper}>
        ...
        ...
    </View>

    <View style={styles.footer}>
        <TouchableOpacity>
            <View style={styles.nextBtn}>
                <Text style={styles.nextBtnText}>Next</Text>
            </View>
        </TouchableOpacity>
    </View>
</View>

I want to make the view with the styles of footer to position at the bottom of the screen. I tried giving the alignSelf property to the footer, but instead of positioning at the bottom, it positions it to the right side of the screen. How can I make the footer item stick to the end? Thank you.


Solution

  • In React Native, the default value of flexDirection is column (unlike in CSS, where it is row).

    Hence, in flexDirection: 'column' the cross-axis is horizontal and alignSelf works left/right.

    To pin your footer to the bottom, apply justifyContent: 'space-between' to the container