useFocusEffect() не хочет работать с useCallback()
settings.screen.js
import React, { useContext, useState} from "react";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useFocusEffect } from "@react-navigation/native";
const { onLogOut, user } = useContext(AuthenticationContext);
const [photo, setPhoto] = useState(null);
const getProfilePicture = async (currentUser) => {
const photoUri = await AsyncStorage.getItem(`${currentUser.uid}-photo`);
setPhoto(photoUri);};
useFocusEffect(
React.useCallback(() => {
getProfilePicture(user);
}, [user]));
camera.screen.js
import React, { useState, useEffect, useRef, useContext } from "react";
import { View, TouchableOpacity } from "react-native";
import { Camera } from "expo-camera";
//Components
import styled from "styled-components/native";
import { Text } from "../../../components/typography/text.component";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { AuthenticationContext } from "../../../services/authentication/authentication.context";
const ProfileCamera = styled(Camera)`
flex: 1;
width: 100%;
height: 100%;
`;
const InnerSnap = styled.View`
width: 100%;
height: 100%;
z-index: 999;
`;
const FlipCameraButton = styled(TouchableOpacity)`
margin-left: 20px;
margin-top: 20px;
justify-content: center;
width: 60px;
height: 60px;
`;
export const CameraScreen = ({ navigation }) => {
const [hasPermission, setHasPermission] = useState(null);
const [type, setType] = useState(Camera.Constants.Type.front);
const cameraRef = useRef();
const { user } = useContext(AuthenticationContext);
const snap = async () => {
if (cameraRef) {
const photo = await cameraRef.current.takePictureAsync();
AsyncStorage.setItem(`${user.uid}-photo`, photo.uri);
navigation.goBack();
}
};
useEffect(() => {
(async () => {
const { status } = await Camera.requestCameraPermissionsAsync();
setHasPermission(status === "granted");
})();
}, []);
if (hasPermission === null) {
return <View />;
}
if (hasPermission === false) {
return <Text variant="error">No access to camera</Text>;
}
return (
<ProfileCamera
ref={(camera) => (cameraRef.current = camera)}
type={type}
ratio={"16:9"}
>
<FlipCameraButton
onPress={() => {
setType(
type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back
);
}}
>
<Text variant="label">Flip</Text>
</FlipCameraButton>
<TouchableOpacity onPress={snap}>
<InnerSnap />
</TouchableOpacity>
</ProfileCamera>
);
};
при нажатии на иконку аватара открывается camera.screen.js, но не включаеться модуль камеры тоесть пустои скрин открывается.
Терминал выдаёт ошибку :
[Unhandled promise rejection: TypeError: _expoCamera.Camera.requestCameraPermissionsAsync is
not a function. (In '_expoCamera.Camera.requestCameraPermissionsAsync()', '_expoCamera.Camera.requestCameraPermissionsAsync' is undefined)]