fix(mobile): recover keyboard composers after Android resume #8212
Closedmrmg(GitHub profile, opens in a new tab)wants to merge 6 commits into
main fromrefs/pull/8212/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx line 508OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -503,4 +505,4 @@503505 height: state.height,504506 isVisible: state.isVisible,505507 }));506- const isAccessoryVisible = keyboardState.isVisible && !isAccessoryDismissed;508+ const { isQuarantined: isKeyboardStateQuarantined } = useAndroidKeyboardRecovery();apps/mobile/src/features/review/ReviewCommentComposerSheet.tsx line 325Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -305,3 +319,4 @@305319 </KeyboardAvoidingView>306320 {isAndroid && target ? (307321 <KeyboardStickyView322+ enabled={isKeyboardAnimationUsable}
- apps/mobile/src/features/keyboard/useAndroidKeyboardRecovery.ts line 37Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +8,21 @@8+} from "./androidKeyboardRecovery";9+10+export function useAndroidKeyboardRecovery(): {11+ readonly isQuarantined: boolean;12+ readonly markInputFocused: () => void;13+} {14+ const [recoveryState, setRecoveryState] = useState<AndroidKeyboardRecoveryState>("ready");15+16+ useEffect(() => {17+ if (Platform.OS !== "android") {18+ return;19+ }20+21+ const appStateSubscription = AppState.addEventListener("change", (state) => {22+ if (state === "active") {23+ setRecoveryState((current) => reduceAndroidKeyboardRecovery(current, "resume"));24+ }25+ });26+ const keyboardShowSubscription = KeyboardEvents.addListener("keyboardWillShow", () => {27+ setRecoveryState((current) => reduceAndroidKeyboardRecovery(current, "keyboard-show"));28+ });
- apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx line 1054OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1041,5 +1049,6 @@10411049 }, []);1042105010431051 const handleShowKeyboard = useCallback(() => {1052+ markInputFocused();10441053 setKeyboardFocusRequest((current) => current + 1);1045- }, []);1054+ }, [markInputFocused]);
- apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx line 1338Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1325,4 +1335,4 @@13251335 </ComposerToolbarRow>13261336 </View>13271337 </KeyboardStickyView>1328- ) : !keyboardState.isVisible ? (1338+ ) : !isKeyboardAnimationUsable ? (apps/mobile/src/features/keyboard/useAndroidKeyboardRecovery.ts line 40OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +20,21 @@20+ );21+22+ useEffect(() => {23+ if (Platform.OS !== "android") {24+ return;25+ }26+27+ const appStateSubscription = AppState.addEventListener("change", (state) => {28+ if (state === "active") {29+ setRecoveryState((current) => reduceAndroidKeyboardRecovery(current, "resume"));30+ }31+ });32+ const keyboardShowSubscription = KeyboardEvents.addListener("keyboardWillShow", () => {33+ setRecoveryState((current) => reduceAndroidKeyboardRecovery(current, "keyboard-show"));34+ });35+36+ // The screen may mount after the app has already resumed. In that case37+ // there is no future active transition for this instance to observe.38+ if (AppState.currentState === "active") {39+ setRecoveryState((current) => reduceAndroidKeyboardRecovery(current, "resume"));40+ }
- apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt line 396Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -372,4 +379,12 @@372379 }373380374381 private fun requestKeyboardFocus() {382+ // requestFocus on an already-focused EditText fires no focus callback, so383+ // emit it here: an explicit show request means the keyboard stream is live384+ // again, and the JS recovery quarantine must lift even when the IME was385+ // retained across an Android resume.386+ val retainedFocus = inputView.hasFocus()375387 inputView.requestFocus()388+ if (retainedFocus) {389+ onTerminalFocus(emptyMap<String, Any>())390+ }
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
bd0574a3-7ade-44d2-85f1-4337a11d9d40You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share