React Native fixed footer

后端 未结 20 1565
南旧
南旧 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: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
    }
    

提交回复
热议问题