I want to enable automatic brightness in my react native android app.
for example, user is able to enable automatic brightness when clicked to a button.
How can I do that?
CodePudding user response:
You can do it with this package expo-brightness
https://docs.expo.dev/versions/latest/sdk/brightness/#brightnesssetsystembrightnessmodeasyncbrightnessmode
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') {
// ANDROID ONLY
Brightness.setSystemBrightnessModeAsync(BrightnessMode.AUTOMATIC)
}
})();
}, []);
return (
<View style={styles.container}>
<Text>Brightness Module Example</Text>
</View>
);
}
If you use it outside expo project follow this instructions: https://github.com/expo/expo/tree/sdk-47/packages/expo-brightness