React native onPress不在嵌套视图中工作
我正在使用TouchableOpacity来处理点击。在上层视图中,一切都正常工作,但下面的两个容器视图不可点击。为了测试目的,我在单击它时设置了一个警报。下面的视图注释不起作用,我想这是因为嵌套不好 以下是代码:React native onPress不在嵌套视图中工作,react-native,onpress,React Native,Onpress,我正在使用TouchableOpacity来处理点击。在上层视图中,一切都正常工作,但下面的两个容器视图不可点击。为了测试目的,我在单击它时设置了一个警报。下面的视图注释不起作用,我想这是因为嵌套不好 以下是代码: return ( <View style={styles.container}> <View style={styles.subContainer}> <Text style={[styles.sto
return (
<View style={styles.container}>
<View style={styles.subContainer}>
<Text style={[styles.storyLikesAndShares, { marginRight: 17 }]}>
{this.state.likes} Likes
</Text>
<Text style={styles.storyLikesAndShares}>
{this.props.story.Shares ? this.props.story.Shares : 0} Shares
</Text>
</View>
<View style={[styles.subContainer, { paddingTop: 16 }]}>
<View style={styles.storyIconsContainer}>
<TouchableOpacity onPress={() => this.changeLikedState(this.props)}>
<Icon
style={[
this.props.story && this.state.isLiked
? styles.storyLikedIcon
: styles.storyNotLikedIcon,
{ marginRight: 24 }
]}
name={"heart"}
size={24}
/>
</TouchableOpacity>
<Icon style={styles.storyNotLikedIcon} name={"share"} size={24} />
//Code bellow is not working
<TouchableOpacity
onPress={() => alert('alertiiiing')}
>
{this.props.storyViewType === "feed" ? (
<Text
onPress={() => console.log('read more clicked')}
style={styles.storyReadMoreText}>Read Full Story...</Text>
) : (
<View />
)}
</TouchableOpacity>
</View>
</View>
</View>
);
}
}
返回(
{this.state.likes}喜欢
{this.props.story.Shares?this.props.story.Shares:0}个共享
this.changeLikedState(this.props)}>
//下面的代码不起作用
警报('alertiiing')}
>
{this.props.storyViewType==“提要”(
console.log('readmore clicked')}
style={styles.storyReadMoreText}>阅读完整故事。。。
) : (
)}
);
}
}