Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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';
}
}
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);
})();