Skip to content

Commit b85d6d1

Browse files
shivamhwpclaude
andcommitted
fix(mobile): let the Android composer picker scroll
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 4ee6bfd commit b85d6d1

3 files changed

Lines changed: 95 additions & 2 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import type { ReactNode } from "react";
2+
import { useCallback, useEffect, useRef, useState } from "react";
3+
import { View, type ViewInstance } from "react-native";
4+
import { useKeyboardState } from "react-native-keyboard-controller";
5+
6+
import { OverlayPortal } from "../../components/OverlayPortal";
7+
8+
const COMPOSER_GAP = 8;
9+
10+
type Frame = {
11+
readonly x: number;
12+
readonly y: number;
13+
readonly width: number;
14+
readonly height: number;
15+
};
16+
17+
function sameFrame(a: Frame | null, b: Frame) {
18+
return a !== null && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
19+
}
20+
21+
/**
22+
* Places a composer popover just above the composer. Android only delivers
23+
* drags to views inside their parent's bounds, so a popover hung above the
24+
* composer with `bottom-full` takes taps but its list never scrolls. Render it
25+
* through OverlayPortal instead, positioned from the composer's window frame.
26+
*/
27+
export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) {
28+
const anchorRef = useRef<ViewInstance>(null);
29+
const overlayRef = useRef<ViewInstance>(null);
30+
const [anchor, setAnchor] = useState<Frame | null>(null);
31+
const [overlay, setOverlay] = useState<Frame | null>(null);
32+
const keyboardHeight = useKeyboardState((state) => state.height);
33+
34+
const measureAnchor = useCallback(() => {
35+
anchorRef.current?.measureInWindow((x, y, width, height) => {
36+
const next = { x, y, width, height };
37+
setAnchor((current) => (sameFrame(current, next) ? current : next));
38+
});
39+
}, []);
40+
41+
const measureOverlay = useCallback(() => {
42+
overlayRef.current?.measureInWindow((x, y, width, height) => {
43+
const next = { x, y, width, height };
44+
setOverlay((current) => (sameFrame(current, next) ? current : next));
45+
});
46+
}, []);
47+
48+
// The composer moves without resizing when the keyboard opens or closes.
49+
useEffect(measureAnchor, [measureAnchor, keyboardHeight]);
50+
51+
return (
52+
<>
53+
{/* Covers the composer so its onLayout fires when the composer grows. */}
54+
<View
55+
ref={anchorRef}
56+
collapsable={false}
57+
pointerEvents="none"
58+
className="absolute inset-0"
59+
onLayout={measureAnchor}
60+
/>
61+
<OverlayPortal>
62+
<View
63+
ref={overlayRef}
64+
collapsable={false}
65+
pointerEvents="box-none"
66+
className="absolute inset-0"
67+
onLayout={measureOverlay}
68+
>
69+
{anchor === null || overlay === null ? null : (
70+
<View
71+
className="absolute"
72+
style={{
73+
left: anchor.x - overlay.x,
74+
width: anchor.width,
75+
bottom: overlay.height - (anchor.y - overlay.y) + COMPOSER_GAP,
76+
}}
77+
>
78+
{props.children}
79+
</View>
80+
)}
81+
</View>
82+
</OverlayPortal>
83+
</>
84+
);
85+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { ReactNode } from "react";
2+
import { View } from "react-native";
3+
4+
/** Places a composer popover just above the composer. */
5+
export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) {
6+
return <View className="absolute inset-x-0 bottom-full z-10 mb-2">{props.children}</View>;
7+
}

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import {
102102
type ComposerSendPresentation,
103103
} from "./composerSendPresentation";
104104
import { ComposerCommandPopover } from "./ComposerCommandPopover";
105+
import { ComposerPopoverAnchor } from "./ComposerPopoverAnchor";
105106
import { ComposerQueuedEditAttachments } from "./ComposerQueuedEdit";
106107
import { useComposerCommandMenu } from "./use-composer-command-menu";
107108
import {
@@ -771,15 +772,15 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
771772
{!voiceInput.isBusy &&
772773
composerMenu.trigger &&
773774
(composerMenu.items.length > 0 || composerMenu.trigger.kind === "pull-request") ? (
774-
<View className="absolute inset-x-0 bottom-full z-10 mb-2">
775+
<ComposerPopoverAnchor>
775776
<ComposerCommandPopover
776777
items={composerMenu.items}
777778
triggerKind={composerMenu.trigger.kind}
778779
isLoading={composerMenu.isLoading}
779780
error={composerMenu.error}
780781
onSelect={composerMenu.onSelect}
781782
/>
782-
</View>
783+
</ComposerPopoverAnchor>
783784
) : null}
784785

785786
{selectedProviderStatus?.compatibilityAdvisory?.message &&

0 commit comments

Comments
 (0)