Skip to content

Commit 9a7cfa9

Browse files
authored
feat: allow customization of the close icon for uploads (#1668)
1 parent b327ef5 commit 9a7cfa9

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

package/src/components/MessageInput/ImageUploadPreview.tsx

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import React from 'react';
2-
import { FlatList, Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
2+
import {
3+
FlatList,
4+
Image,
5+
StyleSheet,
6+
Text,
7+
TouchableOpacity,
8+
TouchableOpacityProps,
9+
View,
10+
} from 'react-native';
311

412
import { UploadProgressIndicator } from './UploadProgressIndicator';
513

@@ -87,9 +95,8 @@ const ImageUploadPreviewWithContext = <
8795

8896
const {
8997
theme: {
90-
colors: { overlay, white },
9198
messageInput: {
92-
imageUploadPreview: { dismiss, flatList, itemContainer, upload },
99+
imageUploadPreview: { flatList, itemContainer, upload },
93100
},
94101
},
95102
} = useTheme();
@@ -140,15 +147,11 @@ const ImageUploadPreviewWithContext = <
140147
style={[styles.upload, upload]}
141148
/>
142149
</UploadProgressIndicator>
143-
<TouchableOpacity
150+
<DismissUpload
144151
onPress={() => {
145152
removeImage(item.id);
146153
}}
147-
style={[styles.dismiss, { backgroundColor: overlay }, dismiss]}
148-
testID='remove-image-upload-preview'
149-
>
150-
<Close pathFill={white} />
151-
</TouchableOpacity>
154+
/>
152155
<UnsupportedImageTypeIndicator indicatorType={indicatorType} />
153156
</View>
154157
);
@@ -170,6 +173,29 @@ const ImageUploadPreviewWithContext = <
170173
) : null;
171174
};
172175

176+
type DismissUploadProps = Pick<TouchableOpacityProps, 'onPress'>;
177+
178+
const DismissUpload = ({ onPress }: DismissUploadProps) => {
179+
const {
180+
theme: {
181+
colors: { overlay, white },
182+
messageInput: {
183+
imageUploadPreview: { dismiss, dismissIconColor },
184+
},
185+
},
186+
} = useTheme();
187+
188+
return (
189+
<TouchableOpacity
190+
onPress={onPress}
191+
style={[styles.dismiss, { backgroundColor: overlay }, dismiss]}
192+
testID='remove-image-upload-preview'
193+
>
194+
<Close pathFill={dismissIconColor || white} />
195+
</TouchableOpacity>
196+
);
197+
};
198+
173199
const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
174200
prevProps: ImageUploadPreviewPropsWithContext<StreamChatGenerics>,
175201
nextProps: ImageUploadPreviewPropsWithContext<StreamChatGenerics>,

package/src/contexts/themeContext/utils/theme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ export type Theme = {
267267
};
268268
imageUploadPreview: {
269269
dismiss: ViewStyle;
270+
dismissIconColor: Color;
270271
flatList: ViewStyle;
271272
itemContainer: ViewStyle;
272273
upload: ImageStyle;
@@ -766,6 +767,7 @@ export const defaultTheme: Theme = {
766767
},
767768
imageUploadPreview: {
768769
dismiss: {},
770+
dismissIconColor: '',
769771
flatList: {},
770772
itemContainer: {},
771773
upload: {},

0 commit comments

Comments
 (0)