nstudio / nativescript-camera-plus

MIT License
79 stars 50 forks source link

How to catch the photoCapturedEvent event properly ? #31

Open Scoottykun opened 6 years ago

Scoottykun commented 6 years ago

Hey there ! Firstly, thanks for your plugin, it's pretty useful in my project :)

I have an issue though, i can't manage to trigger the photoCapturedEvent event. Here is my code :

main-page.xml

<Page class="page" loaded="pageLoaded" actionBarHidden="true" xmlns:Cam="@nstudio/nativescript-camera-plus">
    <StackLayout id="main_layout" class="wrapper">
            <Cam:CameraPlus id="camera"
                            confirmPhotos="false"
                            saveToGallery="false"
                            showCaptureIcon="false"
                            showGalleryIcon="false"
                            showToggleIcon="false"
                            showFlashIcon="false"
                            loaded="camLoaded"
                            photoCapturedEvent="photoCapturedEvent"
                            debug="false">
            </Cam:CameraPlus>
        <Button text="Cheese" tap="takePicFromCam" row="1" col="0" class="btn btn-primary" />
    </StackLayout>
</Page>

main-page.js

var app = require("application");
var platform = require("platform");
var frameModule = require("tns-core-modules/ui/frame");
var permissions = require( "nativescript-permissions" );
var camera = require("nativescript-camera");
var imageModule = require("ui/image");
var fromAsset = require("tns-core-modules/image-source");
var CameraPlus = require("@nstudio/nativescript-camera-plus");
const createViewModel = require("./main-view-model").createViewModel;

exports.pageLoaded = function(args) {
    // using the view model as binding context for the current page
    const mainViewModel = createViewModel();
    page.bindingContext = mainViewModel;
};

exports.camLoaded = function(eventData) {
    alert('camera loaded !');
};

exports.takePicFromCam = function(eventData) {
    let page = frameModule.topmost().currentPage;
    let cam = page.getViewById("camera");
    cam.takePicture({ saveToGallery: false });
};

exports.photoCapturedEvent = function(eventData) {
    console.log('photo captured !');
};

Seems like photoCapturedEvent is never triggered in my case. Could you tell me what i'm doing wrong ?

Plus, All the photos i'm taking are stored in the gallery of my phone, even if i set the property "saveToGallery" to false in my view or in the "takePicture" method... any idea why ?

bradmartin commented 6 years ago

Your code looks okay so not really sure why the event doesn't fire for you 😕 - as for the saveToGallery false and still saving. Can you provide OS, Android/iOS version and so on to try and reproduce it? Thanks

gbatori commented 6 years ago

Hi!

You should register the photoCapturedEvent like this:

`public camLoaded(e: any): void { this.cam = this.camera.nativeElement; this.cam.saveToGallery = false; this.cam.on(CameraPlus.photoCapturedEvent, (event) => { this.photoCapturedEvent(event); });

public photoCapturedEvent(e: any): void { if (isAndroid) { console.log(e.data.android); // the path of the captured file, eg. "/storage/emulated/0/Android/data/COM.YOURAPP.NAME/files/IMG_1535045496885.jpg" } else { console.log(e.data.ios); } }`

konradkluzniak commented 6 years ago

Hi, @Scoottykun, were you able to fix this ? If yes, can you show me the code ? Thanks.

neumartin commented 5 years ago

Same issue heare, any update??

neumartin commented 5 years ago

Solved!, try to change:

const CameraPlus = require('@nstudio/nativescript-camera-plus'); by const CameraPlus = require('@nstudio/nativescript-camera-plus').CameraPlus;