React Native fixed footer

后端 未结 20 1509
南旧
南旧 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:28
    import {Dimensions} from 'react-native'
    
    const WIDTH = Dimensions.get('window').width;
    const HEIGHT = Dimensions.get('window').height;
    

    then on the write this styles

     position: 'absolute',
     top: HEIGHT-80,
     left: 0,
     right: 0,
    

    worked like a charm

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

    You get the Dimension first and then manipulate it through flex style

    var Dimensions = require('Dimensions')
    var {width, height} = Dimensions.get('window')
    

    In render

    <View style={{flex: 1}}>
        <View style={{width: width, height: height - 200}}>main</View>
        <View style={{width: width, height: 200}}>footer</View>
    </View>
    

    The other method is to use flex

    <View style={{flex: 1}}>
        <View style={{flex: .8}}>main</View>
        <View style={{flex: .2}}>footer</View>
    </View>
    
    0 讨论(0)
  • 2020-12-22 17:29

    One could achieve something similar in react native with position: absolute

    let footerStyle = {
      position: 'absolute',
      bottom: 0,
    }
    

    There are a few things to keep in mind though.

    1. absolute positions the element relative to its parent.
    2. You might have to set the width and hight of the element manually.
    3. Width and hight will change when orientation changes. This has to be managed manually

    A practical style definition would look something like this:

    import { Dimensions } from 'react-native';
    
    var screenWidth = Dimensions.get('window').width; //full screen width
    
    let footerStyle = {
      position: 'absolute',
      bottom: 0,
      width: screenWidth,
      height: 60
    }
    
    0 讨论(0)
  • 2020-12-22 17:30

    Off the top of my head you could do this with a ScrollView. Your top-level container could be a flex container, inside that have a ScrollView at the top and your footer at the bottom. Then inside the ScrollView just put the rest of your app as normal.

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

    I think best and easy one would be as below, just place rest of ur view in a content and footer in a separate view.

    `<Container>
       <Content>
         <View>
          Ur contents
        </View>
      </Content>
      <View>
      Footer
      </View>
    </Container>`
    

    or u can use footer from native-base

    `<Container>
      <Content>
        <View>
    Ur contents
        </View>
      </Content>
    <Footer>
    Footer
    </Footer>
    </Container>`
    
    0 讨论(0)
  • 2020-12-22 17:36

    Set android:windowSoftInputMode="adjustPan" in your manifest file, and it will work as you expect.

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