Skip to content

Commit b471053

Browse files
committed
fix(ui): replace native Alert.alert attachment sheet with dismissible bottom sheet
The attachment "+" action sheet was a native Alert.alert that could not be dismissed on Android - the only native alert in the app, while every other sheet (ModelPicker, VariantPicker, DirectoryBrowserSheet, PromptLibrarySheet, SlashHelpSheet) is a @gorhom/bottom-sheet BottomSheet that dismisses fine. Replaced it with a new AttachSheet component following the same pattern (enablePanDownToClose, BottomSheetBackdrop, sheetRef.close()). Also fixed the reply preview layout: it previously sat inside the horizontal inputRow with no width constraint, so a long quoted message squeezed the TextInput down to half a field. It now renders as a full-width block above the input row. - New src/components/chat/AttachSheet.tsx, exported from chat/index.ts - showAttachSheet now calls attachSheetRef.current?.expand() - Removed onLongPress={pickFromCamera} from the attach button (conflicted with onPress on Android); Camera is now a row inside the sheet
1 parent 7ab87fd commit b471053

4 files changed

Lines changed: 318 additions & 60 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Fix: Attachment "+" menu cannot be dismissed on Android
2+
3+
## Problem
4+
5+
Tapping the attachment "+" button in the chat composer opens an action
6+
sheet that cannot be dismissed on Android — none of the buttons respond.
7+
8+
## Root cause
9+
10+
The action sheet was a **native `Alert.alert`** (`app/session/[id].tsx:1233`).
11+
Every other sheet in this app (ModelPicker, VariantPicker, DirectoryBrowserSheet,
12+
PromptLibrarySheet, SlashHelpSheet) is a `@gorhom/bottom-sheet` BottomSheet —
13+
and every one of those dismisses fine (swipe-down, backdrop tap, buttons).
14+
15+
Native `Alert.alert` is the outlier and the only one that can't be dismissed.
16+
The first hypothesis (composer focus + `KeyboardAvoidingView` padding hiding the
17+
dialog) was tested via a full rebuild and made **zero** difference — so it was
18+
wrong. The real issue is the control itself.
19+
20+
## Fix
21+
22+
Replace the native `Alert.alert` with a `@gorhom/bottom-sheet` bottom sheet,
23+
matching the pattern already used by every other sheet in the app.
24+
25+
### New component: `src/components/chat/AttachSheet.tsx`
26+
27+
Modeled on `VariantPicker.tsx`:
28+
- `BottomSheet` with `index={-1}`, `snapPoints={["50%", "75%"]}`,
29+
`enablePanDownToClose`, `BottomSheetBackdrop` (disappears on index -1).
30+
- Renders a title + a list of `TouchableOpacity` rows (icon + label + desc)
31+
+ a Cancel button that calls `sheetRef.current?.close()`.
32+
- Keyboard-safe by construction (bottom sheets handle the keyboard; native
33+
alerts do not).
34+
35+
### `app/session/[id].tsx`
36+
37+
1. Add `const attachSheetRef = useRef<BottomSheet>(null);` (line ~155).
38+
2. `showAttachSheet` now calls `attachSheetRef.current?.expand()` instead of
39+
`Alert.alert(...)`.
40+
3. Render `<AttachSheet sheetRef={attachSheetRef} isDark={isDark}
41+
actions={[...]} />` at the end of the JSX tree, next to the other sheets.
42+
4. Export `AttachSheet` from `src/components/chat/index.ts`.
43+
44+
## Files
45+
46+
- `src/components/chat/AttachSheet.tsx` — new (modeled on VariantPicker.tsx)
47+
- `src/components/chat/index.ts` — export added
48+
- `app/session/[id].tsx` — ref added, `showAttachSheet` rewired, sheet rendered
49+
50+
## Validation
51+
52+
1. Tap the "+" attach button → bottom sheet slides up; tap any option
53+
(Photos/Camera/Files/Paste) → action runs and sheet closes.
54+
2. Swipe down on the sheet, or tap the backdrop → sheet closes.
55+
3. Tap Cancel → sheet closes.
56+
4. Confirm the sheet appears above the keyboard when the composer is open.
57+
58+
## Notes
59+
60+
- The `onLongPress={pickFromCamera}` on the attach button was removed in the
61+
first attempt (it conflicted with `onPress` on Android). It is not restored;
62+
Camera is now reachable as a row inside the sheet, which is cleaner.
63+
- The "Reply to message" path (`handleMessageLongPress`) was investigated but
64+
not changed — it uses the same native `Alert.alert` pattern; if it exhibits
65+
the same stuck-dialog symptom it should be migrated to a bottom sheet next.

