A library to access the devices' flashlight.
In order to install this package, you need to have a project created with Expo.
For bare React Native projects, you must ensure that you
have installed and configured the expo
package before
continuing.
Once you have your project ready, you can install the package using the following command:
npm install @drakexorn/expo-torchstate
To be able to use the library, you need to import it in your file:
import {useTorch} from '@drakexorn/expo-torchstate';
Then, you can use the useTorch
hook to access the flashlight. For example :
export default function SeeTorchState() {
const [torchOn, setTorchStatus] = useTorch();
return (
<View style={styles.container}>
<Text>Flashlight turned {torchOn ? "on" : "off"}</Text>
<Pressable style={styles.button} onPress={() => setTorchStatus(currentState => !currentState)}>
<Text>Toggle flashlight</Text>
</Pressable>
</View>
);
}
The hook provides a boolean value representing the current state of the flashlight and a function to toggle it.
Contributions are very welcome! Please refer to guidelines described in the contributing guide.
Thanks to the following people who have contributed to this project:
- Christophe Bernard - Initial work - @drakexorn
- Tinaël Devresse - Suggestions - @hunteroi
This project has been built using create-expo-module
, thanks to the Expo team for providing this tool.
This project is licensed under the MIT License - see the LICENSE file for details.