Fix the initial state for flashMode and torchMode #768
+8
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix for #518.
On Android, when passing an initial or static value for the
flashModeortorchModeprops that should result in the flash turning on, the value is not actually applied to the camera and the flash does not turn on. With a simple example such as:<Camera torchMode="on" />the flash/torch does not turn on. Similarly<Camera flashMode="on" />(or"auto"in a low-light environment) does not turn the flash on during photo capture. The same goes for a state variable with an initial value that should turn the flash on such as:However changing those values based on user input (i.e. using a state variable) or even a
setTimeout()in auseEffect()like one of the proposed workarounds in #518 after the camera has initialized does work.This PR resolves that issue by setting the
flashModeandtorchModeafter the camera has initialized.How did you test this change?
Tested on a few different Android devices using the examples above.