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

Cannot read property 'class' of undefined #11

Closed lord-zeus closed 5 years ago

lord-zeus commented 5 years ago

After passing the image I want to edit it return a TypeError: Cannot read property 'class' of undefined

PeterStaev commented 5 years ago

Hey @lord-zeus , make sure you are passing an actual image and refer to the working demos in this repo. If you still have problems provide a reproducible sample.

micflan commented 5 years ago

I'm seeing this same error reported on Android, whereas iOS is working fine.

I'm using nativescript-camera to take a photo, then retrieving the ImageSource from the camera's ImageAsset. Have also attempted to to load an image from storage and I have the same error.

Again, this seems to be affecting Android only.

import { ImageSource } from "tns-core-modules/image-source";
import { PhotoEditor } from "nativescript-photo-editor";
import { from } from "rxjs/internal/observable/from";
import { takePicture } from "nativescript-camera";

    public frontImageAction(): void {
        from(takePicture(this.cameraService.config))
            .pipe(switchMap((imageAsset) => from(new ImageSource().fromAsset(imageAsset))))
            .subscribe(
                (imageSource) => {
                    new PhotoEditor().editPhoto({ imageSource: imageSource })
                        .then((newImage: ImageSource) => this.frontImage = newImage)
                        .catch((e) => console.error(e));
                },
                (error) => this.handleAPIError(error)
            );
    }
PeterStaev commented 5 years ago

@micflan , can you also provide the stack trace of the error?

micflan commented 5 years ago

@PeterStaev –

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'class' of undefined
TypeError: Cannot read property 'class' of undefined
    at file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/nativescript-photo-editor/photo-editor.js:61:139
    at new ZoneAwarePromise (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:902:29)
    at PhotoEditor.editPhoto (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/nativescript-photo-editor/photo-editor.js:56:16)
    at SafeSubscriber._next (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/pages/registration/driving-licence.component.js:107:59)
    at SafeSubscriber.__tryOrUnsub (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/rxjs/internal/Subscriber.js:209:16)
    at SafeSubscriber.next (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/rxjs/internal/Subscriber.js:147:22)
    at Subscriber._next (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/rxjs/internal/Subscriber.js:90:26)
    at Subscriber.next (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/rxjs/internal/Subscriber.js:67:18)
    at SwitchMapSubscriber.notifyNext (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/rxjs/internal/operators/switchMap.js:86:26)
    at InnerSubscriber._next (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/rxjs/internal/InnerSubscriber.js:28:21)
    at InnerSubscriber.Subscriber.next (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/rxjs/internal/Subscriber.js:67:18)
    at file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/rxjs/internal/util/subscribeToPromise.js:7:24
    at ZoneDelegate.invoke (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:388:26)
    at Object.onInvoke (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/@angular/core/bundles/core.umd.js:17343:37)
    at ZoneDelegate.invoke (file:///data/data/com.goodtravelsoftware.sharecar.gtsuat/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:387:32)
PeterStaev commented 5 years ago

@micflan , seems the native android component of the plugin is not present in your project: https://github.com/PeterStaev/nativescript-photo-editor/blob/0d131213c432b0bdbd9078d7fffb9265ecdd4736/photo-editor.android.ts#L40 Try to do a tns platform clean android and make sure com.tangrainc.photoeditor.* is excluded from proguard.

micflan commented 5 years ago

@PeterStaev – I owe you a drink! That's fixed it. Guess I forgot to rebuild Android after I added the photo-editor. 🤦‍♂️

Thanks for taking the time to help!