gpt4 book ai didi

react-native - 未定义不是对象(评估 '_reactNativeCamer.RNCamera.Constants'

转载 作者:行者123 更新时间:2023-12-01 05:54:55 26 4
gpt4 key购买 nike

我正在尝试 react-native-camera,我总是得到

Undefined is not an object (evaluating '_reactNativeCamer.RNCamera.Constants'



作为错误。

旧相机工作正常,只是新相机无法启动。

我只是复制粘贴了示例代码,但它似乎不起作用!它有什么问题?
import React, { Component } from 'react';
import {
View,
Text,
Dimensions,
StyleSheet,
TouchableOpacity
} from 'react-native';
import { RNCamera } from 'react-native-camera';

class Camera extends Component {
render() {
return (
<View style={styles.container}>
<RNCamera
ref={ref => {
this.camera = ref;
}}
type={RNCamera.Constants.Type.back}
permissionDialogTitle={'Permission to use camera'}
permissionDialogMessage={'We need your permission to use your camera phone'}
/>
<View style={{ flex: 0, flexDirection: 'row', justifyContent: 'center' }}>
<TouchableOpacity
onPress={this.takePicture.bind(this)}
style={styles.capture}
>
<Text style={{ fontSize: 14 }}> SNAP </Text>
</TouchableOpacity>
</View>
</View>
);
}
takePicture = async function() {
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options)
console.log(data.uri);
}
};
}

const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
backgroundColor: 'black'
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center'
},
capture: {
flex: 0,
backgroundColor: '#fff',
borderRadius: 5,
padding: 15,
paddingHorizontal: 20,
alignSelf: 'center',
margin: 20
}
});

export { Camera };

谢谢

最佳答案

您需要将此添加到文件 android/app/build.gradle

android {
...
defaultConfig {
...
missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
}
}

关于react-native - 未定义不是对象(评估 '_reactNativeCamer.RNCamera.Constants',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50177334/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com