question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't call camera takePictureAsync

See original GitHub issue

Hey, i’m trying take a picture with vue-native

I have tried everything i can think of but every time i try to access the camera object i get undefined.

<template>
    <view class="camera">
        <view class="container">
            <button :on-press="openCamera" title="openCamera"></button>
        </view>
        <camera v-if="cameraSettings.show" :ref="camera" class="camera" :type="cameraSettings.type"/>
        <button :on-press="takePic" title="Snap"></button>
    </view>
</template>
import {Camera, Permissions} from "expo";
    import axios from 'axios';

    export default {
        data() {
            return {
                cameraSettings: {
                    show: false,
                    flash: 'off',
                    zoom: 0,
                    autoFocus: 'on',
                    type: Camera.Constants.Type.back,
                    whiteBalance: 'auto',
                    ratio: '16:9',
                    ratios: [],
                    barcodeScanning: false,
                    faceDetecting: false,
                    faces: [],
                    newPhotos: false,
                    permissionsGranted: false,
                    pictureSize: undefined,
                    pictureSizes: [],
                    pictureSizeId: 0,
                    showGallery: false,
                    showMoreOptions: false,
                },
            };
        },
        methods: {
            openCamera() {
                if (!this.cameraSettings.permissionsGranted) {
                    Permissions.askAsync(Permissions.CAMERA)
                        .then(status => {
                            this.cameraSettings.permissionsGranted = status.status === "granted";
                            this.cameraSettings.show = true;
                        }).catch((err) => {
                        this.cameraSettings.show = false;
                        console.log(err);
                    });
                } else {
                    this.cameraSettings.show = !this.cameraSettings.show;
                }
            },
            takePic(){
                console.log(this.camera); //undefined
                console.log(this.$refs.camera); //undefined
                console.log(Camera.takePictureAsync()); //undefined is not a function
                console.log(this.$refs.camera.takePictureAsync()); //undefined is not a function
            }
        },
        components: {Camera},
    };
.container {
        flex: 1;
        background-color: white;
        align-items: center;
        justify-content: center;
    }

    .camera {
        flex: 1;
    }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
neeraj-singh47commented, Sep 26, 2018

@nniicc Seems like you’ve used incorrect ref format while declaration. It should be just ref="camera". You need to remove the : before ref since it binds the variable with data.

0reactions
myhexacommented, Jul 25, 2021

Found the answer, <camera v-if="cameraSettings.show" :ref="camera" class="camera" :type="cameraSettings.type"/> should be <Camera v-if="cameraSettings.show" ref="camera" class="camera" :type="cameraSettings.type"/> typo on Camera and also remove : on ref (sorry for bad english)

Pak Tut Widi Memang Master

liak ajaann…

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native-camera (android): takePictureAsync() throws error
It appears that the camera will not resume on Android unless the RNCamera component has children. So if you change the example from...
Read more >
Using React Native Camera in your app - FullStack Labs
This function checks that we have a ref for our RNCamera component and that no picture is being processed currently. Next, it calls...
Read more >
Make a Camera App using React Native Expo (Android & IOS)
Your browser can't play this video. ... We have two types of cameras on our phone, front camera and back camera. ... takePictureAsync(null)...
Read more >
Expo Client App Crashes on Camera.takePictureAsync()
The android emulator crashes all the time when calling takePictureAsync (api 23, 25, 27 and 29). On the live app (standalone app with...
Read more >
React Native Mobile Apps, Integrating Expo Camera ...
React Native Mobile Apps, Integrating Expo Camera, Supabase Buckets and Image Upload#reactnative #supabase #imageupload #bucketsworking with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found