Skip to content

Commit cebd7cf

Browse files
committed
2 parents e445e9c + 8a2be89 commit cebd7cf

File tree

13 files changed

+100
-23
lines changed

13 files changed

+100
-23
lines changed

docusaurus/docs/reactnative/common-content/contexts/image-gallery-context/set_image.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Setter for value [`image`](../../../contexts/message_input_context.mdx#image).
1+
Setter for value [`image`](../../../contexts/image_gallery_context.mdx#image).
22

33
| Type |
44
| ------------------------------------------------------ |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Setter for value [`images`](../../../contexts/image_gallery_context.mdx#images).
2+
3+
| Type |
4+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
5+
| `(messageWithImages: [MessageType](https://github.com/GetStream/stream-chat-react-native/blob/master/package/src/components/MessageList/hooks/useMessageList.ts)[]) => void` |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The giphy version to render when viewing a Giphy in the Image Gallery.
2+
Check the keys of the [Image Object](https://developers.giphy.com/docs/api/schema#image-object) for possible values.
3+
4+
| Type | Default |
5+
| ------ | -------------- |
6+
| string | 'fixed_height' |

docusaurus/docs/reactnative/core-components/overlay_provider.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import AttachmentPickerBottomSheetHeight from '../common-content/core-components
1212
import AttachmentPickerErrorButtonText from '../common-content/core-components/overlay-provider/props/attachment_picker_error_button_text.mdx';
1313
import AttachmentPickerErrorText from '../common-content/core-components/overlay-provider/props/attachment_picker_error_text.mdx';
1414
import AttachmentSelectionBarHeight from '../common-content/core-components/overlay-provider/props/attachment_selection_bar_height.mdx';
15+
import GiphyVersion from '../common-content/core-components/overlay-provider/props/giphy_version.mdx';
1516
import I18nInstance from '../common-content/core-components/overlay-provider/props/i18n_instance.mdx';
1617
import ImageGalleryCustomComponents from '../common-content/core-components/overlay-provider/props/image_gallery_custom_components.mdx';
1718
import ImageGalleryGridHandleHeight from '../common-content/core-components/overlay-provider/props/image_gallery_grid_handle_height.mdx';
@@ -153,6 +154,10 @@ This can also be set via the `setBottomInset` function provided by the `useAttac
153154
| ------ | ------- |
154155
| number | 0 |
155156

157+
### giphyVersion
158+
159+
<GiphyVersion />
160+
156161
### i18nInstance
157162

158163
<I18nInstance />

docusaurus/docs/reactnative/ui-components/gallery.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ title: Gallery
44
---
55

66
import SetImage from '../common-content/contexts/image-gallery-context/set_image.mdx';
7+
import SetImages from '../common-content/contexts/image-gallery-context/set_images.mdx';
78

89
import Alignment from '../common-content/contexts/message-context/alignment.mdx';
910
import GroupStyles from '../common-content/contexts/message-context/group_styles.mdx';
@@ -112,6 +113,10 @@ If true, onPress handler will be disabled.
112113

113114
<SetImage />
114115

116+
### <div class="label description">_overrides the value from [ImageGalleryContext](../contexts/image_gallery_context.mdx#setimages)_</div> setImages {#setimages}
117+
118+
<SetImages />
119+
115120
### <div class="label description">_overrides the value from [OverlayContext](../contexts/overlay_context.mdx#setoverlay)_</div> setOverlay {#setoverlay}
116121

117122
<SetOverlay />

docusaurus/docs/reactnative/ui-components/giphy.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import HandleAction from '../common-content/contexts/message-context/handle_acti
77
import OnLongPress from '../common-content/contexts/message-context/on_long_press.mdx';
88
import OnPress from '../common-content/contexts/message-context/on_press.mdx';
99
import OnPressIn from '../common-content/contexts/message-context/on_press_in.mdx';
10+
import SetImage from '../common-content/contexts/image-gallery-context/set_image.mdx';
11+
import SetImages from '../common-content/contexts/image-gallery-context/set_images.mdx';
1012

1113
import AdditionalTouchableProps from '../common-content/core-components/channel/props/additional_touchable_props.mdx';
14+
import SetOverlay from '../common-content/contexts/overlay-context/set_overlay.mdx';
1215

1316
Component to render giphy attachments within the [`MessageList`](./message_list.mdx).
1417

@@ -43,3 +46,15 @@ Attachment object for `giphy` type attachment.
4346
### <div class="label description">_overrides the value from [MessageContext](../contexts/message_context.mdx#onpressin)_</div> onPressIn {#onpressin}
4447

4548
<OnPressIn />
49+
50+
### <div class="label description">_overrides the value from [ImageGalleryContext](../contexts/image_gallery_context.mdx#setimage)_</div> setImage {#setimage}
51+
52+
<SetImage />
53+
54+
### <div class="label description">_overrides the value from [ImageGalleryContext](../contexts/image_gallery_context.mdx#setimages)_</div> setImages {#setimages}
55+
56+
<SetImages />
57+
58+
### <div class="label description">_overrides the value from [OverlayContext](../contexts/overlay_context.mdx#setoverlay)_</div> setOverlay {#setoverlay}
59+
60+
<SetOverlay />

examples/SampleApp/ios/SampleApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@
495495
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
496496
CLANG_ENABLE_MODULES = YES;
497497
CODE_SIGN_IDENTITY = "iPhone Distribution";
498-
CURRENT_PROJECT_VERSION = 77;
498+
CURRENT_PROJECT_VERSION = 78;
499499
DEVELOPMENT_TEAM = EHV7XZLAHA;
500500
ENABLE_BITCODE = NO;
501501
INFOPLIST_FILE = SampleApp/Info.plist;
@@ -525,7 +525,7 @@
525525
CLANG_ENABLE_MODULES = YES;
526526
CODE_SIGN_IDENTITY = "iPhone Distribution";
527527
CODE_SIGN_STYLE = Manual;
528-
CURRENT_PROJECT_VERSION = 77;
528+
CURRENT_PROJECT_VERSION = 78;
529529
DEVELOPMENT_TEAM = EHV7XZLAHA;
530530
INFOPLIST_FILE = SampleApp/Info.plist;
531531
LD_RUNPATH_SEARCH_PATHS = (

examples/SampleApp/ios/SampleApp/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>77</string>
24+
<string>78</string>
2525
<key>LSRequiresIPhoneOS</key>
2626
<true />
2727
<key>NSAppTransportSecurity</key>

examples/SampleApp/ios/SampleAppTests/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>77</string>
22+
<string>78</string>
2323
</dict>
2424
</plist>

package/src/components/Attachment/Giphy.tsx

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
33

44
import type { Attachment } from 'stream-chat';
55

6+
import {
7+
ImageGalleryContextValue,
8+
useImageGalleryContext,
9+
} from '../../contexts/imageGalleryContext/ImageGalleryContext';
610
import {
711
MessageContextValue,
812
useMessageContext,
@@ -11,6 +15,10 @@ import {
1115
MessagesContextValue,
1216
useMessagesContext,
1317
} from '../../contexts/messagesContext/MessagesContext';
18+
import {
19+
OverlayContextValue,
20+
useOverlayContext,
21+
} from '../../contexts/overlayContext/OverlayContext';
1422
import { useTheme } from '../../contexts/themeContext/ThemeContext';
1523
import { GiphyIcon } from '../../icons';
1624
import { Lightning } from '../../icons/Lightning';
@@ -107,13 +115,20 @@ const styles = StyleSheet.create({
107115

108116
export type GiphyPropsWithContext<
109117
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
110-
> = Pick<
111-
MessageContextValue<StreamChatGenerics>,
112-
'handleAction' | 'isMyMessage' | 'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress'
113-
> &
118+
> = Pick<ImageGalleryContextValue<StreamChatGenerics>, 'setImage' | 'setImages'> &
119+
Pick<
120+
MessageContextValue<StreamChatGenerics>,
121+
| 'handleAction'
122+
| 'isMyMessage'
123+
| 'message'
124+
| 'onLongPress'
125+
| 'onPress'
126+
| 'onPressIn'
127+
| 'preventPress'
128+
> &
114129
Pick<MessagesContextValue<StreamChatGenerics>, 'giphyVersion' | 'additionalTouchableProps'> & {
115130
attachment: Attachment<StreamChatGenerics>;
116-
};
131+
} & Pick<OverlayContextValue, 'setOverlay'>;
117132

118133
const GiphyWithContext = <
119134
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -123,12 +138,17 @@ const GiphyWithContext = <
123138
const {
124139
additionalTouchableProps,
125140
attachment,
141+
giphyVersion,
126142
handleAction,
127143
isMyMessage,
144+
message,
128145
onLongPress,
129146
onPress,
130147
onPressIn,
131148
preventPress,
149+
setImage,
150+
setImages,
151+
setOverlay,
132152
} = props;
133153

134154
const { actions, giphy: giphyData, image_url, thumb_url, title, type } = attachment;
@@ -159,8 +179,14 @@ const GiphyWithContext = <
159179
let uri = image_url || thumb_url;
160180
const giphyDimensions: { height?: number; width?: number } = {};
161181

182+
const defaultOnPress = () => {
183+
setImages([message]);
184+
setImage({ messageId: message.id, url: uri });
185+
setOverlay('gallery');
186+
};
187+
162188
if (type === 'giphy' && giphyData) {
163-
const giphyVersionInfo = giphyData[props.giphyVersion];
189+
const giphyVersionInfo = giphyData[giphyVersion];
164190
uri = giphyVersionInfo.url;
165191
giphyDimensions.height = parseFloat(giphyVersionInfo.height);
166192
giphyDimensions.width = parseFloat(giphyVersionInfo.width);
@@ -247,6 +273,7 @@ const GiphyWithContext = <
247273
onPress={(event) => {
248274
if (onPress) {
249275
onPress({
276+
defaultHandler: defaultOnPress,
250277
emitter: 'giphy',
251278
event,
252279
});
@@ -337,10 +364,7 @@ const MemoizedGiphy = React.memo(GiphyWithContext, areEqual) as typeof GiphyWith
337364

338365
export type GiphyProps<
339366
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
340-
> = Partial<
341-
Pick<MessageContextValue<StreamChatGenerics>, 'isMyMessage' | 'onLongPress' | 'onPressIn'> &
342-
Pick<MessagesContextValue<StreamChatGenerics>, 'giphyVersion' | 'additionalTouchableProps'>
343-
> & {
367+
> = Partial<GiphyPropsWithContext<StreamChatGenerics>> & {
344368
attachment: Attachment<StreamChatGenerics>;
345369
};
346370

@@ -352,21 +376,26 @@ export const Giphy = <
352376
>(
353377
props: GiphyProps<StreamChatGenerics>,
354378
) => {
355-
const { handleAction, isMyMessage, onLongPress, onPress, onPressIn, preventPress } =
379+
const { handleAction, isMyMessage, message, onLongPress, onPress, onPressIn, preventPress } =
356380
useMessageContext<StreamChatGenerics>();
357381
const { additionalTouchableProps, giphyVersion } = useMessagesContext<StreamChatGenerics>();
358-
382+
const { setImage, setImages } = useImageGalleryContext<StreamChatGenerics>();
383+
const { setOverlay } = useOverlayContext();
359384
return (
360385
<MemoizedGiphy
361386
{...{
362387
additionalTouchableProps,
363388
giphyVersion,
364389
handleAction,
365390
isMyMessage,
391+
message,
366392
onLongPress,
367393
onPress,
368394
onPressIn,
369395
preventPress,
396+
setImage,
397+
setImages,
398+
setOverlay,
370399
}}
371400
{...props}
372401
/>

0 commit comments

Comments
 (0)