How to use the expo-battery.addLowPowerModeListener function in expo-battery

To help you get started, we’ve selected a few expo-battery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo / apps / native-component-list / src / screens / BatteryScreen.tsx View on Github external
Battery.getBatteryStateAsync(),
        Battery.isLowPowerModeEnabledAsync(),
      ]);

      setIsAvailable(isAvailable && false);
      setBatteryLevel(batteryLevel);
      setBatteryState(batteryState);
      setLowPowerMode(lowPowerMode);
    })();
    const batteryLevelListener = Battery.addBatteryLevelListener(({ batteryLevel }) =>
      setBatteryLevel(batteryLevel)
    );
    const batteryStateListener = Battery.addBatteryStateListener(({ batteryState }) =>
      setBatteryState(batteryState)
    );
    const lowPowerModeListener = Battery.addLowPowerModeListener(({ lowPowerMode }) =>
      setLowPowerMode(lowPowerMode)
    );
    return () => {
      batteryLevelListener && batteryLevelListener.remove();
      batteryStateListener && batteryStateListener.remove();
      lowPowerModeListener && lowPowerModeListener.remove();
    };
  }, []);