React Native fixed footer

后端 未结 20 1507
南旧
南旧 2020-12-22 16:57

I try to create react native app that looks like existing web app. I have a fixed footer at bottom of window. Do anyone have idea how this can be achieved with react native?

相关标签:
20条回答
  • 2020-12-22 17:15

    Suggestion 1

    => Body with fixed footer

    <View style={{ flex: 1, backgroundColor: 'gray' }}>
    
            <View style={{ flex: 9, backgroundColor: 'gray',alignItems: 'center', justifyContent: 'center',  }}>
              <Text style={{color:'white'}}>...Header or Body</Text>
            </View>
    
    
            <View style={{ flex: 1, backgroundColor: 'yellow', alignItems: 'center', justifyContent: 'center', }}>
              <Text>...Footer</Text>
            </View>
    
    </View>
    

    Edit 2

    => Body & Fixed footer with tabs

    <View style={{ flex: 1, backgroundColor: 'gray' }}>
    
            <View style={{ flex: 9, backgroundColor: 'gray', alignItems: 'center', justifyContent: 'center', }}>
              <Text style={{ color: 'white' }}>...Header or Body</Text>
            </View>
    
    
            <View style={{ flex: 1, backgroundColor: 'yellow', alignItems: 'center', justifyContent: 'center', }}>
              <View style={{ flex: 1, flexDirection: 'row' }}>
                <TouchableOpacity style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'white' }}>
                  <View>
                    <Text>
                      ...Home
                  </Text>
                  </View>
                </TouchableOpacity>
                <TouchableOpacity style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'white' }}>
                  <View>
                    <Text>
                      ...Settings
                  </Text>
                  </View>
                </TouchableOpacity>
              </View>
            </View>
    </View>
    

    Notes

    import {TouchableOpacity} from 'react-native'
    

    Advantages

    We can use this simple footer without react bottom navigation

    0 讨论(0)
  • 2020-12-22 17:15

    i created a package. it may meet your needs.

    https://github.com/caoyongfeng0214/rn-overlaye

    <View style={{paddingBottom:100}}>
         <View> ...... </View>
         <Overlay style={{left:0, right:0, bottom:0}}>
            <View><Text>Footer</Text></View>
         </Overlay>
    </View>
    
    0 讨论(0)
  • 2020-12-22 17:16

    I'm using fixed footers for buttons in my app. The way I implement a fixed footer is like so:

    <View style={{flex: 1}}>
    <View><Text>my text</Text></View>
    <View style={{position: 'absolute', left: 0, right: 0, bottom: 0}}><Text>My fixed footer</Text></View>
    </View>
    

    And if need the footer to move up when a keyboard appears for instance you can use:

    const {  DeviceEventEmitter } = React
    
    class MyClass {
      constructor() {
         this.state = {
           btnLocation: 0
         }
      }
    
      componentWillMount() {
         DeviceEventEmitter.addListener('keyboardWillShow', this.keyboardWillShow.bind(this))
         DeviceEventEmitter.addListener('keyboardWillHide', this.keyboardWillHide.bind(this))
      }
    
      keyboardWillShow(e) {
        this.setState({btnLocation: e.endCoordinates.height})
      }
    
      keyboardWillHide(e) {
        this.setState({btnLocation: 0})
      }
    }
    

    Then use {bottom: this.state.btnLocation} in your fixed footer class. I hope this helps!

    0 讨论(0)
  • 2020-12-22 17:18

    You might also want to take a look at NativeBase (http://nativebase.io). This a library of components for React Native that include some nice layout structure (http://nativebase.io/docs/v2.0.0/components#anatomy) including Headers and Footers.

    It's a bit like Bootstrap for Mobile.

    0 讨论(0)
  • 2020-12-22 17:18

    The best way is to use justifyContent property

    <View style={{flexDirection:'column',justifyContent:'flex-end'}}>
         <View>
            <Text>fixed footer</Text>
        </View>
    </View>
    

    if you have multiple view elements on screen, then you can use

    <View style={{flexDirection:'column',justifyContent:'space-between'}}>
         <View>
            <Text>view 1</Text>
        </View>
        <View>
            <Text>view 2</Text>
        </View>
        <View>
            <Text>fixed footer</Text>
        </View>
    </View>
    
    0 讨论(0)
  • 2020-12-22 17:19

    For Android problems with this:

    in app/src/AndroidManifest.xml change windowSoftInputMode to the following.

    <activity
       android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
    

    I had absolutely no problems with this in ios using react-native and keyboardAwareScroll. I was about to implement a ton of code to figure this out until someone gave me this solution. Worked perfectly.

    0 讨论(0)
提交回复
热议问题