Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout a button from superview's bottom in react-native

I wanna render a button in react native like this:

enter image description here

Hear is my code :

    class Test extends Component {
      render() {
        return (
          <View>
            <TouchableHighlight style={{marginBottom:20,height:40,backgroundColor:'blue',justifyContent:'center'}}>
            <Text style={{alignSelf:'center',color:'white'}}>Login</Text>
            </TouchableHighlight>          
          </View>
        );
      }
   }

But the render result for mentioned above is :

enter image description here

How to modify my code?

like image 331
ZeroChow Avatar asked Jan 27 '26 20:01

ZeroChow


1 Answers

Use position: 'absolute' in this case, like:

loginButton: {
   position:'absolute',
   bottom: 0,
   height:40,
   backgroundColor:'blue',
   justifyContent:'center',
   width: width
 }

and render should be:

render() {
   return (
      <View style={styles.loginButton}>
         <TouchableHighlight>
            <Text style={styles.loginButtonText}>Login</Text>
         </TouchableHighlight>          
      </View>
   );
}

Here is the full working code: https://rnplay.org/apps/6qMTdA

like image 70
Ivan Chernykh Avatar answered Jan 30 '26 09:01

Ivan Chernykh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!