-2

How to put button just after text in react-native like on image below?

It should look like that:

TylerH
  • 20,799
  • 66
  • 75
  • 101
Mateusz Piwowarski
  • 559
  • 1
  • 6
  • 15

3 Answers3

1

You can use onPress prop in Text component. And use nested Text

You can try here: https://snack.expo.io/@vasylnahuliak/9a76b0

import React, { useState } from 'react';
import { Text, View, StyleSheet } from 'react-native';

const App = () => {
  const handleLinkPress = () => {
    alert('link pressed')
  }

  return (
    <View style={styles.container}>
      <Text>
        Short descriptopm for trainer: Lorem ipsum dolor sit amet, consectetur
        adipiscing elit, sed do eiusmod tempor incididunt ut labore.
        <Text style={styles.link} onPress={handleLinkPress}> edit </Text>
      </Text>
    </View>
  );
};

const styles = StyleSheet.create({
  link: {
    color: 'blue',
    fontWeight: 'bold',
  },
});

export default App;
Vasyl Nahuliak
  • 1,912
  • 2
  • 14
  • 32
0

You can use <TouchableOpacity></TouchableOpacity> for example. You just have to wrap your <Text>-Tag in it.

<TouchableOpacity> <Text> edit </Text> </TouchableOpacity>

TouchableOpacity has OnPress Events similar to a Button.

https://reactnative.dev/docs/touchableopacity

yesIamFaded
  • 1,970
  • 2
  • 20
  • 45
  • Can you write example on snack.expo.io? I guess this choice not working, because `TouchableOpacity` will be under text in this case. – Vasyl Nahuliak Jun 23 '21 at 09:04
-2

You can try with https://www.npmjs.com/package/react-native-render-html#making-your-custom-component-block-or-inline

Make edit button as an href link and you can get its onPress on onLinkPress prop