React-native-image-crop-picker: Illegal callback invocation from native module.

Created on 1 Apr 2019  路  15Comments  路  Source: ivpusic/react-native-image-crop-picker

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.23.1
  • react-native v0.58.6

Platform

Tell us to which platform this issue is related

  • iOS

Expected behaviour

No crash.

Actual behaviour

Illegal callback invocation from native module. This callback type only permists a single invocation from native code.

Steps to reproduce

  1. Call openPicker()

  2. In the photo gallery, select a photo

  3. Cancel (which takes you back to the photo gallery)

  4. Cancel again (to go back to the calling app)

  5. Instead it crashes.

Attachments

function chooseFromLibrary(fireBaseLocation, maxDimensions, callback) {
ImagePicker.openPicker({
mediaType: "photo",
width: maxDimensions ? maxDimensions.x : 300,
height: maxDimensions ? maxDimensions.y : 300,
cropping: true,
})
.then((image) => ImageStorage.ProcessPhoto(fireBaseLocation, callback, image))
.catch((e) => {
console.log(e);
return callback(null);
});
}

function processPhoto(fireBaseLocation, callback, image) {
if ( image && image.path ) {
const firebaseManager = FirebaseManager.getInstance();
const source = {uri: image.path.replace('file://', ''), isStatic: true};

  firebaseManager.storeImage(fireBaseLocation, source.uri, (fileURL) => {
    if ( callback ) {
      if ( fileURL ) {
        callback({uri: fileURL, isStatic: true});
      } else {
        callback(null);
      }
    }
  })
} else {
  if ( callback ) {
    callback (null);
  }
}

}

Love react-native-image-crop-picker? Please consider supporting our collective:
馃憠 https://opencollective.com/react-native-image-crop-picker/donate

Most helpful comment

Possibly solved:

ImageCropPicker.m

// Crop image has been canceled.

  • (void)imageCropViewControllerDidCancelCrop:
    (RSKImageCropViewController *)controller {
    [self dismissCropper:controller selectionDone:NO completion:[self waitAnimationEnd:^{
    if (self.currentSelectionMode == CROPPING || [[self.options objectForKey:@"cropping"] boolValue]) {
    //self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
    }
    }]];
    }

I commented out the self.reject which will prevent the Promise from expiring too early. Is there a better way to solve this error?

All 15 comments

the same issue

the same issue

+1, wanna new version

same

same

I can confirm that this issue is still happening in RN 0.59.5 with 0.23.1.

Code:

ImagePicker.openPicker({
width: 300,
height: 400,
cropping: true
}).then(image => {
console.log(image);
}).catch((error) => {
alert(error)
});

It ignores my catch and causes the red warning screen to appear, with the error: Illegal callback from native module. This callback type only permits a single invocation from native code.

Seems like the problem could be occurring because the original Promise is already called when the user cancels the image selection, so there should be another Promise to deal with cancelling the entire viewcontroller.

https://medium.com/nycdev/calling-a-callback-multiple-times-in-a-react-native-module-5c3c61f2fca4

Can someone implement this?

Possibly solved:

ImageCropPicker.m

// Crop image has been canceled.

  • (void)imageCropViewControllerDidCancelCrop:
    (RSKImageCropViewController *)controller {
    [self dismissCropper:controller selectionDone:NO completion:[self waitAnimationEnd:^{
    if (self.currentSelectionMode == CROPPING || [[self.options objectForKey:@"cropping"] boolValue]) {
    //self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
    }
    }]];
    }

I commented out the self.reject which will prevent the Promise from expiring too early. Is there a better way to solve this error?

@joyshion's commit fixed this issue well

Any update here? Can I resolve this issue without forking? It's a giant problem for this library. User can't use cropper in the main case:

  1. Open album
  2. Choose some photo
  3. OOPS, wrong photo, Cancel cropper
  4. Repeat until success

@joyshion @howieyoung When can we expect this to be merged?

@cinnabarhorse very very thank you. i encountered this problem for three weeks. problem is solved. thank you for efforts.

For anyone coming here for a fix, one was released in 0.24.1 of this library!

amazing! thanks @simonmitchell

error is gone now, but it still throws a warning - 'unhandled promise rejection'

do you know how to get rid of that?

I am also facing the same issue when I launch image from Library and again try to crop the image. Here I need to click the choose twice and it shows the error as "Illegal callback invocation from the native module. This callback type only permits a single invocation from native code"

RN version is 0.58.4
I am using "react-native-image-crop-picker": "^0.22.0".

I have upgraded to the latest. Still facing the same issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

co-de picture co-de  路  3Comments

pavsidhu picture pavsidhu  路  3Comments

tximpa91 picture tximpa91  路  3Comments

Phenek picture Phenek  路  3Comments

phantom1299 picture phantom1299  路  3Comments