‎app/session/[id].tsx‎

Lines changed: 90 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
MessageSearchBar,
4747
OfflineQueueBanner,
4848
PromptPresetBar,
49+
AttachSheet,
4950
type WorkspaceMode,
5051
type PaletteAction,
5152
type Attachment,
@@ -151,6 +152,7 @@ export default function SessionScreen() {
151152
const { t } = useTranslation();
152153

153154
const flatListRef = useRef<FlatList>(null);
155+
const attachSheetRef = useRef<BottomSheet>(null);
154156
const modelSheetRef = useRef<BottomSheet>(null);
155157
const variantSheetRef = useRef<BottomSheet>(null);
156158
const browserSheetRef = useRef<BottomSheet>(null);
@@ -1232,26 +1234,8 @@ export default function SessionScreen() {
12321234

12331235
const showAttachSheet = useCallback(() => {
12341236
void hapticSelection();
1235-
Alert.alert(t("session.alerts.attachTitle"), undefined, [
1236-
{
1237-
text: t("session.alerts.attachPhotos"),
1238-
onPress: () => void pickFromLibrary(),
1239-
},
1240-
{
1241-
text: t("session.alerts.attachCamera"),
1242-
onPress: () => void pickFromCamera(),
1243-
},
1244-
{
1245-
text: t("session.alerts.attachFiles"),
1246-
onPress: () => void pickDocument(),
1247-
},
1248-
{
1249-
text: t("session.alerts.attachPaste"),
1250-
onPress: () => void pasteFromClipboard(),
1251-
},
1252-
{ text: t("common.cancel"), style: "cancel" },
1253-
]);
1254-
}, [t, pickFromLibrary, pickFromCamera, pickDocument, pasteFromClipboard]);
1237+
attachSheetRef.current?.expand();
1238+
}, [attachSheetRef]);
12551239

