React-native-image-crop-picker: User cancelled image selection (Warning)

Created on 25 Oct 2017  路  4Comments  路  Source: ivpusic/react-native-image-crop-picker

Version

Tell us which versions you are using:

  • react-native-image-crop-picker : 0.18.1
  • react-native : 0.49.3

Platform

Tell us to which platform this issue is related

  • Android
    @ivpusic

Expected behavior

After opening the camera, if I don't take a photo, the application must not give a warning.
After opening the gallery, if I don't select a photo, the application must not give a warning.

Actual behavior

If I don't select the picture after opening the gallery, the application gives a warning.
If I don't take a photo after opening the camera, the application gives a warning.

Steps to reproduce

1.

2.

3.

Attachments

Possible Unhandled Promise Rejection (id: 0):
Error: User cancelled image selection
Error: User cancelled image selection
    at createErrorFromErrorData (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1787:15)
    at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1744:25
    at MessageQueue.__invokeCallback (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2097:16)
    at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1890:15
    at MessageQueue.__guard (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2028:9)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1889:13)
    at http://localhost:8081/debuggerWorker.js:72:58
console.warn @ YellowBox.js:78
onUnhandled @ Promise.js:35
onUnhandled @ rejection-tracking.js:71
(anonymous) @ JSTimers.js:256
_callTimer @ JSTimers.js:148
callTimers @ JSTimers.js:405
__callFunction @ MessageQueue.js:306
(anonymous) @ MessageQueue.js:108
__guard @ MessageQueue.js:269
MessageQueue.callFunctionReturnFlushedQueue @ MessageQueue.js:107
(anonymous) @ debuggerWorker.js:72

screenshot from 2017-10-25 16-26-16

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

Most helpful comment

yes, this is intended behavior. In case user canceled image selection, .catch block will be invoked. Just implement it and the warning should disappear.

All 4 comments

yes, this is intended behavior. In case user canceled image selection, .catch block will be invoked. Just implement it and the warning should disappear.

@ivpusic

private void imagePickerResult(Activity activity, final int requestCode, final int resultCode, final Intent data) {
        if (resultCode == Activity.RESULT_CANCELED) {
            return; // ----> **deleted this row**
        } else if (resultCode == Activity.RESULT_OK) {
            if (multiple) {
                ClipData clipData = data.getClipData();

                try {
                    // only one image selected
                    if (clipData == null) {
                        resultCollector.setWaitCount(1);
                        getAsyncSelection(activity, data.getData(), false);
                    } else {
                        resultCollector.setWaitCount(clipData.getItemCount());
                        for (int i = 0; i < clipData.getItemCount(); i++) {
                            getAsyncSelection(activity, clipData.getItemAt(i).getUri(), false);
                        }
                    }
                } catch (Exception ex) {
                    resultCollector.notifyProblem(E_NO_IMAGE_DATA_FOUND, ex.getMessage());
                }

            } else {
                Uri uri = data.getData();

                if (uri == null) {
                    resultCollector.notifyProblem(E_NO_IMAGE_DATA_FOUND, "Cannot resolve image url");
                    return;
                }

                if (cropping) {
                    startCropping(activity, uri);
                } else {
                    try {
                        getAsyncSelection(activity, uri, false);
                    } catch (Exception ex) {
                        resultCollector.notifyProblem(E_NO_IMAGE_DATA_FOUND, ex.getMessage());
                    }
                }
            }
        }
    }

deleting this part cause any problems ? @ivpusic
resultCollector.notifyProblem(E_PICKER_CANCELLED_KEY,E_PICKER_CANCELLED_MSG);

resultCollector.notifyProblem(E_PICKER_CANCELLED_KEY,E_PICKER_CANCELLED_MSG); is intended. Otherwise promise would resolve with empty result which is not what we want. If user cancelled image selection, or some error happened, .catch will be called with error.code property so you can know the reason why .catch was called

While user select image, some error happened. This situation app must give a warning. But
if the user canceled image selection, why app gives a warning? this situation app does not give a warning. am I right? @ivpusic

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Martian2Lee picture Martian2Lee  路  3Comments

tximpa91 picture tximpa91  路  3Comments

xuchao321 picture xuchao321  路  3Comments

leelandclay picture leelandclay  路  3Comments

habovh picture habovh  路  3Comments