-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathAnimatedCameraView.tsx
More file actions
64 lines (55 loc) · 1.46 KB
/
AnimatedCameraView.tsx
File metadata and controls
64 lines (55 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React from 'react';
import { CameraView, useCameraPermissions, CameraViewProps } from 'expo-camera';
import { Button, StyleSheet, Text, View } from 'react-native';
import Animated, {
AnimateProps,
useAnimatedProps,
} from 'react-native-reanimated';
const AnimatedCameraView = Animated.createAnimatedComponent(CameraView);
interface CameraProps extends Omit<CameraViewProps, 'zoom'> {
ref?: React.RefObject<
React.Component<AnimateProps<CameraViewProps>, any, any>
>;
zoom: Animated.SharedValue<number>;
}
const Camera = ({ ref, ...props }: CameraProps) => {
const [permission, requestPermission] = useCameraPermissions();
const animatedProps = useAnimatedProps(() => {
return {
zoom: props.zoom.value - 1,
};
});
if (!permission) {
return <View />;
}
if (!permission.granted) {
return (
<View style={styles.container}>
<Text style={{ textAlign: 'center' }}>
We need your permission to show the camera
</Text>
<Button onPress={requestPermission} title="Grant permission" />
</View>
);
}
return (
<View style={styles.container} pointerEvents="none">
<AnimatedCameraView
ref={ref}
style={styles.camera}
facing={props.facing}
animatedProps={animatedProps}
/>
</View>
);
};
export default Camera;
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
camera: {
flex: 1,
},
});