0

I need to launch the cropping window using react-native-image picker. But the below-mentioned code snippet not worked for me. Any suggestions

ImagePicker.launchImageLibrary(options, (response)  => {
        if (response.didCancel) {
          console.warn('Cancel photo picker');
        }
        else if (response.error) {
          console.warn('ImagePicker Error: ', response.error);
        }
        else {
          console.warn('ImagePicker no Error: ', response.error);
          ImagePicker.openCropper({
            path: response,
            width: deviceWidth,
            height: deviceWidth*5/4,
            cropperToolbarTitle: '',
            hideBottomControls: true,
            enableRotationGesture: true,
            avoidEmptySpaceAroundImage:true
         }).then(image => {
            this.props.navigation.navigate('ShowAllCroppedImage', {uri: response.uri, croppedImage: this.croppedImage.bind(this)});
          })
          .catch((err) => {
            console.log("openCropper error = " + err)
          });
        }
      });
    }
sejn
  • 2,040
  • 6
  • 28
  • 82

2 Answers2

0

You are using wrong library. The library you are using doesn't support cropping features.

Use react-native-image-crop-picker for selecting image from library and then cropping it.

Sanyam Jain
  • 1,154
  • 6
  • 9
  • I have used react-native-image-crop-picker (open cropper). Here I am getting ilegal call back invocation error – sejn Aug 19 '19 at 07:18
  • @sejn If you are using correct library, then there is no `launchImageLibrary` api in that library. – Sanyam Jain Aug 19 '19 at 08:07
  • Yes, that correct. My scenario is launching library in a class and redirecting to other screen and opening the cropping window from the launched library image. – sejn Aug 19 '19 at 10:02
0

Image cropper doesn't trigger because launchImageLibrary animation is still ending. With the picker modal still open, cropper modal fails to open correctly. If you want to use both libraries like this, you should call a separate function within launchImageLibrary callback. This function should use setTimeout and wait ~500ms, and then launch ImagePicker.OpenCropper. That is how we use both of these libraries successfully.

Eric T
  • 1