Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

enna-systems/react-native-sensor-ambient-light

Repository files navigation

react-native-sensor-ambient-light

React Native Module for android only to read ambient light sensors value

Installation

npm install react-native-sensor-ambient-light

Usage

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();
      };
    }
  }, []);

License

MIT


Made with create-react-native-library