Style
Can use nativewind for tailwindcss styling!
Basic
Pass in style object into style prop
Can pass in an array and the last in array will override/cascade like CSS
import { Button, StyleSheet, View } from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
buttonContainer: {
margin: 20
},
alternativeLayoutButtonContainer: {
margin: 20,
flexDirection: 'row',
justifyContent: 'space-between'
}
});
//....
<View style={styles.container}>
<View style={styles.buttonContainer}>
//.......
</View>
</View>
//....Layouts
Absolute
Can use position: absolute with top, right, bottom, and left
Flex
Parent element should have a width/height/flex defined or its size will be 0 and everything wont exist
Set flex:1 to tell View to expand to fit available space, different numbers mean take up that ratio of space compared to neighbors
Change flexdirection to row to do within that view
justifyContent => main-axis alignment like flex box
alignItems => cross-axis, stretch is default value
Parent Styles
flexGrow => default flex grow of children
flexShrink => default flex shrink of children
flexBasis => default size along main axis of children
Platform Specific
resizeMode
Cant pass className as a prop, need to do like myClassName or something(because nativewind works by transpiling className into actually passing a style prop)
Last updated