I have the following code using the Text
and Button
components from react-native-paper
:
<Text>See also </Text>
<Button mode="text" compact onPress={this.nav( name )}>Compass</Button>
<Text> on how to use the Compass.</Text>
When rendered this results in:
If I replace the Button
with TouchableOpacity
or alike the result looks like:
How can I style the Button
or TouchableOpacity
so it’s not offset in regard to the surrounding text?
UPDATE
Using the example from @RajendranNadar and after fixing so it runs on android:
See also <Pressable onPress={() => alert('Hello :)')}><Text style={styles.text}>Compass</Text></Pressable> on how to use the Compass.
results in
3
Answers
One way to accomplish this is to use nested texts. Something like this:
This is the best approach to using the
Pressable
component from the react-native packageCheck the live demo here https://snack.expo.dev/@raajnadar/pressable-example
Pressable component docs
this is full working example.