Keep awake
KeepAwake holds the device's screen on, bound to expo-keep-awake.
Import
import { KeepAwake } from '@ng-native/expo';
Inject
inject(KeepAwake)It is never a bare activate: a screen that holds the display on and never releases it is a phone
that never sleeps, which the user experiences as a battery fault and never attributes to the app
that caused it. hold() always returns the function that releases it.
Install
npx expo install expo-keep-awakeimport { KeepAwake } from '@ng-native/expo/keep-awake';The smallest useful example
import { Component, DestroyRef, inject } from '@angular/core';
import { KeepAwake } from '@ng-native/expo/keep-awake';
@Component({
selector: 'app-recording',
template: `<text>Recording...</text>`,
})
export class Recording {
constructor() {
inject(DestroyRef).onDestroy(inject(KeepAwake).hold('recording'));
}
}What it does
hold(tag)- holds the screen on under that tag, and returns the function that releases it. The tag defaults to a package-wide constant, but naming it explicitly is what lets two screens each hold the screen on without either releasing the other's hold.holders- a signal of the set of tags currently holding the screen on, for a debug screen that wants to say which.active- whether anything currently holds the screen on, computed from whetherholdersis non-empty.
Releasing the same hold twice does nothing the second time.
Without the module installed
hold() still tracks the tag in holders and active, but nothing on the device changes and
stop calls into a module that is not there safely.
Reference
KeepAwakeservice@ng-native/expoimport { KeepAwake } from '@ng-native/expo';Signals
activeSignal<boolean>Whether anything currently holds the screen on.
Methods
hold(tag = DEFAULT_TAG): () => void Hold the screen on. Returns the function that releases it, ready for DestroyRef.onDestroy .