1

Is there anyway to use the view as button? Im kinda clueless of what Im doing.

return (
  <View style={styles.container}>
    <View style={styles.vicon} onClick={() => this.props.navigation.navigate('MessageScreen')}>
      <Image source={require('../misc/icon1.png')} style={styles.iicon} />
    </View>
    <View style={styles.vtexts} onClick={() => this.props.navigation.navigate('MessageScreen')}>
      <Text style={styles.tname}>{this.state.name}</Text>
      <Text style={styles.tmessage}>{this.state.message}</Text>
    </View>
  </View>
);

this is me so far. I need to use the view as a button to redirect to the messageScreen. Hope someone can help me. Thanksss

5

2 Answers 2

1

You can put TouchableWithoutFeedback inside the View and then put the navigate function in onPress prop.

return (
  <View style={styles.container}>
    <View style={styles.vicon}>
        <TouchableWithoutFeedback onPress={() => this.props.navigation.navigate('MessageScreen')}>
            <Image source={require('../misc/icon1.png')} style={styles.iicon} />
        </TouchableWithoutFeedback>
    </View>
    <View style={styles.vtexts}>
        <TouchableWithoutFeedback onPress={() => this.props.navigation.navigate('MessageScreen')}>
            <View>
              <Text style={styles.tname}>{this.state.name}</Text>
              <Text style={styles.tmessage}>{this.state.message}</Text>
            </View>
        </TouchableWithoutFeedback>
    </View>
  </View>
);

You can play around with the style prop to get the desired styling.

Happy Coding!

Sign up to request clarification or add additional context in comments.

2 Comments

As I know TouchableNativeFeedback is only for Android .
Thanks for pointing it out @oma, i have edited the answer now.
0

Just use TouchableOpacity. Is exactly what you need, check here the definition from react-native documentation:

A wrapper for making views respond properly to touches. On press down, the opacity of the wrapped view is decreased, dimming it.

You can find details here: https://facebook.github.io/react-native/docs/touchableopacity.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.