One Logo Pool Ball
wwwwwwwwwwwwwwwwwww

Light Sensor

Ambient light level in lux from the device light sensor

One.LightSensor reports the ambient light level on Android, with live updates. It has isAvailable(), setUpdateInterval(intervalMs), and addListener(fn).

import { One } from 'one'
if (One.LightSensor.isAvailable()) {
One.LightSensor.setUpdateInterval(1000)
const subscription = One.LightSensor.addListener(({ illuminance }) => {
console.log(illuminance)
})
// later: subscription.remove()
}

isAvailable() is synchronous. Each event is { illuminance, timestamp }: illuminance in lux (lx) and timestamp in seconds since boot. setUpdateInterval paces delivery on Android.

iOS exposes no public ambient light API, so the sensor reads unavailable there and listeners never fire. On web, the generic-sensor AmbientLightSensor supplies live lux where the browser has it (with a unix-seconds timestamp); without it the sensor reads unavailable and listeners never fire.

Edit this page on GitHub.