React Native Image Picker: null is not an object (evaluating 'ImagePickerManager.showImagePicker')

Iffat picture Iffat · Aug 5, 2019 · Viewed 8.6k times · Source

I installed react-native-image-picker according to the documentation. When I am trying to select the image from the phone (after hitting the button), the emulator is giving me this error- null is not an object (evaluating 'ImagePickerManager.showImagePicker')

My React native's version is 0.59.8

and image picker's version is 0.28.0

this the code-

import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  View,
  Image,
  Button
} from 'react-native';
import ImagePicker from "react-native-image-picker";

export default class App extends Component {

  state = {
    pickedImage: null
  }

  reset = () => {
    this.setState({
      pickedImage: null
    });
  }




pickImageHandler = () => {
    ImagePicker.showImagePicker({title: "Pick an Image", maxWidth: 800, maxHeight: 600}, res => {
      if (res.didCancel) {
        console.log("User cancelled!");
      } else if (res.error) {
        console.log("Error", res.error);
      } else {
        this.setState({
          pickedImage: { uri: res.uri }
        });

      }
    });
  }



       resetHandler = () =>{
            this.reset();
          }

  render() {
    return (
      <View style={styles.container}>
      <Text style={styles.textStyle}>Pick Image From Camera and Gallery </Text>
        <View style={styles.placeholder}>
          <Image source={this.state.pickedImage} style={styles.previewImage} />
        </View>
        <View style={styles.button}>

          <Button title="Pick Image" onPress={this.pickImageHandler} />

          <Button title="Reset" onPress={this.resetHandler} />

         </View>
      </View>
    );
  }
}

Answer

Anayo Oleru picture Anayo Oleru · Dec 11, 2019

I think there is a bug with the current version. I've experienced this, what I did was to uninstall the current version on the image-picker package, and installed the version @1.1.0:

Or you can simply downgrade your current version.

  1. npm uninstall react-native-image-picker

  2. npm install [email protected] --save

  3. react-native link react-native-image-picker

  4. cd ios

  5. pod install

  6. cd ..

Stop and re-run your Packager or Bundler

Then reset your cache

npm start --reset-cache