Expo

Documentation

Brightness

An API to get and set screen brightness.
On Android, there is a global system-wide brightness setting, and each app has its own brightness setting that can optionally override the global setting. It is possible to set either of these values with this API. On iOS, the system brightness setting cannot be changed programmatically; instead, any changes to the screen brightness will persist until the device is locked or powered off.

Gets the current brightness level of the device's main screen.

A Promise that is resolved with a number between 0 and 1, inclusive, representing the current 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.

  • brightnessValue (number) - A number between 0 and 1, inclusive, representing the desired screen brightness.

A Promise that is resolved when the brightness has been successfully set.

  • ERR_BRIGHTNESS - An unexpected OS error occurred when trying to set the brightness. See the nativeError object for more information.

Android only. Resets the brightness setting of the current activity to use the system-wide brightness value rather than overriding it.

A Promise that is resolved when the setting has been successfully changed.

Android only. Returns a boolean specifying whether or not the current activity is using the system-wide brightness value.

A Promise that resolves with true when the current activity is using the system-wide brightness value, and false otherwise.

  • ERR_BRIGHTNESS - An unexpected OS error occurred when trying to set the brightness. See the nativeError object for more information.

Android only. Gets the global system screen brightness.

A Promise that is resolved with a number between 0 and 1, inclusive, representing the current system screen brightness.

  • ERR_BRIGHTNESS_SYSTEM - An unexpected OS error occurred when trying to get the system brightness. See the nativeError object for more information.

WARNING: This method is experimental.
Android only. Sets the global system screen brightness and changes the brightness mode to MANUAL. Requires SYSTEM_BRIGHTNESS permissions.

  • brightnessValue (number) - A number between 0 and 1, inclusive, representing the desired screen brightness.

A Promise that is resolved when the brightness has been successfully set.

  • ERR_BRIGHTNESS_PERMISSIONS_DENIED - The user did not grant SYSTEM_BRIGHTNESS permissions.
  • ERR_BRIGHTNESS_SYSTEM - An unexpected OS error occurred when trying to set the system brightness. See the nativeError object for more information.

await Permissions.askAsync(Permissions.SYSTEM_BRIGHTNESS);

const { status } = await Permissions.getAsync(Permissions.SYSTEM_BRIGHTNESS);
if (status === 'granted') {
  Brightness.setSystemBrightnessAsync(1);
}

Android only. 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 is resolved with a BrightnessMode. Requires SYSTEM_BRIGHTNESS permissions.

  • ERR_BRIGHTNESS_MODE - An unexpected OS error occurred when trying to get the brightness mode. See the nativeError object for more information.

Android only. Sets the system brightness mode.

  • brightnessMode (BrightnessMode) - One of BrightnessMode.MANUAL or BrightnessMode.AUTOMATIC. The system brightness mode cannot be set to BrightnessMode.UNKNOWN.

A Promise that is resolved when the brightness mode has been successfully set.

  • ERR_INVALID_ARGUMENT - An invalid argument was passed. Only BrightnessMode.MANUAL or BrightnessMode.AUTOMATIC are allowed.
  • ERR_BRIGHTNESS_MODE - An unexpected OS error occurred when trying to set the brightness mode. See the nativeError property of the thrown error for more information.
  • ERR_BRIGHTNESS_PERMISSIONS_DENIED - The user did not grant SYSTEM_BRIGHTNESS permissions.

  • BrightnessMode.AUTOMATIC - Mode in which the device OS will automatically adjust the screen brightness depending on the ambient light.
  • BrightnessMode.MANUAL - Mode in which the screen brightness will remain constant and will not be adjusted by the OS.
  • BrightnessMode.UNKNOWN - Means that the current brightness mode cannot be determined.

CodeDescription
ERR_BRIGHTNESSAn error occurred when getting or setting the app brightness.
ERR_BRIGHTNESS_MODEAn error occurred when getting or setting the system brightness mode.
ERR_BRIGHTNESS_PERMISSIONS_DENIEDAn attempt to set the system brightness was made without the proper permissions from the user.
ERR_BRIGHTNESS_SYSTEMAn error occurred when getting or setting the system brightness.