mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
6.72k stars 1k forks source link

Open Flash light by click on the Icon #2846

Closed zoobibackups closed 3 weeks ago

zoobibackups commented 3 weeks ago

Question

how I open flash light when I click on Icon

What I tried

No response

VisionCamera Version

"react-native-vision-camera": "^4.0.1"

Additional information

zoobibackups commented 3 weeks ago

Question

how I open flash light when I click on Icon

What I tried

const toggleFlash =() => { cameraRef.current?.CameraDevice({ hasTorch: 'on' }) }

VisionCamera Version

"react-native-vision-camera": "^4.0.1"

Additional information

bruno-centanaro commented 3 weeks ago

Why not have a state variable for the torch?

zoobibackups commented 3 weeks ago

const [torch,setTorch] = useState(false); const toggleFlash =() => { cameraRef.current?.CameraDevice({ hasTorch: 'on', }) setTorch(!torch) } <Camera hasTorch={torch} ref={cameraRef} style={StyleSheet.absoluteFill} device={device} isActive={isActive} />

but error is that cameraRef.current.CameraDevice is not a function it is undefined

bruno-centanaro commented 3 weeks ago

but why is it not a prop of the camera component? With this So it should be something like torch={torch ? 'on' : 'off'}