diff --git a/package.json b/package.json index 9052740..5f0be90 100644 --- a/package.json +++ b/package.json @@ -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 @@ } } } -} \ No newline at end of file +} diff --git a/src/screens/Playback/RecordPlayback.js b/src/screens/Playback/RecordPlayback.js index 204be4c..40a4197 100644 --- a/src/screens/Playback/RecordPlayback.js +++ b/src/screens/Playback/RecordPlayback.js @@ -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. diff --git a/yarn.lock b/yarn.lock index cc875f1..d8cd0db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"