expo keep awake

This commit is contained in:
2026-02-12 14:11:43 +01:00
parent 9d7421e3d8
commit 689b42654e
3 changed files with 28 additions and 1 deletions
+2 -1
View File
@@ -53,6 +53,7 @@
"expo-image": "~2.0.7",
"expo-image-picker": "~16.0.6",
"expo-insights": "~0.8.2",
"expo-keep-awake": "^15.0.8",
"expo-linear-gradient": "~14.0.2",
"expo-linking": "~7.0.5",
"expo-location": "~18.0.10",
@@ -133,4 +134,4 @@
}
}
}
}
}
+21
View File
@@ -1,5 +1,6 @@
import { useFocusEffect } from '@react-navigation/native'
import { CameraView, useCameraPermissions } from 'expo-camera'
import { activateKeepAwakeAsync, deactivateKeepAwake } from 'expo-keep-awake'
import * as FileSystem from 'expo-file-system'
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { BackHandler, Text, TouchableOpacity, View } from 'react-native'
@@ -22,6 +23,7 @@ import CreateLyricsHeader from '../Writing/components/CreateLyricsHeader'
const TIME_BEFORE_INCREMENT_MS = 20000 // 20s
const COUNTDOWN_SECONDS = 10
const LOG_PREFIX = '[RecordPlayback]'
const KEEP_AWAKE_TAG = 'record-playback'
const log =
typeof __DEV__ === 'undefined' || __DEV__
? (...args) => console.log(LOG_PREFIX, ...args)
@@ -97,6 +99,25 @@ const RecordPlayback = ({ route }) => {
isPausedRef.current = isPaused
}, [isPaused])
useEffect(() => {
const shouldKeepAwake = isPreparing || isRecording
const updateKeepAwake = async () => {
try {
if (shouldKeepAwake) {
await activateKeepAwakeAsync(KEEP_AWAKE_TAG)
} else {
await deactivateKeepAwake(KEEP_AWAKE_TAG)
}
} catch (_) { }
}
void updateKeepAwake()
return () => {
try {
void deactivateKeepAwake(KEEP_AWAKE_TAG)
} catch (_) { }
}
}, [isPreparing, isRecording])
// Removed AppState listener as it was too aggressive.
// We now use duration validation at the end of recording.
+5
View File
@@ -5234,6 +5234,11 @@ expo-json-utils@~0.14.0:
resolved "https://registry.npmjs.org/expo-json-utils/-/expo-json-utils-0.14.0.tgz"
integrity sha512-xjGfK9dL0B1wLnOqNkX0jM9p48Y0I5xEPzHude28LY67UmamUyAACkqhZGaPClyPNfdzczk7Ej6WaRMT3HfXvw==
expo-keep-awake@^15.0.8:
version "15.0.8"
resolved "https://registry.yarnpkg.com/expo-keep-awake/-/expo-keep-awake-15.0.8.tgz#911c5effeba9baff2ccde79ef0ff5bf856215f8d"
integrity sha512-YK9M1VrnoH1vLJiQzChZgzDvVimVoriibiDIFLbQMpjYBnvyfUeHJcin/Gx1a+XgupNXy92EQJLgI/9ZuXajYQ==
expo-keep-awake@~14.0.3:
version "14.0.3"
resolved "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-14.0.3.tgz"