Expo module to control the device torch (flashlight): turn it on/off and adjust its brightness.
- iOS — continuous brightness via
AVCaptureDevice.setTorchModeOn(level:). - Android — on/off via
CameraManager.setTorchMode; adjustable brightness on Android 13+ (API 33) viaturnOnTorchWithStrengthLevel, with automatic on/off fallback on older devices. - Web — reports the torch as unavailable (control is not supported).
npx expo install expo-flashlightThis is a native module, so it requires a development build — it does not run in Expo Go.
import Flashlight from 'expo-flashlight';
if (Flashlight.isAvailable()) {
Flashlight.enable(); // turn on (last/full brightness)
Flashlight.setBrightness(0.5); // 50% brightness (0..1)
Flashlight.toggle(); // flip on/off, returns the new state
if (Flashlight.isOn) {
Flashlight.disable(); // turn off
}
}import Flashlight, { ExpoFlashlightModule } from 'expo-flashlight';
import { useEvent } from 'expo';
function TorchStatus() {
const state = useEvent(ExpoFlashlightModule, 'onTorchStateChanged');
// state?.enabled, state?.brightness
}Or imperatively:
const sub = Flashlight.addListener(({ enabled, brightness }) => {
console.log({ enabled, brightness });
});
// later
sub.remove();| Member | Type | Description |
|---|---|---|
isAvailable() |
boolean |
Whether the device has a controllable torch. |
isBrightnessControlAvailable() |
boolean |
Whether brightness can be adjusted (always on iOS with a torch; Android 13+ only). |
enable(brightness?) |
void |
Turn the torch on. Optional 0..1 brightness. |
disable() |
void |
Turn the torch off. |
toggle() |
boolean |
Toggle the torch; returns the new on/off state. |
set(on) |
void |
Set the torch on or off. |
setBrightness(level) |
void |
Set brightness 0..1. 0 turns the torch off. |
getBrightness() |
number |
Current brightness 0..1 (0 when off). |
isOn / isOff |
boolean (getter) |
Whether the torch is currently on/off. |
isEnabled() |
boolean |
Method form of isOn. |
addListener(cb) |
EventSubscription |
Subscribe to { enabled, brightness } changes. |
Below Android 13 the torch is on/off only, so setBrightness(level) turns the
torch on at full brightness for any level > 0. On Android 13+ the normalized
0..1 value is mapped to the device's discrete strength steps. Use
isBrightnessControlAvailable() to detect support.
This package uses Bun as its package manager.
bun install # install dependencies
bun run build # compile src/ -> build/
bun run lint # eslint
bun run test # run the Vitest suite once
bun run test:watchUnit tests live in src/__tests__/ and use Vitest. The
native module is mocked, so the tests cover the JavaScript wrapper logic
(brightness clamping, delegation, getters, event subscription) without a device.
MIT © Aziz Becha