react-native-vision-camera
react-native-vision-camera copied to clipboard
Open Flash light by click on the Icon
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
- [ ] I am using Expo
- [X] I have read the Troubleshooting Guide
- [X] I agree to follow this project's Code of Conduct
- [X] I searched for similar questions in the issues page as well as in the discussions page and found none.
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
- [ ] I am using Expo
- [x] I have read the Troubleshooting Guide
- [x] I agree to follow this project's Code of Conduct
- [x] I searched for similar questions in the issues page as well as in the discussions page and found none.
Why not have a state variable for the torch?
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
but why is it not a prop of the camera component? With this
So it should be something like torch={torch ? 'on' : 'off'}