React Native Module for android only to read ambient light sensors value
npm install react-native-sensor-ambient-light
import { DeviceEventEmitter, Platform } from 'react-native';
import {
startUpdateLightSensor,
stopUpdateLightSensor,
} from 'react-native-sensor-ambient-light';
// ...
useEffect(() => {
if (Platform.OS === 'android') {
startUpdateLightSensor();
const subscription = DeviceEventEmitter.addListener(
'AmbientLightSensor',
(data: { lightValue: number; maxRange: number }) => {
console.log('light', data.lightValue);
console.log('maxRange', data.maxRange);
},
);
return () => {
stopUpdateLightSensor();
subscription?.remove();
};
}
}, []);
MIT
Made with create-react-native-library