PeterStaev / nativescript-photo-editor

🎨 Easily edit an image in your NativeScript app (crop, draw, etc)
Apache License 2.0
47 stars 15 forks source link

[PhotoEditorControl] TypeError: Cannot read property "Draw" of undefined #26

Closed gabrielsmelo closed 5 years ago

gabrielsmelo commented 5 years ago

Hi,

I'm using this plugin in two applications. In the first one, I didn't needed to use the "hiddenControls" option. But in this second one, I need to hide some of them, but I'm being unable to do that because of a TypeError that seems to have no reason to happen, since I'm following demo code examples.

Here is an example based on the same code I'm using (NS-Vue):

import { PhotoEditor, PhotoEditorControl } from "nativescript-photo-editor";
import { fromFileOrResource } from 'tns-core-modules/image-source/image-source';

const photoEditor = new PhotoEditor();

export default {
   methods: {
      myAppEvent(){
         photoEditor.editPhoto({
               imageSource: imageSrc,
               hiddenControls: [
                  // PhotoEditorControl.Save,
                  // PhotoEditorControl.Clear,
                  PhotoEditorControl.Draw
                  // PhotoEditorControl.Text,
               ],
            }).then( (newImage) => {
               this.$store.dispatch('user/saveAvatarImg', newImage);
               this.$router.goBack();
            }).catch((error) => {
               console.log(error);
            });
      }
   }
}

NS-Vue sends me the following log after attempting to use the photoEditor:

"TypeError: Cannot read property 'Draw' of undefined"

PeterStaev commented 5 years ago

Hi @gabrielsmelo , I guess the problem comes, because from the little I know Vue is not TS based, so it cannot work with the TS const enums. So you will have to use the respective int values for the controls you want to hide, as defined here: https://github.com/PeterStaev/nativescript-photo-editor/blob/d0e047120962de77e1a32cc88a54bfce1b3265f4/photo-editor.d.ts#L15-L23

gabrielsmelo commented 5 years ago

Thank you @PeterStaev . It helped a lot, and its working now. I Hope this issue can help other NS-Vue developers. o/