Skip to content
TypeScript

fix(mobile): keep screen awake during dictation (#12227)

Julius Marmingedd9528a974ba
diff --git a/apps/mobile/package.json b/apps/mobile/package.json
index b1d73662140..031a23b666d 100644
--- a/apps/mobile/package.json
+++ b/apps/mobile/package.json
@@ -93,6 +93,7 @@
"expo-image": "~57.0.3",
"expo-image-manipulator": "~57.0.17",
"expo-image-picker": "~57.0.14",
+ "expo-keep-awake": "~57.0.2",
"expo-linking": "~57.0.8",
"expo-network": "~57.0.1",
"expo-notifications": "~57.0.15",
diff --git a/apps/mobile/src/features/voice-input/useVoiceInputController.ts b/apps/mobile/src/features/voice-input/useVoiceInputController.ts
index 8d1c9a9780a..5fd15482d03 100644
--- a/apps/mobile/src/features/voice-input/useVoiceInputController.ts
+++ b/apps/mobile/src/features/voice-input/useVoiceInputController.ts
@@ -7,8 +7,9 @@ import {
type RecordingStatus,
} from "expo-audio";
import { File } from "expo-file-system";
+import { activateKeepAwakeAsync, deactivateKeepAwake } from "expo-keep-awake";
import { useFocusEffect } from "@react-navigation/native";
-import { useCallback, useEffect, useRef, useState } from "react";
+import { useCallback, useEffect, useId, useRef, useState } from "react";
import { AppState } from "react-native";
import { useSharedValue } from "react-native-reanimated";
@@ -71,6 +72,8 @@ export function useVoiceInputController(input: {
}) {
const [state, setState] = useState<VoiceInputState>(INITIAL_STATE);
const [elapsedSeconds, setElapsedSeconds] = useState(0);
+ const keepAwakeId = useId();
+ const keepAwakeSessionRef = useRef(0);
const elapsedSecondsRef = useRef(0);
const audioLevelsRef = useRef(Array<number>(VOICE_WAVEFORM_SAMPLE_COUNT).fill(0));
const audioLevels = useSharedValue(audioLevelsRef.current);
@@ -156,6 +159,18 @@ export function useVoiceInputController(input: {
useEffect(() => () => controller.dispose(), [controller]);
+ useEffect(() => {
+ if (state.phase !== "recording") return;
+
+ const tag = `voice-input:${keepAwakeId}:${++keepAwakeSessionRef.current}`;
+ const activation = activateKeepAwakeAsync(tag);
+ void activation.catch(() => {});
+ return () => {
+ // Release after activation settles, even if the recording ends immediately.
+ void activation.then(() => deactivateKeepAwake(tag)).catch(() => {});
+ };
+ }, [keepAwakeId, state.phase]);
+
useEffect(() => {
if (state.phase !== "preparing" && state.phase !== "recording") return;
diff --git a/docs/user/composer.md b/docs/user/composer.md
index f3be7a5f342..b0b42850c4c 100644
--- a/docs/user/composer.md
+++ b/docs/user/composer.md
@@ -131,7 +131,8 @@ recording started, ready for you to review and edit before sending.
The first use may download Apple's speech model and needs a network connection.
Later transcription works offline for that language. Recordings can be up to five
minutes long. Canceling, leaving the screen, or an audio interruption discards the
-recording and preserves your existing draft.
+recording and preserves your existing draft. While recording, the screen stays
+awake; it can sleep normally once recording stops.
Transcription runs on your device. T3 Code deletes the temporary audio after
transcription or cancellation; only the message text is sent when you submit.
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 905d4ac1de2..a2a0d9a9633 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -373,6 +373,9 @@ importers:
expo-image-picker:
specifier: ~57.0.14
version: 57.0.14([email protected])
+ expo-keep-awake:
+ specifier: ~57.0.2
expo-linking:
specifier: ~57.0.8
@@ -7568,8 +7571,8 @@ packages:
resolution: {integrity: sha512-cgTe1NqzQdYs/WN+3nIY5IZg8s0pb0xaTUbhYvxQDn137GbwRfHoGM2se3m3Vsl4Qu+B9G4RPEK5WJDEU2Do7g==}
- resolution: {integrity: sha512-28lkFImeXTS+bhAjuCFV7w7tW5bXg27BJVrxv+nC/nyYa86qEa0oFeHwqol6ha5k4pdVDQgBF09GM4A1k76Ssg==}
+ resolution: {integrity: sha512-GqgH746wtJImmsbyHmCQoi7cOslKuWQBbJHXr53S35Bpf5UvxCAztvnitUEd7D0QvFN2rvkOhylbZpgZZfBLlQ==}
peerDependencies:
expo: '*'
react: '*'
@@ -18157,12 +18160,12 @@ snapshots:
dependencies:
expo: 57.0.18(41fd11498a34454c91128cdad32f22f8)
react: 19.2.3
dependencies:
expo: 57.0.18(0bf40d5ad6281d8f1e92517b24812edb)
react: 19.2.6
@@ -18384,7 +18387,7 @@ snapshots:
- expo-keep-awake: 57.0.1([email protected])([email protected])
+ expo-keep-awake: 57.0.2([email protected])([email protected])
expo-modules-autolinking: 57.0.12([email protected])
pretty-format: 29.7.0
@@ -18427,7 +18430,7 @@ snapshots:
- expo-keep-awake: 57.0.1([email protected])([email protected])
+ expo-keep-awake: 57.0.2([email protected])([email protected])
expo-modules-autolinking: 57.0.12([email protected])
pretty-format: 29.7.0