ionic-team / pwa-elements

Quality UI experiences for Web APIs that require custom UI (such as media/camera).
https://medium.com/@maxlynch/building-the-progressive-web-app-os-57daebcb69c1
MIT License
168 stars 50 forks source link

Camera breaks on modal close on web #94

Closed guypeer8 closed 2 years ago

guypeer8 commented 3 years ago

image

Resources: Before submitting an issue, please consult our docs.

Stencil version: (run npm list @stencil/core from a terminal/cmd prompt and paste output below):

photo-gallery-capacitor-react@2.0.0 /Users/guypeer/Desktop/projects/ventures/tabs
└── (empty)

I'm submitting a ... (check one with "x") [x] bug report

Current behavior: Currently on the web (chrome), when opening the camera modal and closing, the application breaks.

Expected behavior: Expect the code not to break :) just close the modal and the device camera.

Steps to reproduce: demo

Related code:

insert any relevant code here
  const takePhoto = async () => {
    const cameraPhoto = await Camera.getPhoto({
      resultType: CameraResultType.Uri,
      source: CameraSource.Camera,
      quality: 100,
    }); 
    const fileName = `${new Date().getTime()}.jpeg`;
    const savedFileImage = await savePicture(cameraPhoto, fileName);
    const newPhotos = [savedFileImage, ...photos];
    setPhotos(newPhotos);
    Storage.set({ key: PHOTO_STORAGE, value: JSON.stringify(newPhotos) });
  };
jcesarmobile commented 2 years ago

That's Capacitor's Camera plugin rejecting the promise with an error, it's the same error iOS and Android platforms return when you cancel the native dialogs. Whenever you call a Capacitor plugin you should put the code in a try-catch to catch possible errors the plugins return https://github.com/ionic-team/capacitor-testapp/blob/main/src/pages/Camera.tsx#L42-L58

That error screen is provided by react while in development mode, it won't appear in release mode. Can also be disabled in development mode, but it's helpful to see errors that otherwise you could miss https://stackoverflow.com/questions/46589819/disable-error-overlay-in-development-mode