nativescript-camera-plus icon indicating copy to clipboard operation
nativescript-camera-plus copied to clipboard

Invalid camera object in loaded event

Open kryzys69 opened this issue 8 years ago • 4 comments

I don't know why I have invalid object in loaded event. It doesn't have any methods, that CameraPlus should have...

public camLoaded(e: any): void {
  console.log('***** cam loaded *****');
  this.cam = e.object as CameraPlus;
  let flashMode = this.cam.getFlashMode();
  ...

I've got: ERROR TypeError: this.cam.getFlashMode is not a function

this.cam object looks like a view, but it is not camera :|

It behaves the same in Genymotion emulator and real device.

kryzys69 avatar Apr 14 '18 08:04 kryzys69

What's your template look like?

bradmartin avatar Apr 14 '18 22:04 bradmartin

Sorry, I should have included it at the beginning...

<GridLayout class="page page-content" rows="*, auto" columns="*">

    <CameraPlus debug="true" 
        galleryPickerMode="single" 
        showFlashIcon="true" 
        showToggleIcon="true" 
        showCaptureIcon="true" 
        showGalleryIcon="true"
        (loaded)="camLoaded($event)" 
        (toggleCameraEvent)="toggleCameraEvent($event)" 
        (photoCapturedEvent)="photoCaptured($event)"
        (imagesSelectedEvent)="imagesSelectedEvent($event)">
        
        <!-- OVERLAY CONTENT-->
        <GridLayout rows="*, auto" columns="*">
            <Label class="timer-label" row="1" [text]="timerLabel"></Label>
        </GridLayout>

    </CameraPlus>
    
    <Button class="cancel-button" row="1" text="Anuluj" isEnabled="{{!cancelRequested && countdown > 1}}" (tap)="onCancelTap($event)"></Button>

</GridLayout>

but I've also tried your template and code from demo-ng... the same result.

when i look at the object in loaded event, one thing catches my eye: "_isAddedToNativeVisualTree": false, does it mean that it is not initialized properly?

kryzys69 avatar Apr 15 '18 07:04 kryzys69

Damn, it was this part that was missing... I've missed:

registerElement("CameraPlus", () => <any>CameraPlus);

Sorry :\

kryzys69 avatar Apr 15 '18 12:04 kryzys69

This should be added to the ng-demo example, or as a comment in the README, the problem is that i was assuming that the plugin was taking care of this, similar to camera permissions. Besides this small thing, the plugin works really well, great job

tnx author.

aosi87 avatar Apr 08 '20 15:04 aosi87