12561240
const removeAttachment = useCallback((index: number) => {
12571241
void hapticLight();
@@ -2007,12 +1991,51 @@ export default function SessionScreen() {
20071991
},
20081992
]}
20091993
>
1994+
{/* Reply preview — full-width block above the input row so a
1995+
long quoted message can't squeeze the TextInput (it used to
1996+
live inside the horizontal inputRow and shrank the composer
1997+
to half a field). */}
1998+
{replyTo && (
1999+
<View style={[s.replyPreview, isDark && s.replyPreviewDark]}>
2000+
<View style={s.replyPreviewHeader}>
2001+
<Text
2002+
style={[
2003+
s.replyPreviewLabel,
2004+
isDark && s.replyPreviewLabelDark,
2005+
]}
2006+
>
2007+
{replyTo.role === "user"
2008+
? t("session.reply.inReplyToUser")
2009+
: t("session.reply.inReplyToAssistant")}
2010+
</Text>
2011+
<TouchableOpacity
2012+
onPress={cancelReply}
2013+
style={s.replyPreviewDismiss}
2014+
>
2015+
<Ionicons
2016+
name="close"
2017+
size={16}
2018+
color={isDark ? "#888888" : "#666666"}
2019+
/>
2020+
</TouchableOpacity>
2021+
</View>
2022+
<Text
2023+
style={[
2024+
s.replyPreviewText,
2025+
isDark && s.replyPreviewTextDark,
2026+
]}
2027+
numberOfLines={3}
2028+
>
2029+
{replyTo.text || t("session.reply.emptyMessage")}
2030+
</Text>
2031+
</View>
2032+
)}
2033+
20102034
<View style={s.inputRow}>
20112035
{/* Attach button */}
20122036
<TouchableOpacity
20132037
style={s.attachBtn}
20142038
onPress={showAttachSheet}
2015-
onLongPress={pickFromCamera}
20162039
>
20172040
<Ionicons
20182041
name="add-circle-outline"
@@ -2033,45 +2056,6 @@ export default function SessionScreen() {
20332056
/>
20342057
</TouchableOpacity>
20352058

2036-
{/* Reply preview */}
2037-
{replyTo && (
2038-
<View
2039-
style={[s.replyPreview, isDark && s.replyPreviewDark]}
2040-
>
2041-
<View style={s.replyPreviewHeader}>
2042-
<Text
2043-
style={[
2044-
s.replyPreviewLabel,
2045-
isDark && s.replyPreviewLabelDark,
2046-
]}
2047-
>
2048-
{replyTo.role === "user"
2049-
? t("session.reply.inReplyToUser")
2050-
: t("session.reply.inReplyToAssistant")}
2051-
</Text>
2052-
<TouchableOpacity
2053-
onPress={cancelReply}
2054-
style={s.replyPreviewDismiss}
2055-
>
2056-
<Ionicons
2057-
name="close"
2058-
size={16}
2059-
color={isDark ? "#888888" : "#666666"}
2060-
/>
2061-
</TouchableOpacity>
2062-
</View>
2063-
<Text
2064-
style={[
2065-
s.replyPreviewText,
2066-
isDark && s.replyPreviewTextDark,
2067-
]}
2068-
numberOfLines={3}
2069-
>
2070-
{replyTo.text || t("session.reply.emptyMessage")}
2071-
</Text>
2072-
</View>
2073-
)}
2074-
20752059
<TextInput
20762060
ref={composerRef}
20772061
{...shortcutProps}
@@ -2240,6 +2224,52 @@ export default function SessionScreen() {
22402224
onSaveCurrent={handleSavePrompt}
22412225
onDelete={handleDeletePrompt}
22422226
/>
2227+
2228+
{/* Attach bottom sheet — replaces the native Alert.alert that could not
2229+
be dismissed on Android (taps landed behind the keyboard padding). */}
2230+
<AttachSheet
2231+
sheetRef={attachSheetRef}
2232+
isDark={isDark}
2233+
actions={[
2234+
{
2235+
key: "photos",
2236+
icon: "images-outline",
2237+
label: t("session.alerts.attachPhotos", "Photos"),
2238+
description: t(
2239+
"session.alerts.attachPhotosDesc",
2240+
"Pick from your library",
2241+
),
2242+
onPress: () => void pickFromLibrary(),
2243+
},
2244+
{
2245+
key: "camera",
2246+
icon: "camera-outline",
2247+
label: t("session.alerts.attachCamera", "Camera"),
2248+
description: t(
2249+
"session.alerts.attachCameraDesc",
2250+
"Take a new photo",
2251+
),
2252+
onPress: () => void pickFromCamera(),
2253+
},
2254+
{
2255+
key: "files",
2256+
icon: "document-outline",
2257+
label: t("session.alerts.attachFiles", "Files"),
2258+
description: t("session.alerts.attachFilesDesc", "Pick a document"),
2259+
onPress: () => void pickDocument(),
2260+
},
2261+
{
2262+
key: "paste",
2263+
icon: "clipboard-outline",
2264+
label: t("session.alerts.attachPaste", "Paste"),
2265+
description: t(
2266+
"session.alerts.attachPasteDesc",
2267+
"Paste text or image",
2268+
),
2269+
onPress: () => void pasteFromClipboard(),
2270+
},
2271+
]}
2272+
/>
22432273
</>
22442274
);
22452275
}

0 commit comments

Comments
 (0)