Skip to content

Commit

Permalink
toggle camera
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiz Carlos committed Jul 3, 2024
1 parent 5a18291 commit 1ed399c
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ function FaceDetection(): JSX.Element {
autoScale,
setAutoScale
] = useState<boolean>( true )
const [
facingFront,
setFacingFront
] = useState<boolean>( true )
const faceDetectionOptions = useRef<FaceDetectionOptions>( {
performanceMode: 'fast',
classificationMode: 'all'
Expand All @@ -78,7 +82,7 @@ function FaceDetection(): JSX.Element {
isFocused &&
appState === 'active'
)
const cameraDevice = useCameraDevice( 'front' )
const cameraDevice = useCameraDevice( facingFront ? 'front' : 'back' )
//
// vision camera ref
//
Expand Down Expand Up @@ -247,24 +251,45 @@ function FaceDetection(): JSX.Element {
left: 0,
right: 0,
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between'
flexDirection: 'column'
} }
>
<Button
onPress={ () => setAutoScale( ( current ) => !current ) }
title={ `${ autoScale ? 'Disable' : 'Enable' } scale` }
/>
<View
style={ {
width: '100%',
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-around'
} }
>
<Button
onPress={ () => setFacingFront( ( current ) => !current ) }
title={ 'Toggle Cam' }
/>

<Button
onPress={ () => setCameraPaused( ( current ) => !current ) }
title={ `${ cameraPaused ? 'Resume' : 'Pause' } Cam` }
/>
<Button
onPress={ () => setAutoScale( ( current ) => !current ) }
title={ `${ autoScale ? 'Disable' : 'Enable' } Scale` }
/>
</View>
<View
style={ {
width: '100%',
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-around'
} }
>
<Button
onPress={ () => setCameraPaused( ( current ) => !current ) }
title={ `${ cameraPaused ? 'Resume' : 'Pause' } Cam` }
/>

<Button
onPress={ () => setCameraMounted( ( current ) => !current ) }
title={ `${ cameraMounted ? 'Unmount' : 'Mount' } Cam` }
/>
<Button
onPress={ () => setCameraMounted( ( current ) => !current ) }
title={ `${ cameraMounted ? 'Unmount' : 'Mount' } Cam` }
/>
</View>
</View>
</> )
}
Expand Down

0 comments on commit 1ed399c

Please sign in to comment.