【发布时间】:2019-10-08 02:07:17
【问题描述】:
我正在尝试获取存储在一个屏幕中的数组中的图像,并将其设置为另一个屏幕中图像的源。本质上,当用户触摸某个图像时,该精确图像将被带到下一个屏幕。问题是我收到一条错误消息undefined is not an object (evaluating 'navigation.getParam')
代码如下: 屏幕 1
this.state = {
messageItem: null,
chat: [{
convo: [Chat1, Chat2, Pic1, Chat4, Chat5, Chat6],
}]
}
openMessage = (bub) => {
this.setState({
messageItem: bub
});
console.log({ bub })
}
renderChat = () => {
return this.state.chat.map((bub, index) => {
return bub.convo.map((convo, i) => {
if (bub.convo[i])
return (
<Avatar
key={i}
size="medium"
containerStyle={{
marginRight: 15, shadowOpacity: 0.3,
shadowRadius: 2,
shadowColor: 'black'
}}
rounded
source={bub.convo[i]}
onPress={() => { this.openMessage({ convo: bub.convo[i] }) }
} />
)
})
})
}
renderChat = () => {
return this.state.chat.map((bub, index) => {
return bub.convo.map((convo, i) => {
if (bub.convo[i])
return (
<Avatar
key={i}
size="medium"
containerStyle={{
marginRight: 15, shadowOpacity: 0.3,
shadowRadius: 2,
shadowColor: 'black'
}}
rounded
source={bub.convo[i]}
onPress={() => { this.openMessage({ convo: bub.convo[i] }) }
} />
)
})
})
}
render(){
{ this.renderChat() }
{ this.state.messageItem && this.props.navigation.navigate('ChatScreen', { avatarPicture: this.state.messageItem.convo }) }
}
触摸头像会进入聊天界面,相关代码如下:
render() {
const { navigation } = this.props;
<Avatar
size="medium"
containerStyle={{ alignSelf: 'center', position: 'absolute', justifyContent: 'center', marginTop: 28 }}
rounded
source={navigation.getParam('avatarPicture')}
/>
}
【问题讨论】:
标签: react-native navigation expo