Android Device | Android Emulator | iOS Device | iOS Simulator | Web |
---|---|---|---|---|
→
expo install expo-brightness
If you're installing this in a bare React Native app, you should also follow these additional installation instructions.
import React, { useEffect } from 'react'; import { StyleSheet, View, Text } from 'react-native'; import * as Brightness from 'expo-brightness'; export default function App() { useEffect(() => { (async () => { const { status } = await Brightness.requestPermissionsAsync(); if (status === 'granted') { Brightness.setSystemBrightnessAsync(1); } })(); }, []); return ( <View style={styles.container}> <Text>Brightness Module Example</Text> </View> ); } %%placeholder-start%%const styles = StyleSheet.create({ ... }); %%placeholder-end%%const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, });
import * as Brightness from 'expo-brightness';
Name | Type | Description |
---|---|---|
options (optional) | PermissionHookOptions<object> | - |
Check or request permissions to modify the system brightness.
This uses both requestPermissionAsync
and getPermissionsAsync
to interact with the permissions.
const [status, requestPermission] = Brightness.usePermissions();
[null | PermissionResponse, RequestPermissionMethod<PermissionResponse>, GetPermissionMethod<PermissionResponse>]
Gets the current brightness level of the device's main screen.
Promise<number>
A Promise
that fulfils with a number between 0
and 1
, inclusive, representing the
current screen brightness.
Checks user's permissions for accessing system brightness.
A promise that fulfils with an object of type PermissionResponse.
Gets the global system screen brightness.
Promise<number>
A Promise
that is resolved with a number between 0
and 1
, inclusive, representing
the current system screen brightness.
Gets the system brightness mode (e.g. whether or not the OS will automatically adjust the screen brightness depending on ambient light).
A Promise
that fulfils with a BrightnessMode
. Requires
SYSTEM_BRIGHTNESS
permissions.
Returns whether the Brightness API is enabled on the current device. This does not check the app permissions.
Promise<boolean>
Async boolean
, indicating whether the Brightness API is available on the current device.
Currently this resolves true
on iOS and Android only.
Returns a boolean specifying whether or not the current activity is using the system-wide brightness value.
Promise<boolean>
A Promise
that fulfils with true
when the current activity is using the system-wide
brightness value, and false
otherwise.
Asks the user to grant permissions for accessing system brightness.
A promise that fulfils with an object of type PermissionResponse.
Name | Type | Description |
---|---|---|
brightnessValue | number | A number between 0 and 1 , inclusive, representing the desired screen
brightness. |
Sets the current screen brightness. On iOS, this setting will persist until the device is locked, after which the screen brightness will revert to the user's default setting. On Android, this setting only applies to the current activity; it will override the system brightness value whenever your app is in the foreground.
Promise<void>
A Promise
that fulfils when the brightness has been successfully set.
Name | Type | Description |
---|---|---|
brightnessValue | number | A number between 0 and 1 , inclusive, representing the desired screen
brightness. |
WARNING: This method is experimental.
Sets the global system screen brightness and changes the brightness mode to
MANUAL
. Requires SYSTEM_BRIGHTNESS
permissions.
Promise<void>
A Promise
that fulfils when the brightness has been successfully set.
Name | Type | Description |
---|---|---|
brightnessMode | BrightnessMode | One of BrightnessMode.MANUAL or BrightnessMode.AUTOMATIC . The system
brightness mode cannot be set to BrightnessMode.UNKNOWN . |
Sets the system brightness mode.
Promise<void>
Resets the brightness setting of the current activity to use the system-wide brightness value rather than overriding it.
Promise<void>
A Promise
that fulfils when the setting has been successfully changed.
Acceptable values are: 'never'
, number
.
Acceptable values are: PermissionHookBehavior
, Options
.
Name | Type | Description |
---|---|---|
canAskAgain | boolean | - |
expires | PermissionExpiration | - |
granted | boolean | - |
status | PermissionStatus | - |
UNKNOWN
- Means that the current brightness mode cannot be determined.BrightnessMode.UNKNOWN = 0
AUTOMATIC
- Mode in which the device OS will automatically adjust the screen brightness depending on the
ambient light.BrightnessMode.AUTOMATIC = 1
MANUAL
- Mode in which the screen brightness will remain constant and will not be adjusted by the OS.BrightnessMode.MANUAL = 2
DENIED
PermissionStatus.DENIED = "denied"
GRANTED
PermissionStatus.GRANTED = "granted"
UNDETERMINED
PermissionStatus.UNDETERMINED = "undetermined"
nativeError
property of the thrown error for more information.SYSTEM_BRIGHTNESS
permissions.BrightnessMode.MANUAL
or BrightnessMode.AUTOMATIC
are allowed.