Skip to content

Commit 79e27bd

Browse files
committed
perf: make attachbutton better
1 parent 03732df commit 79e27bd

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

package/src/components/MessageInput/AttachButton.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import { Pressable } from 'react-native';
55
import { NativeAttachmentPicker } from './components/NativeAttachmentPicker';
66

77
import { useAttachmentPickerContext } from '../../contexts/attachmentPickerContext/AttachmentPickerContext';
8-
import { useMessageInputContext } from '../../contexts/messageInputContext/MessageInputContext';
8+
import {
9+
MessageInputContextValue,
10+
useMessageInputContext,
11+
} from '../../contexts/messageInputContext/MessageInputContext';
912
import { useTheme } from '../../contexts/themeContext/ThemeContext';
1013
import { Attach } from '../../icons/Attach';
1114

1215
import { isImageMediaLibraryAvailable } from '../../native';
1316

14-
type AttachButtonPropsWithContext = {
17+
type AttachButtonPropsWithContext = Pick<
18+
MessageInputContextValue,
19+
'handleAttachButtonPress' | 'toggleAttachmentPicker'
20+
> & {
1521
disabled?: boolean;
1622
/** Function that opens attachment options bottom sheet */
1723
handleOnPress?: ((event: GestureResponderEvent) => void) & (() => void);
@@ -21,14 +27,19 @@ type AttachButtonPropsWithContext = {
2127
const AttachButtonWithContext = (props: AttachButtonPropsWithContext) => {
2228
const [showAttachButtonPicker, setShowAttachButtonPicker] = useState<boolean>(false);
2329
const [attachButtonLayoutRectangle, setAttachButtonLayoutRectangle] = useState<LayoutRectangle>();
24-
const { disabled = false, handleOnPress, selectedPicker } = props;
30+
const {
31+
disabled = false,
32+
handleAttachButtonPress,
33+
handleOnPress,
34+
selectedPicker,
35+
toggleAttachmentPicker,
36+
} = props;
2537
const {
2638
theme: {
2739
colors: { accent_blue, grey },
2840
messageInput: { attachButton },
2941
},
3042
} = useTheme();
31-
const { handleAttachButtonPress, toggleAttachmentPicker } = useMessageInputContext();
3243

3344
const onAttachButtonLayout = (event: LayoutChangeEvent) => {
3445
const layout = event.nativeEvent.layout;
@@ -122,8 +133,14 @@ export type AttachButtonProps = Partial<AttachButtonPropsWithContext>;
122133
*/
123134
export const AttachButton = (props: AttachButtonProps) => {
124135
const { selectedPicker } = useAttachmentPickerContext();
136+
const { handleAttachButtonPress, toggleAttachmentPicker } = useMessageInputContext();
125137

126-
return <MemoizedAttachButton {...{ selectedPicker }} {...props} />;
138+
return (
139+
<MemoizedAttachButton
140+
{...{ handleAttachButtonPress, selectedPicker, toggleAttachmentPicker }}
141+
{...props}
142+
/>
143+
);
127144
};
128145

129146
AttachButton.displayName = 'AttachButton{messageInput}';

0 commit comments

Comments
 (0)