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

前端 未结 13 2303
别跟我提以往
别跟我提以往 2020-12-13 23:37

Suppose this is the layout:


    
        ...
        ...
    
             


        
13条回答
  •  既然无缘
    2020-12-14 00:30

    import React from 'react'
    import { View, StyleSheet } from 'react-native'
    function moveToBottom(component) {
      return (
        
          {component}
        
      )
    }
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'flex-end',
        marginBottom: 36
      }
    })
    export default moveToBottom
    

    Now in our screen, we just need to import:

    import moveToBottom from 'library/utils/moveToBottom'

    and wrap our button:

    {
      moveToBottom(
         {
            this.props.navigation.navigate('Term')
          }} />
      )
    }
    

    I tested it and I approve it's the best option to respect the layout without having fixed things to bottom, which is not possible if you use react-native-web in addition of react-native, because people resize and elements overlap on each over.

    Source: https://medium.com/react-native-training/position-element-at-the-bottom-of-the-screen-using-flexbox-in-react-native-a00b3790ca42

提交回复
热议问题