One Logo Pool Ball
wwwwwwwwwwwwwwwwwww

Brightness

App and system screen brightness

One.Brightness reads and writes the screen brightness: an app-level override on both platforms, plus the system brightness and mode on Android. Reach for it for video players, barcode scanners, and night modes that need the screen brighter or dimmer than the user’s setting.

On iOS app brightness reads and writes UIScreen on the main thread. On Android it sets the activity window attribute, while the system family reads and writes Settings.System. On web reads resolve 1, effects do nothing, permissions read denied, and listeners never fire.

Usage

import { useEffect } from 'react'
import { One } from 'one'
function useFullBrightness() {
useEffect(() => {
async function boost() {
const initial = await One.Brightness.get()
await One.Brightness.set(1)
return initial
}
const initial = boost()
return () => {
void initial.then((value) => One.Brightness.set(value))
}
}, [])
}

Saving the starting value and restoring it on unmount leaves the user’s brightness exactly as it was. Out-of-range values throw synchronously.

How it works

get and set move a number from 0 to 1. On iOS the setting persists until the device locks. On Android it applies to the current activity while the app is in the foreground. addListener receives { brightness } and fires on iOS only; the iOS simulator never posts brightness notifications for programmatic sets, so listeners stay quiet there while get still reads back every set.

The getSystem family is Android only. getSystem reads the global brightness, setSystem writes it and switches the mode to manual, getSystemMode resolves unknown, automatic, or manual, setSystemMode switches between manual and automatic, isUsingSystem reports whether the activity follows the system value, and restoreSystem drops the app override. On iOS these resolve the app value or the matching empty value (unknown mode, always using system) and change nothing.

System writes need the Android write-settings grant. Permissions resolve a granted, denied, or undetermined status with granted and can-ask-again flags; on iOS they resolve granted with no prompt. requestPermissions opens the system settings screen, so read the grant back when the app resumes. The manifest must also declare WRITE_SETTINGS, which prebuild does not stamp yet: grant it from the settings screen, or on dev builds with adb. Without the declaration and the grant, setSystem and setSystemMode reject with E_BRIGHTNESS_PERMISSIONS.

API reference

Methods: appTypeDescription
get() => Promise<number>The app brightness, 0 to 1.
() => Promise<number>The app brightness, 0 to 1.
set(value: number) => Promise<void>Set the app brightness. Out of range throws.
(value: number) => Promise<void>Set the app brightness. Out of range throws.
isUsingSystem() => Promise<boolean>Whether the app follows the system value.
() => Promise<boolean>Whether the app follows the system value.
restoreSystem() => Promise<void>Drop the app override.
() => Promise<void>Drop the app override.
isAvailable() => booleanWhether brightness reads work here.
() => booleanWhether brightness reads work here.
addListener(listener: (event: BrightnessEvent) => void) => BrightnessSubscriptionHear brightness changes. iOS only.
(listener: (event: BrightnessEvent) => void) => BrightnessSubscriptionHear brightness changes. iOS only.
Methods: systemTypeDescription
getSystem() => Promise<number>The global brightness. Android only.
() => Promise<number>The global brightness. Android only.
setSystem(value: number) => Promise<void>Write the global brightness, switching to manual.
(value: number) => Promise<void>Write the global brightness, switching to manual.
getSystemMode() => Promise<BrightnessMode>Unknown, automatic, or manual.
() => Promise<BrightnessMode>Unknown, automatic, or manual.
setSystemMode(mode: BrightnessMode) => Promise<void>Switch manual and automatic.
(mode: BrightnessMode) => Promise<void>Switch manual and automatic.
getPermissions() => Promise<BrightnessPermissionResponse>The write-settings grant, without prompting.
() => Promise<BrightnessPermissionResponse>The write-settings grant, without prompting.
requestPermissions() => Promise<BrightnessPermissionResponse>Open system settings for the grant.
() => Promise<BrightnessPermissionResponse>Open system settings for the grant.
PermissionTypeDescription
statusBrightnessPermissionStatusGranted, denied, or undetermined.
BrightnessPermissionStatusGranted, denied, or undetermined.
grantedbooleanWhether system writes may run.
booleanWhether system writes may run.
canAskAgainbooleanWhether settings may still grant it.
booleanWhether settings may still grant it.
EventTypeDescription
brightnessnumberThe new app brightness, 0 to 1.
numberThe new app brightness, 0 to 1.
SubscriptionTypeDescription
remove() => voidStop this listener.
() => voidStop this listener.

Platform differences

iOSAndroidWeb
App levelScreen APIWindow valueAlways 1
System levelApp valueGlobal valueAlways 1
ModeUnknownAuto or manualUnknown
EventsYesNeverNever
GrantAlways yesSettings pageDenied

Limits and gotchas

Examples

Brighten a scanner screen

import { useEffect } from 'react'
import { One } from 'one'
function useScannerBrightness() {
useEffect(() => {
async function boost() {
const initial = await One.Brightness.get()
await One.Brightness.set(1)
return initial
}
const initial = boost()
return () => {
void initial.then((value) => One.Brightness.set(value))
}
}, [])
}

Full brightness helps the camera freeze barcodes in dim aisles. The cleanup restores the exact prior value even when the screen unmounts mid-boost.

Dim for a night mode

import { useEffect } from 'react'
import { One } from 'one'
function useNightDim(night: boolean) {
useEffect(() => {
if (!night) return
async function dim() {
const initial = await One.Brightness.get()
await One.Brightness.set(0.2)
return initial
}
const initial = dim()
return () => {
void initial.then((value) => One.Brightness.set(value))
}
}, [night])
}

Tying the effect to the night flag restores brightness the moment night mode turns off or the screen unmounts, whichever comes first.

Edit this page on GitHub.