Skip to content

iOS: Should resolve after modal has dismissed #236

@mailiam

Description

@mailiam

Is there any particular reason that imagePicker.present() is resolved before dismissing?

Complicated modal chaining (ie. showing ImageCropper after imagePicker.present() in modal) is broken because QBImagePicker is not dismissed when resolved.

below example and error is just to represent process

example

// currently in modal 

async getCroppedImage() {
  const context = imagepicker.create();
  await context.authorize();
  const selections = await context.present();
  selections.forEach((selection) => {
    selection.getImageAsync(async source => {
      const imageSource = new ImageSource();
      imageSource.setNativeSource(source);
      const cropper = new ImageCropper();
      const cropped = await cropper.show(imageSource); // Error in this line
    });
  });
}

error

Warning: Attempt to present <TOCropViewController: 0x1059b0200> on < QBImagePickerController: 0x105839c00> whose view is not in the window hierarchy!

possible fix

I could fix below error by moving

this._resolve(assets);

to

        imagePickerController.dismissViewControllerAnimatedCompletion(true, () => {
           this._resolve(assets);

            // FIX: possible memory issue when picking images many times.
            // Not the best solution, but the only one working for now
            // https://github.com/NativeScript/nativescript-imagepicker/issues/222
            setTimeout(utils.GC, 200);
        });

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions