GeezerVison is showing github.com — fix(mobile): the Android card no longer closes while focus returns fr… · pingdotgg/t3code@a50ca1c
File treeExpand file treeCollapse file tree Open diff view settings apps/mobile/src/features/threads
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadComposer.tsx +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -151,6 +151,10 @@ export function useCompactComposerEditor( | 151 | 151 | const [contentSize, setContentSize] = useState({ width: 0, height: 0 }); | 152 | 152 | const [slot, setSlot] = useState(EMPTY_COMPACT_COMPOSER_SLOT); | 153 | 153 | const keyboardShowing = useAndroidKeyboardShowing(); | | 154 | + // Only a keyboard that showed since focus and then hid closes the card, so a refocus that | | 155 | + // is still waiting for its keyboard (after the model sheet) keeps it open. | | 156 | + const [keyboardShownSinceFocus, setKeyboardShownSinceFocus] = useState(false); | | 157 | + if (keyboardShowing && !keyboardShownSinceFocus) setKeyboardShownSinceFocus(true); | 154 | 158 | const contentHeight = contentSize.height; | 155 | 159 | const rowWidth = useSharedValue(0); | 156 | 160 | const editorX = useSharedValue(0); | @@ -161,8 +165,7 @@ export function useCompactComposerEditor( | 161 | 165 | const { isExpanded, modelIconOnly, labelShownAtRest } = resolveCompactComposerLayout({ | 162 | 166 | ...state, | 163 | 167 | slot, | 164 | | - isAndroid: Platform.OS === "android", | 165 | | - keyboardShowing, | | 168 | + keyboardDismissed: keyboardShownSinceFocus && !keyboardShowing, | 166 | 169 | value, | 167 | 170 | contentSize, | 168 | 171 | lineHeight: text.lineHeight, | @@ -209,6 +212,7 @@ export function useCompactComposerEditor( | 209 | 212 | ); | 210 | 213 | } | 211 | 214 | }, | | 215 | + onEditorFocus: () => setKeyboardShownSinceFocus(false), | 212 | 216 | onModelControlLayout: (event: { nativeEvent: { layout: { width: number } } }) => { | 213 | 217 | const { width } = event.nativeEvent.layout; | 214 | 218 | setSlot((current) => | @@ -677,6 +681,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps | 677 | 681 | const onEditorFocusChange = props.onEditorFocusChange; | 678 | 682 | const handleFocus = () => { | 679 | 683 | setIsFocused(true); | | 684 | + compactEditor.onEditorFocus(); | 680 | 685 | settingsSheetPresentation.onEditorFocusChange(true); | 681 | 686 | onEditorFocusChange?.(true); | 682 | 687 | setComposerEditing(true); | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/compactComposerLayout.test.ts +4-8Lines changed: 4 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,8 +16,7 @@ function composer( | 16 | 16 | input: { | 17 | 17 | readonly rowWidth?: number; | 18 | 18 | readonly isFocused?: boolean; | 19 | | - readonly isAndroid?: boolean; | 20 | | - readonly keyboardVisible?: boolean; | | 19 | + readonly keyboardDismissed?: boolean; | 21 | 20 | readonly keepsSettingsOpen?: boolean; | 22 | 21 | readonly value?: string; | 23 | 22 | readonly contentSize?: { readonly width: number; readonly height: number }; | @@ -34,8 +33,7 @@ function composer( | 34 | 33 | attachmentCount: input.measuredAttachmentCount ?? input.attachmentCount ?? 0, | 35 | 34 | }, | 36 | 35 | isFocused: input.isFocused ?? false, | 37 | | - isAndroid: input.isAndroid ?? false, | 38 | | - keyboardShowing: input.keyboardVisible ?? false, | | 36 | + keyboardDismissed: input.keyboardDismissed ?? false, | 39 | 37 | keepsSettingsOpen: input.keepsSettingsOpen ?? false, | 40 | 38 | value: input.value ?? "", | 41 | 39 | contentSize: input.contentSize ?? { width: 0, height: LINE_HEIGHT }, | @@ -50,10 +48,8 @@ describe("compact composer layout", () => { | 50 | 48 | it("opens the card with the model label when a narrow composer is focused", () => { | 51 | 49 | expect(composer()).toEqual({ isExpanded: false, modelIconOnly: true }); | 52 | 50 | expect(composer({ isFocused: true })).toEqual({ isExpanded: true, modelIconOnly: false }); | 53 | | - expect(composer({ isFocused: true, isAndroid: true }).isExpanded).toBe(false); | 54 | | - expect(composer({ isFocused: true, isAndroid: true, keyboardVisible: true }).isExpanded).toBe( | 55 | | - true, | 56 | | - ); | | 51 | + // Android's Back hides the keyboard but leaves the editor focused. | | 52 | + expect(composer({ isFocused: true, keyboardDismissed: true }).isExpanded).toBe(false); | 57 | 53 | expect(composer({ keepsSettingsOpen: true })).toEqual({ | 58 | 54 | isExpanded: true, | 59 | 55 | modelIconOnly: false, | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/compactComposerLayout.ts +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,9 +52,8 @@ export function compactSlotAfterLabelLayout( | 52 | 52 | export function resolveCompactComposerLayout(input: { | 53 | 53 | readonly slot: CompactComposerSlot; | 54 | 54 | readonly isFocused: boolean; | 55 | | - readonly isAndroid: boolean; | 56 | 55 | /** Android's Back hides the keyboard without blurring the editor. */ | 57 | | - readonly keyboardShowing: boolean; | | 56 | + readonly keyboardDismissed: boolean; | 58 | 57 | readonly keepsSettingsOpen: boolean; | 59 | 58 | readonly value: string; | 60 | 59 | readonly contentSize: { readonly width: number; readonly height: number }; | @@ -74,7 +73,7 @@ export function resolveCompactComposerLayout(input: { | 74 | 73 | const opensOnFocus = | 75 | 74 | rowWidth > 0 && | 76 | 75 | !isWide && | 77 | | - ((input.isFocused && (!input.isAndroid || input.keyboardShowing)) || input.keepsSettingsOpen); | | 76 | + ((input.isFocused && !input.keyboardDismissed) || input.keepsSettingsOpen); | 78 | 77 | const wraps = input.contentSize.height > input.lineHeight * 1.5; | 79 | 78 | // A line that fits the expanded editor may still overflow its compact slot. | 80 | 79 | // Compare its measured width too, a character early, so widening cannot loop. | |
|