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 { 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={{ flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }}> <Text>Brightness Module Example</Text> </View> ); }
import * as Brightness from 'expo-brightness';
boolean
, indicating whether the Brightness API is available on the current device. Currently this resolves true
on iOS and Android only.Permissions.askAsync(Permissions.BRIGHTNESS)
.Permissions.getAsync(Permissions.BRIGHTNESS)
.Promise
that is resolved with a number between 0 and 1, inclusive, representing the current screen brightness.Promise
that is resolved when the brightness has been successfully set.Promise
that is resolved when the setting has been successfully changed.Promise
that resolves with true
when the current activity is using the system-wide brightness value, and false
otherwise.Promise
that is resolved with a number between 0 and 1, inclusive, representing the current system screen brightness.WARNING: This method is experimental.
MANUAL
. Requires SYSTEM_BRIGHTNESS
permissions.Promise
that is resolved when the brightness has been successfully set.BrightnessMode.MANUAL
or BrightnessMode.AUTOMATIC
. The system brightness mode cannot be set to BrightnessMode.UNKNOWN
.Promise
that is resolved when the brightness mode has been successfully set.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.nativeError
property of the thrown error for more information.SYSTEM_BRIGHTNESS
permissions.BrightnessMode.MANUAL
or BrightnessMode.AUTOMATIC
are allowed.