How to use expo-battery - 10 common examples

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
function getBatteryStateString(batteryState: Battery.BatteryState): string {
  switch (batteryState) {
    case Battery.BatteryState.UNPLUGGED:
      return 'UNPLUGGED';
    case Battery.BatteryState.CHARGING:
      return 'CHARGING';
    case Battery.BatteryState.FULL:
      return 'FULL';
    case Battery.BatteryState.UNKNOWN:
    default:
      return 'UNKNOWN';
  }
}
github expo / expo / apps / native-component-list / src / screens / BatteryScreen.tsx View on Github external
export default function BatteryScreen() {
  const [isAvailable, setIsAvailable] = React.useState(null);
  const [batteryLevel, setBatteryLevel] = React.useState(-1);
  const [batteryState, setBatteryState] = React.useState(Battery.BatteryState.UNKNOWN);
  const [lowPowerMode, setLowPowerMode] = React.useState(false);

  React.useEffect(() => {
    (async () => {
      const [isAvailable, batteryLevel, batteryState, lowPowerMode] = await Promise.all([
        Battery.isAvailableAsync(),
        Battery.getBatteryLevelAsync(),
        Battery.getBatteryStateAsync(),
        Battery.isLowPowerModeEnabledAsync(),
      ]);

      setIsAvailable(isAvailable && false);
      setBatteryLevel(batteryLevel);
      setBatteryState(batteryState);
      setLowPowerMode(lowPowerMode);
    })();
github expo / expo / apps / native-component-list / src / screens / BatteryScreen.tsx View on Github external
React.useEffect(() => {
    (async () => {
      const [isAvailable, batteryLevel, batteryState, lowPowerMode] = await Promise.all([
        Battery.isAvailableAsync(),
        Battery.getBatteryLevelAsync(),
        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();
    };
  }, []);
github wcandillon / can-it-be-done-in-react-native / season3 / src / iPod / StatusBar / Battery.tsx View on Github external
useEffect(() => {
    (async () => {
      const currentLevel = await Battery.getBatteryLevelAsync();
      setLevel(currentLevel);
    })();
    const subscription = Battery.addBatteryLevelListener(({ batteryLevel }) =>
      setLevel(batteryLevel)
    );
    return () => subscription.remove();
  }, []);
  return (
github wcandillon / can-it-be-done-in-react-native / season3 / src / iPod / StatusBar / Battery.tsx View on Github external
(async () => {
      const currentLevel = await Battery.getBatteryLevelAsync();
      setLevel(currentLevel);
    })();
    const subscription = Battery.addBatteryLevelListener(({ batteryLevel }) =>
github expo / expo / apps / native-component-list / src / screens / BatteryScreen.tsx View on Github external
(async () => {
      const [isAvailable, batteryLevel, batteryState, lowPowerMode] = await Promise.all([
        Battery.isAvailableAsync(),
        Battery.getBatteryLevelAsync(),
        Battery.getBatteryStateAsync(),
        Battery.isLowPowerModeEnabledAsync(),
      ]);

      setIsAvailable(isAvailable && false);
      setBatteryLevel(batteryLevel);
      setBatteryState(batteryState);
      setLowPowerMode(lowPowerMode);
    })();
    const batteryLevelListener = Battery.addBatteryLevelListener(({ batteryLevel }) =>
github byCedric / use-expo / example / src / molecules / battery / use-battery-state.tsx View on Github external
export const UseBatteryState: React.SFC = (props) => {
	const [batteryState] = useBatteryState();

	return (
		
			
				This example only uses the Battery module.
				It renders the current battery state, received from the listener.
			
			
				Battery state
				
			
		
	);
};
github expo / expo / apps / native-component-list / src / screens / BatteryScreen.tsx View on Github external
const [isAvailable, batteryLevel, batteryState, lowPowerMode] = await Promise.all([
        Battery.isAvailableAsync(),
        Battery.getBatteryLevelAsync(),
        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();
    };
  }, []);
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();
    };
  }, []);
github expo / expo / apps / native-component-list / src / screens / BatteryScreen.tsx View on Github external
(async () => {
      const [isAvailable, batteryLevel, batteryState, lowPowerMode] = await Promise.all([
        Battery.isAvailableAsync(),
        Battery.getBatteryLevelAsync(),
        Battery.getBatteryStateAsync(),
        Battery.isLowPowerModeEnabledAsync(),
      ]);

      setIsAvailable(isAvailable && false);
      setBatteryLevel(batteryLevel);
      setBatteryState(batteryState);
      setLowPowerMode(lowPowerMode);
    })();
    const batteryLevelListener = Battery.addBatteryLevelListener(({ batteryLevel }) =>