React native 如何在React Native中将图像作为导航参数传递

React native 如何在React Native中将图像作为导航参数传递,react-native,react-native-image-picker,React Native,React Native Image Picker,我正在使用图像选择器获取用户照片,然后我需要在下一个屏幕中显示它。 我怎样才能做到这一点 图像选择器功能: const options={ title: 'Profile picture', takePhotoButtonTitle: 'Take picture', chooseFromLibraryButtonTitle: 'Choose from gallery' } myFun=()=>{ ImagePicker.showImagePicker(op

我正在使用图像选择器获取用户照片,然后我需要在下一个屏幕中显示它。 我怎样才能做到这一点

图像选择器功能:

const options={
    title: 'Profile picture',
    takePhotoButtonTitle: 'Take picture',
    chooseFromLibraryButtonTitle: 'Choose from gallery'
}

myFun=()=>{
    ImagePicker.showImagePicker(options, (response) => {
        console.log('Response = ', response);

        if (response.didCancel) {
          console.log('User cancelled image picker');
        } else if (response.error) {
          console.log('ImagePicker Error: ', response.error);
        }
         else {
          const source = { uri: response.uri };

          // You can also display the image using data:
          // const source = { uri: 'data:image/jpeg;base64,' + response.data };

          this.setState({
            avatarSource: source,
          });
        }
      });
}
我需要使用此按钮将图像传递到下一个屏幕:

<GradientButton text='Next' onPress={() => {this.props.navigation.navigate('NextScreen', {photo: this.state.avatarSource} )}}/>
{this.props.navigation.navigate('NextScreen',{photo:this.state.avatarSource}}}/>
这就是我一直在尝试的方法,但我无法让它工作,我只能通过导航参数传递普通值,比如字符串。

{This.props.navigation.navigate('NextScreen'{photo:This.state.avatarSource}}}/>
<GradientButton text='Next' onPress={() => {this.props.navigation.navigate('NextScreen' {photo: this.state.avatarSource} )}}/>
看起来有一个语法错误,你必须在“NextScree”后面加一个逗号,这样它应该是

<GradientButton text='Next' onPress={() => {this.props.navigation.navigate('NextScreen', {photo: this.state.avatarSource} )}}/>
{this.props.navigation.navigate('NextScreen',{photo:this.state.avatarSource}}}/>
在下一个屏幕中,您可以使用
props.navigation.getParam('photo')
获取这些数据


希望有帮助。

事实上,这是我的错误,我可能在堆栈溢出中意外删除了问题中的逗号,但在我的代码中有逗号,我将修复问题中的逗号。顺便问一下,你确定这个方法可以传递图像吗?因为我完全按照你说的做了,我只能传递“简单”变量,比如字符串。我刚刚发现我可以使用NextScreen中的console.log()来打印有关图像的信息,并且它可以工作,唯一的问题是我不能在屏幕上显示它,例如,我需要查看图像的代码,这样我就可以判断它的错误。我假设您可能使用了错误类型的源对象。请在问题帖中添加图像渲染代码。