Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29639

React native camera stay black after component change

$
0
0

I am currently working on a react-native application.I would like to use the camera with the 'expo' package.

I manage to display the camera, but when I switch between my components (main menu component/ settings component) and I return to the camera component, the camera preview is black.

In fact it is the same problem as here: https://github.com/expo/expo/issues/5952

I used the proposed solution but it still doesn't work.

import React, { useState, useEffect } from 'react';import { Text, View, TouchableOpacity, Dimensions } from 'react-native';import { Camera } from 'expo-camera';import { useFocusEffect, useNavigation } from '@react-navigation/native';import { FontAwesome, Ionicons,MaterialCommunityIcons } from '@expo/vector-icons';import { withNavigationFocus } from 'react-navigation';import * as Permissions from 'expo-permissions'import styles from './styles';class CameraPage extends React.Component {  camera = null;  state = {      hasCameraPermission: null,  };  async componentDidMount() {      const camera = await Permissions.askAsync(Permissions.CAMERA);      const hasCameraPermission = (camera.status === 'granted');      this.setState({ hasCameraPermission });  };  render() {      const { hasCameraPermission } = this.state;      if (hasCameraPermission === null) {          return <View />;      } else if (hasCameraPermission === false) {          return <Text>Access to camera has been denied.</Text>;      }      else if (this.props.isFocused)      {        return (<View style={{ flex: 1 }}><Camera style={{ flex: 1 }} type={this.state.cameraType}></Camera><Text> IS FOCUS </Text></View>        )      }  };};export default withNavigationFocus(CameraPage);

The app launches by default in the camera component and the camera preview is displayedAs I have said, when I switch the component and come back to the camera the preview stays black,but the text 'IS FOCUS' is displayed so this.props.isFocused is true.

Therefore the problem comes from the camera itself. But I do not understand.

Any ideas where the problem comes from?


Viewing all articles
Browse latest Browse all 29639

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>