Battery

Battery reports the level, charging state and power-saving mode, for the work an app should not be doing on 5%.

Import
import { Battery } from '@ng-native/expo';
Inject
inject(Battery)

Install

npx expo install expo-battery
import { Battery } from '@ng-native/expo/battery';

The smallest useful example

import { Component, inject } from '@angular/core';
import { Text } from '@ng-native/components';
import { Battery } from '@ng-native/expo/battery';

@Component({
  selector: 'app-status',
  imports: [Text],
  template: `
    @if (battery.low()) {
      <text>Battery saver recommended</text>
    }
  `,
})
export class Status {
  protected readonly battery = inject(Battery);
}

What it reports

  • level - nought to one. Starts at 1 until the platform answers, since an app should not open dimmed.
  • known - whether the platform will actually say. False on a simulator, and on a device that reports a level of -1: iOS answers -1 for "no battery to report on", and level treats that as 1 rather than passing a negative number through as a real reading that happens to be below every threshold an app has.
  • state - 'unknown', 'unplugged', 'charging' or 'full'. Android's NOT_CHARGING (plugged in and holding) reads as 'full': for every purpose an app has, the battery is not going down.
  • charging - true when state is 'charging' or 'full'.
  • saving - Low Power Mode on iOS, Battery Saver on Android. Starts false.
  • low - under a fifth and not charging: the point at which an app should start doing less. False whenever the level is unknown, since "I cannot tell" and "almost flat" are not the same answer and only one of them is a reason to degrade.

Without the module installed

level reads 1, known is false, state is 'unknown', saving and low are false. Nothing throws.

Reference

Batteryservice@ng-native/expo
import { Battery } from '@ng-native/expo';

Signals

level
Signal<number>

Nought to one. One until the platform says otherwise: an app should not open dimmed.

known
Signal<boolean>

Whether the platform will say. False on a simulator, and on a device that answers -1.

state
Signal<BatteryState>

saving
Signal<boolean>

Low Power Mode on iOS, Battery Saver on Android. The signal to skip the background refresh, drop the frame rate of a decoration, or stop prefetching.

charging
Signal<boolean>

low
Signal<boolean>

Under a fifth and not charging: the point at which an app should start doing less.

Angular components as native iOS and Android views, built and shipped with Expo.

An alpha. MIT licensed. Sponsor its development.

An independent project, not affiliated with or endorsed by Google, the Angular team or Expo. Angular is a trademark of Google LLC.