Skip to content

Commit e284cf0

Browse files
committed
Step 4: Get Camera device and start <Camera>
1 parent 67e6e24 commit e284cf0

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

App.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import React, {useEffect} from 'react';
22
import {Linking, StyleSheet, Text, useColorScheme, View} from 'react-native';
3-
import {useCameraPermission} from 'react-native-vision-camera';
3+
import {
4+
Camera,
5+
CameraPosition,
6+
useCameraDevice,
7+
useCameraPermission,
8+
} from 'react-native-vision-camera';
49

510
function App(): React.JSX.Element {
611
const isDarkMode = useColorScheme() === 'dark';
712
const {hasPermission, requestPermission} = useCameraPermission();
13+
const position: CameraPosition = 'front';
14+
const device = useCameraDevice(position);
815

916
useEffect(() => {
1017
if (!hasPermission) {
@@ -14,7 +21,15 @@ function App(): React.JSX.Element {
1421

1522
return (
1623
<View style={styles.container}>
17-
{!hasPermission && (
24+
{hasPermission ? (
25+
device != null ? (
26+
<Camera style={styles.camera} isActive={true} device={device} />
27+
) : (
28+
<Text style={styles.text}>
29+
Your phone does not have a {position} Camera.
30+
</Text>
31+
)
32+
) : (
1833
<Text style={styles.text} numberOfLines={5}>
1934
FaceBlurApp needs Camera permission.{' '}
2035
<Text style={styles.link} onPress={Linking.openSettings}>
@@ -32,6 +47,9 @@ const styles = StyleSheet.create({
3247
justifyContent: 'center',
3348
alignItems: 'center',
3449
},
50+
camera: {
51+
flex: 1,
52+
},
3553
text: {
3654
maxWidth: '60%',
3755
fontWeight: 'bold',

0 commit comments

Comments
 (0)