Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/12227/headmerged by juliusmarminge View on GitHub

Showing 4 changed files with 19 additions and 2 deletions.

x
0 of 4 viewed, 4 left
16 additions and 1 deletionapps/mobile/src/features/voice-input/useVoiceInputController.tsModified
View file
@@ -7,8 +7,9 @@
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 @@
}) {
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 @@
​
useEffect(() => () => controller.dispose(), [controller]);
​
+ useEffect(() => {
+ if (state.phase !== "recording") return;
+​
+ const tag = `voice-input:${keepAwakeId}:${++keepAwakeSessionRef.current}`;