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.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

For managed apps, you'll need to run expo install expo-brightness. To use it in a bare React Native app, follow its installation instructions.

import React from 'react';
import { View, Text } from 'react-native';
import * as Brightness from 'expo-brightness';
import * as Permissions from 'expo-permissions';

export default class App extends React.Component {
  componentDidMount = async () => {
    const { status } = await Permissions.askAsync(Permissions.SYSTEM_BRIGHTNESS);
    if (status === 'granted') {
      Brightness.setSystemBrightnessAsync(1);
    }
  };

  render() {
    return (
      <View
        style={{
          flex: 1,
          backgroundColor: '#fff',
          alignItems: 'center',
          justifyContent: 'center',
        }}>
        <Text>Brightness Module Example</Text>
      </View>
    );
  }
}

import * as Brightness from 'expo-brightness';

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

Returns

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.

Arguments

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

Returns

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

Error Codes


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

Returns

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.

Returns

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

Error Codes


Android only. Gets the global system screen brightness.

Returns

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

Error Codes


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

Arguments

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

Returns

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

Error Codes

Android only. Gets the system brightness mode (e.g. whether or not the OS will automatically adjust the screen brightness depending on ambient light).

Returns

A Promise that is resolved with a BrightnessMode. Requires SYSTEM_BRIGHTNESS permissions.

Error Codes


Android only. Sets the system brightness mode.

Arguments

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

Returns

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

Error Codes

  • 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.

An error occurred when getting or setting the app brightness.

An error occurred when getting or setting the system brightness mode. See the nativeError property of the thrown error for more information.

An attempt to set the system brightness was made without the proper permissions from the user. The user did not grant SYSTEM_BRIGHTNESS permissions.

An error occurred when getting or setting the system brightness.

An invalid argument was passed. Only BrightnessMode.MANUAL or BrightnessMode.AUTOMATIC are allowed.