Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async () => {
await Brightness.setBrightnessAsync(value);
this.updateBrightness();
};
}
function setBrightness(brightness: number) {
return setBrightnessAsync(brightness).then(() => setData(brightness));
}
_brightness = async () => {
if (!this.state.brightness) {
await Brightness.setBrightnessAsync(1);
} else {
await Brightness.useSystemBrightnessAsync();
}
this.state.brightness ? this.setState({ brightness: false }) : this.setState({ brightness: true });
}
return async () => {
await Brightness.setSystemBrightnessAsync(value);
this.updateBrightness();
};
}
(async () => {
const { status } = await Brightness.requestPermissionsAsync();
if (status === 'granted') {
Brightness.setSystemBrightnessAsync(1);
}
})();
}, []);
private async updateBrightness() {
this.setState({
normalBrightness: await Brightness.getBrightnessAsync(),
systemBrightness: await Brightness.getSystemBrightnessAsync()
});
}
}
function getBrightness() {
return getBrightnessAsync().then(setData);
}
This example uses both the Permissions and Brightness modules.
When you grant the SYSTEM_BRIGHTNESS permission, it renders two buttons to switch the system brightness mode.
{(permission && permission.status !== 'granted') && (
We need permission to modify the system brightness.
)}
{(permission && permission.status === 'granted') && (
<>
<button mode="{mode" color="#333"> setMode(BrightnessMode.AUTOMATIC)}
>
Automatic
</button>
<button mode="{mode" color="#333"> setMode(BrightnessMode.MANUAL)}
>
Manual
</button>
)}
onPress={() => setMode(BrightnessMode.AUTOMATIC)}
>
onPress={() => setMode(BrightnessMode.MANUAL)}
>