jibon57 / nativescript-mediafilepicker

A complete file picker solution for NativeScript
Apache License 2.0
51 stars 39 forks source link

openFilePicker and openImagePicker is navigating to the same component #100

Closed jorgeeferreyra closed 4 years ago

jorgeeferreyra commented 4 years ago

Describe the bug

When I execute the openFilePicker or the openImagePicker method and I select a file (tapping the "done" button) it navigates to the same component (but in other instance) before the getFiles event triggers. That generates inconsistence between the state of both components.

To Reproduce Steps to reproduce the behavior:

Execute either openFilePicker or openImagePicker method and select a file.

Expected behavior A clear and concise description of what you expected to happen.

It must stay in the same component

NativeScript Info(please run tns info):

Getting NativeScript components versions information... ✔ Component nativescript has 6.3.3 version and is up to date. ✔ Component tns-core-modules has 6.3.2 version and is up to date. ✔ Component tns-android has 6.3.1 version and is up to date. ✔ Component tns-ios has 6.3.0 version and is up to date.

Sample Code(please provide minimum code to reproduce problem):

import { Mediafilepicker } from 'nativescript-mediafilepicker';

const USE_CAMERA = 'Use camera';
const PICK_IMAGE = 'Select image';
const PICK_PDF = 'Select PDF';
const CANCEL = 'Cancel';

..

methods: {
  async buildFilePickerOptions() {
    const modes = [USE_CAMERA, PICK_IMAGE, PICK_PDF];
    const mode = await action('Select one', CANCEL, modes);

    if (mode == CANCEL) return false;

    let options = {};

    if (mode == USE_CAMERA || mode == PICK_IMAGE) {
      options = {
        android: {
          isCaptureMood: mode == USE_CAMERA,
          isNeedCamera: true,
          maxNumberFiles: 1,
          isNeedFolderList: true
        },
        ios: {
          isCaptureMood: mode == USE_CAMERA,
          maxNumberFiles: 1
        }
      };
    } else {
      let extensions = [];

      if (platform.isIOS) {
        extensions = [kUTTypePDF];
      } else {
        extensions = ['pdf'];
      }

      options = {
        android: {
          extensions: extensions,
          maxNumberFiles: 1
        },
        ios: {
          extensions: extensions,
          multipleSelection: false
        }
      };
    }

    return {
      mode: mode,
      options: options
    };
  },
  async myMethod() {
    const result = await this.buildFilePickerOptions();

    if (!result) return;

    let mediafilepicker = new Mediafilepicker();
    mediafilepicker.on('getFiles', (res) => {
      // Handler
    });

    if (result.mode == PICK_PDF) {
      mediafilepicker.openFilePicker(result.options);
    } else {
      mediafilepicker.openImagePicker(result.options);
    }
  }
}
jorgeeferreyra commented 4 years ago

It was a problem with my code. Sorry!