react-native-camera (android): takePictureAsync() throws error

后端 未结 1 437
天涯浪人
天涯浪人 2021-01-25 16:43

After calling takePictureAsync() from react-native-camera, i\'m getting this error:

{
  \"framesToPop\": 1,
  \"nativeStackAndroid\": [],
  \"userInfo\": null,
         


        
1条回答
  •  没有蜡笔的小新
    2021-01-25 17:28

    Try to use component as FaCC (Function as Child Components)! This way worked for me.

    const PendingView = () => (
      
        Waiting
      
    );
    
    class ExampleApp extends PureComponent {
      render() {
        return (
          
            
              {({ camera, status, recordAudioPermissionStatus }) => {
                if (status !== 'READY') return ;
                return (
                  
                     this.takePicture(camera)} style={styles.capture}>
                       SNAP 
                    
                  
                );
              }}
            
          
        );
      }
    
      takePicture = async function(camera) {
        const options = { quality: 0.5, base64: true };
        const data = await camera.takePictureAsync(options);
        //  eslint-disable-next-line
        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,
      },
    });
    

    0 讨论(0)
提交回复
热议问题