30
loading...
This website collects cookies to deliver better user experience
View
encapsulating a couple of Text
elements, the child Text
elements will not inherit the textAlign
style property from View
.<View style={{ textAlign: 'center' }}>
<Text>Blah blah</Text> // this will not be center aligned!
<Text>Blah blah</Text> // this will not be center aligned!
</View>
Text
elements directly:<View>
<Text style={{ textAlign: 'center' }}>Blah blah</Text>
<Text style={{ textAlign: 'center' }}>Blah blah</Text>
</View>
Stylesheet
- still repetitive though;<View>
<Text style={styles.centerText}>Blah blah</Text>
<Text style={styles.centerText}>Blah blah</Text>
</View>
const styles = StyleSheet.create({
centerText: {
textAlign: 'center',
},
})
export const RegularCenterText = ({ style, children }: Props) => (
<Text style={[fontStyles.textReg, style]}>
{children}
</Text>
);
export const fontStyles = StyleSheet.create({
textReg: {
color: 'black,
fontSize: 16,
lineHeight: 24,
textAlign: 'center',
},
)
FlatList
or SectionList
allow us to do this easily by taking in a data array, and allowing us to define how to render a single item.hitSlop
. The name itself doesn't give a lot away, so I did some googling which opened up a whole new area of mobile development that I'm ashamed to say, had not crossed my mind at all.Pressable
component that allows you to define what happens onPress
but also onLongPress
lasting more than 500ms. The thing to consider here is what you're making "pressable". If it's a small word, e.g. "link", it might be difficult for the user to actually click on it depending on the size of their finger, what device they are using, magnification settings etc etc.hitSlop
. This allows us to sets the additional [rectangular] area around an element in which the interaction can still be detected. Read this document if you want to learn more.