Can't call camera takePictureAsync
See original GitHub issueHey, 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:
- Created 5 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.liak ajaann…