I'm working on my first react-native app, and am trying to wrap my head around layouts. Here is my code so far:
import React from 'react'
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native'
function App() {
return (
<View style={styles.container}>
<Text style={styles.text}>My App</Text>
<View style={styles.buttonContainer}>
<TouchableOpacity>
<Text>My Button</Text>
</TouchableOpacity>
</View>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
alignItems: 'center',
justifyContent: 'center'
},
text: {
fontSize: 45
},
buttonContainer: {
backgroundColor: 'gray',
paddingHorizontal: 20,
paddingVertical: 5
}
})
export default App
This renders as:
However, what I was hoping for was to vertically center the text, but push the button to the bottom, just slightly above it. Something like this:
I was able to get that output by adding:
position: 'absolute',
bottom: 50
to my buttonContainer
styles, but I feel like this isn't the right way to do it. Is there a proper flex
-y way to do this?