A client wants a paragraph of text in a React Native app, where there is inline text that is pressable. The problem is that I can't put hitSlop on a Text and if I use TouchableOpacity, it won't display inline with the text - each is its own block.
Here is what I've tried:
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Text style={ styles.text }>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi </Text>
<TouchableOpacity
onPress={ () => Alert.alert('howdy') }
hitSlop={ { top: 15, right: 15, bottom: 15, left: 15 } }
>
<Text style={ styles.buttonText }>ut aliquip ex ea commodo consequat.</Text>
</TouchableOpacity>
<Text style={ styles.text }>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
marginTop: 50,
flexDirection: 'row',
flexWrap: 'wrap',
},
text: {
flexWrap: 'wrap',
},
buttonText: {
color: 'red',
}
});
There is a snack here.
Is there a way to get some hitSlop on a Text? Or is there a way to get a TouchableOpacity inline with other text? In either case, the hitSlop would need to overlap the inert text that surrounds it.
Any ideas? Thanx.
Addendum: I forgot to mention that on Android, you can't have a View (which TouchableOpacity inherits) as a child of a Text. It works on iOS but not Android, which is unacceptable.