Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to implement this library into latest version of React Native. #21

Open
anshumanburman opened this issue Jul 13, 2020 · 2 comments

Comments

@anshumanburman
Copy link

I am trying to implements this library into my latest version 0.62.2 of react native but unable to use this libarary. please make this library updated.

@oojr
Copy link
Owner

oojr commented Jul 18, 2020

@anshumanburman on ios or android

@liran
Copy link

liran commented Sep 2, 2020

It can be used like this.

import React, { useState, useEffect } from 'react';
import { View, DeviceEventEmitter, Text, NativeModules } from 'react-native';

const BatteryManager = NativeModules.BatteryManager;

export default ({ style }) => {
  const [batteryLevel, setBatteryLevel] = useState(0);

  useEffect(() => {
    BatteryManager.updateBatteryLevel((info) => {
      setBatteryLevel(info.level);
    });

    const e = DeviceEventEmitter.addListener('BatteryStatus', ({ level }) => {
      setBatteryLevel(level);
    });
    return () => e.remove();
  }, []);

  return (
    <View style={[style]}>
      <Text>{batteryLevel}</Text>
    </View>
  );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants