react-native - 用户定义的组件未在 react-native 中导致其他屏幕
问题描述
我有一个包含 Tile 的用户定义组件,我正在使用此组件使用 FlatList 填充第一个屏幕,当我使用导航道具单击 Tile 时尝试移动到下一个屏幕时出现问题。
尝试使用 this.props.navigation.navigate('next_screen') 但无法移动并得到错误 undefined is not an object(评估 '_this.props.navigation.navigate')
first_screen
<FlatList
data={[{key: 'a', imgSrc: require('./image.jpg')}]}
renderItem = {({item}) => <ImageContent sourceImage = { item } /> }
/>
ImageContent
export default class ImageContent extends React.Component {
_toPriceLayout = () => {
this.props.navigation.navigate('next_screen')
}
render() {
return (
<View style = {styles.content} >
<TouchableOpacity >
<Tile
imageSrc = {this.props.sourceImage.imgSrc}
title = {this.props.sourceImage.key}
onPress = {() => this._toPriceLayout()}
/>
</TouchableOpacity>
</View>
)
}
}
单击 ImageContent 时,它应该导航到 next_screen。
解决方案
推荐阅读
- ios - 将 cocoapods 用于 facebookSDK 时找不到“FBSDKAppEvents.h”文件
- plotly - plotly.js图例anc图表之间有过多的空白
- azure-devops - 如何在构建管道上“弹出”GUI?
- angular - 在服务中加载和重新加载数据
- php - 我如何在 wordpress 页面上打印 'bloginfo('url')'
- algorithm - 将多边形投影到边界框中
- java - 在使用 Streams API 时使用 Chronicle Map 产生垃圾
- gradle - Gradle 子项目中的测试看不到 Kotlin 内部可见性
- sql - 使用触发器将当前年份从一个表存储到另一个表
- kentico - 如何在 Kentico 12 页面类型中创建一对多关系?