gpt4 book ai didi

javascript - 使用 View 作为按钮 - React Native

转载 作者:行者123 更新时间:2023-11-30 20:36:08 37 4
gpt4 key购买 nike

无论如何都可以使用 View 作为按钮吗?我有点不知道我在做什么。

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>
);

到目前为止,这就是我。我需要使用 View 作为按钮来重定向到 messageScreen。希望可以有人帮帮我。谢谢

最佳答案

您可以将 TouchableWithoutFeedback 放在 View 中,然后将导航功能放在 onPress 属性中。

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>
);

您可以使用 style Prop 来获得所需的样式。

编码愉快!

关于javascript - 使用 View 作为按钮 - React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49816182/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com