0.1.2 • Published 2 years ago

react-native-sensor-ambient-light v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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