0

I have a code that picks an image from the gallery, i want after selecting an image to navigate to another component to display the selected image there, it's working fine until i navigate to the other component it's not displaying the selected image actually i don't know how should i display it there, help please, here is the code:

state = {
 image: null,
};

_pickImage = async () => {
  const { navigate } = this.props.navigation;

  let result = await ImagePicker.launchImageLibraryAsync({
   allowsEditing: false,
   aspect: [4, 4],
  });

  navigate('ConfirmImage');

if (!result.cancelled) {
  this.setState({ image: result.uri });
 }

To upload the image

let { image } = this.state;
<TouchableOpacity onPress={this._pickImage}><Text>Upload</Text></TouchableOpacity>
Judy M.
  • 243
  • 1
  • 4
  • 12

1 Answers1

0

To Display image in ConfirmImage screen

  1. you need to pass the image uri as a navigation parameter from the First screen.

 navigate(
  'ConfirmImage', 
  { uri : result.uri }
);
  1. Access the passed value in ConfirmImage.

//ConfirmImage.js 

 render() {
  const { navigation } = this.props;
  const uri = navigation.getParam('uri');

  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Image  style={{width: 50, height: 50}} source={{uri:uri}}/>
    </View>
  )
}
Mohammed Ashfaq
  • 3,353
  • 2
  • 15
  • 22