Skip to content

Commit 11f70e8

Browse files
committed
fix: improve ui of the mobile attachment componser UI
1 parent 11d38f3 commit 11f70e8

3 files changed

Lines changed: 60 additions & 51 deletions

File tree

apps/mobile/components/ai-chat/attachment.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const AttachmentUI: FC<{ noRemoveButton?: boolean }> = ({ noRemoveButton }) => {
5050
<AttachmentPrimitive.Root className="relative">
5151
<View
5252
className={cn(
53-
"aspect-square flex-1 overflow-hidden rounded-xl border border-input",
53+
"aspect-square flex-1 overflow-hidden rounded-2xl border border-input",
5454
)}
5555
>
5656
<AttachmentThumb />
@@ -86,15 +86,21 @@ export const UserMessageAttachments: FC = () => {
8686
export const ComposerAttachments: FC = () => {
8787
const attachments = ComposerPrimitive.useComposer((s) => s.attachments);
8888
return attachments.length > 0 ? (
89-
<ScrollView
90-
horizontal
91-
contentContainerStyle={{ gap: 8, paddingHorizontal: 6, paddingBottom: 4 }}
92-
className="h-32 w-full p-2"
93-
>
94-
<ComposerPrimitive.Attachments
95-
components={{ Attachment: AttachmentUI }}
96-
/>
97-
</ScrollView>
89+
<View className="h-28 w-full">
90+
<ScrollView
91+
horizontal
92+
contentContainerStyle={{
93+
gap: 8,
94+
paddingHorizontal: 6,
95+
paddingBottom: 4,
96+
}}
97+
className="h-full w-full p-2"
98+
>
99+
<ComposerPrimitive.Attachments
100+
components={{ Attachment: AttachmentUI }}
101+
/>
102+
</ScrollView>
103+
</View>
98104
) : null;
99105
};
100106

apps/mobile/components/ai-chat/thread.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,35 @@ const ThreadSuggestions: FC = () => {
172172
);
173173
};
174174

175+
const AttachmentComposer: React.FC = () => {
176+
const attachments = ComposerPrimitive.useComposer((s) => s.attachments);
177+
return (
178+
<>
179+
<View className="absolute top-0 left-0 z-1 w-full pl-14">
180+
<ComposerAttachments />
181+
</View>
182+
183+
<ComposerPrimitive.Input
184+
headerContent={<ComposerAttachments />}
185+
placeholder="Send a message..."
186+
className={cn(
187+
"my-auto flex max-h-50 min-h-12 w-full flex-1 flex-row items-center rounded-3xl bg-secondary px-3 py-2 text-base outline-none transition-shadow placeholder:text-muted-foreground",
188+
attachments.length > 0 ? "pt-28" : "",
189+
)}
190+
autoFocus
191+
aria-label="Message input"
192+
/>
193+
</>
194+
);
195+
};
196+
175197
const Composer: React.FC = () => {
176198
return (
177199
<ComposerPrimitive.Root>
178-
<View className="flex-row items-end gap-2">
179-
<ComposerAction />
180-
<View className="flex flex-1 items-start rounded-3xl bg-secondary">
181-
<ComposerAttachments />
182-
<ComposerPrimitive.Input
183-
placeholder="Send a message..."
184-
className="my-auto flex max-h-40 min-h-12 w-full flex-1 flex-row items-center rounded-3xl bg-secondary px-3 py-2 text-base outline-none transition-shadow placeholder:text-muted-foreground"
185-
autoFocus
186-
aria-label="Message input"
187-
/>
200+
<View className="flex">
201+
<View className="flex-row items-end gap-2">
202+
<ComposerAction />
203+
<AttachmentComposer />
188204
</View>
189205
<ComposerSubmit />
190206
</View>
@@ -223,7 +239,7 @@ const ComposerAction: FC = () => {
223239

224240
const ComposerSubmit: FC = () => {
225241
return (
226-
<View className="absolute right-0 bottom-0 my-auto flex flex-row items-center justify-between pr-2 pb-2">
242+
<View className="absolute right-0 bottom-0 z-30 my-auto flex flex-row items-center justify-between pr-2 pb-2">
227243
<ThreadPrimitive.If running={false}>
228244
<ComposerPrimitive.Send
229245
type="submit"

apps/mobile/components/ui/autoresize-textarea.tsx

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"use client";
22

3-
import React, { useCallback, useEffect, useRef } from "react";
3+
import React, { useCallback } from "react";
44
import {
55
TextInput,
66
type NativeSyntheticEvent,
77
type TextInputContentSizeChangeEventData,
8+
View,
89
type TextInputProps,
910
} from "react-native";
1011
import { cn } from "~/utils/cn";
@@ -24,20 +25,22 @@ export type AutoResizeTextareaProps = Omit<
2425
"onChange" | "multiline"
2526
> & {
2627
onChange?: (value: string, e?: unknown) => void;
27-
// minRows?: number;
28-
// maxRows?: number;
29-
// rowHeight?: number;
30-
// onHeightChange?: (height: number) => void;
31-
// cacheMeasurements?: boolean;
32-
// height?: number;
28+
headerContent?: React.ReactNode;
3329
};
3430

3531
export const AutoResizeTextarea = React.forwardRef<
3632
TextInput,
3733
AutoResizeTextareaProps
3834
>(
3935
(
40-
{ onChange, onChangeText, onContentSizeChange, className, ...restProps },
36+
{
37+
onChange,
38+
onChangeText,
39+
onContentSizeChange,
40+
headerContent,
41+
className,
42+
...restProps
43+
},
4144
ref,
4245
) => {
4346
const [displayExpand, setDisplayExpand] = React.useState<boolean>(false);
@@ -59,24 +62,6 @@ export const AutoResizeTextarea = React.forwardRef<
5962
[onChange, onChangeText],
6063
);
6164

62-
// const fadeAnim = useRef(new Animated.Value(0)).current;
63-
64-
// useEffect(() => {
65-
// if(displayExpand) {
66-
// Animated.timing(fadeAnim, {
67-
// toValue: 1,
68-
// duration: 300,
69-
// useNativeDriver: true,
70-
// }).start();
71-
// } else {
72-
// Animated.timing(fadeAnim, {
73-
// toValue: 0,
74-
// duration: 300,
75-
// useNativeDriver: true,
76-
// }).start();
77-
// }
78-
// }, [displayExpand]);
79-
8065
return (
8166
<ActionSheet>
8267
<TextInput
@@ -91,10 +76,10 @@ export const AutoResizeTextarea = React.forwardRef<
9176
<Animated.View
9277
entering={FadeIn.duration(200)}
9378
exiting={FadeOut.duration(200)}
94-
className="absolute top-2 right-2"
79+
className="absolute top-2 right-2 z-20"
9580
>
9681
<ActionSheetTrigger asChild>
97-
<Button size="sm-icon" variant="ghost">
82+
<Button size="sm-icon" variant="ghost" className="bg-secondary">
9883
<Icon name="Expand" size={20} color={textMutedForeground} />
9984
</Button>
10085
</ActionSheetTrigger>
@@ -112,19 +97,21 @@ export const AutoResizeTextarea = React.forwardRef<
11297
<Button
11398
size="sm-icon"
11499
variant="ghost"
115-
className="absolute top-4 right-4 z-10"
100+
className="absolute top-4 right-4 z-20"
116101
>
117102
<Icon name="Shrink" size={20} />
118103
</Button>
119104
</ActionSheetClose>
120105

106+
{headerContent}
107+
121108
<TextInput
122109
{...restProps}
123110
ref={ref}
124111
multiline
125112
className={cn("h-full p-4 pt-12 text-base text-foreground")}
126113
onChangeText={handleChangeText}
127-
></TextInput>
114+
/>
128115
</ActionSheetContent>
129116
</ActionSheet>
130117
);

0 commit comments

Comments
 (0)