Skip to content

Commit ad1d08d

Browse files
committed
fix: narrow giphy with reply bg
1 parent 381b9cd commit ad1d08d

2 files changed

Lines changed: 52 additions & 8 deletions

File tree

package/src/components/Attachment/Giphy/Giphy.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Button } from '../../ui/';
2222

2323
export type GiphyPropsWithContext = Pick<
2424
MessageContextValue,
25-
'handleAction' | 'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress'
25+
'handleAction' | 'isMyMessage' | 'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress'
2626
> &
2727
Pick<MessagesContextValue, 'additionalPressableProps' | 'giphyVersion'> & {
2828
attachment: Attachment;
@@ -34,6 +34,7 @@ const GiphyWithContext = (props: GiphyPropsWithContext) => {
3434
attachment,
3535
giphyVersion,
3636
handleAction,
37+
isMyMessage,
3738
onLongPress,
3839
onPress,
3940
onPressIn,
@@ -53,7 +54,7 @@ const GiphyWithContext = (props: GiphyPropsWithContext) => {
5354
},
5455
} = useTheme();
5556

56-
const styles = useStyles();
57+
const styles = useStyles({ isMyMessage });
5758

5859
const uri = image_url || thumb_url;
5960

@@ -122,7 +123,7 @@ const GiphyWithContext = (props: GiphyPropsWithContext) => {
122123
}
123124
}}
124125
testID='giphy-attachment'
125-
style={styles.container}
126+
style={[styles.container, container]}
126127
{...additionalPressableProps}
127128
>
128129
<GiphyImage attachment={attachment} giphyVersion={giphyVersion} />
@@ -134,10 +135,12 @@ const areEqual = (prevProps: GiphyPropsWithContext, nextProps: GiphyPropsWithCon
134135
const {
135136
attachment: { actions: prevActions, image_url: prevImageUrl, thumb_url: prevThumbUrl },
136137
giphyVersion: prevGiphyVersion,
138+
isMyMessage: prevIsMyMessage,
137139
} = prevProps;
138140
const {
139141
attachment: { actions: nextActions, image_url: nextImageUrl, thumb_url: nextThumbUrl },
140142
giphyVersion: nextGiphyVersion,
143+
isMyMessage: nextIsMyMessage,
141144
} = nextProps;
142145

143146
const imageUrlEqual = prevImageUrl === nextImageUrl;
@@ -165,6 +168,11 @@ const areEqual = (prevProps: GiphyPropsWithContext, nextProps: GiphyPropsWithCon
165168
return false;
166169
}
167170

171+
const isMyMessageEqual = prevIsMyMessage === nextIsMyMessage;
172+
if (!isMyMessageEqual) {
173+
return false;
174+
}
175+
168176
return true;
169177
};
170178

@@ -178,7 +186,8 @@ export type GiphyProps = Partial<GiphyPropsWithContext> & {
178186
* UI component for card in attachments.
179187
*/
180188
export const Giphy = (props: GiphyProps) => {
181-
const { handleAction, onLongPress, onPress, onPressIn, preventPress } = useMessageContext();
189+
const { handleAction, isMyMessage, onLongPress, onPress, onPressIn, preventPress } =
190+
useMessageContext();
182191
const { additionalPressableProps, giphyVersion } = useMessagesContext();
183192

184193
return (
@@ -187,6 +196,7 @@ export const Giphy = (props: GiphyProps) => {
187196
additionalPressableProps,
188197
giphyVersion,
189198
handleAction,
199+
isMyMessage,
190200
onLongPress,
191201
onPress,
192202
onPressIn,
@@ -199,14 +209,16 @@ export const Giphy = (props: GiphyProps) => {
199209

200210
Giphy.displayName = 'Giphy{messageItemView{giphy}}';
201211

202-
const useStyles = () => {
212+
const useStyles = ({ isMyMessage }: Pick<GiphyPropsWithContext, 'isMyMessage'>) => {
203213
const {
204214
theme: { semantics },
205215
} = useTheme();
206216
return useMemo(() => {
207217
return StyleSheet.create({
208218
container: {
209-
backgroundColor: semantics.chatBgOutgoing,
219+
backgroundColor: isMyMessage
220+
? semantics.chatBgAttachmentOutgoing
221+
: semantics.chatBgAttachmentIncoming,
210222
borderRadius: primitives.radiusLg,
211223
maxWidth: 256, // TODO: Not sure how to fix this
212224
overflow: 'hidden',
@@ -240,5 +252,5 @@ const useStyles = () => {
240252
lineHeight: primitives.typographyLineHeightTight,
241253
},
242254
});
243-
}, [semantics]);
255+
}, [isMyMessage, semantics]);
244256
};

package/src/components/Attachment/__tests__/Giphy.test.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { MessageProvider } from '../../../contexts/messageContext/MessageContext
1414
import { MessagesProvider } from '../../../contexts/messagesContext/MessagesContext';
1515
import { OverlayProvider } from '../../../contexts/overlayContext/OverlayProvider';
1616

17-
import { ThemeProvider } from '../../../contexts/themeContext/ThemeContext';
17+
import { mergeThemes, ThemeProvider } from '../../../contexts/themeContext/ThemeContext';
1818
import { getOrCreateChannelApi } from '../../../mock-builders/api/getOrCreateChannel';
1919
import { useMockedApis } from '../../../mock-builders/api/useMockedApis';
2020
import { generateGiphyAttachment } from '../../../mock-builders/generator/attachment';
@@ -36,6 +36,8 @@ const streami18n = new Streami18n({
3636
});
3737

3838
describe('Giphy', () => {
39+
const lightTheme = mergeThemes({ scheme: 'light' });
40+
3941
const getAttachmentComponent = (props, messageContextValue = {}) => {
4042
const message = generateMessage();
4143
return (
@@ -115,6 +117,36 @@ describe('Giphy', () => {
115117
});
116118
});
117119

120+
it('uses the outgoing attachment background for outgoing giphys', async () => {
121+
render(getAttachmentComponent({ attachment }, { isMyMessage: true }));
122+
123+
await waitFor(() => {
124+
const style = screen.getByTestId('giphy-attachment').props.style;
125+
expect(style).toEqual(
126+
expect.arrayContaining([
127+
expect.objectContaining({
128+
backgroundColor: lightTheme.semantics.chatBgAttachmentOutgoing,
129+
}),
130+
]),
131+
);
132+
});
133+
});
134+
135+
it('uses the incoming attachment background for incoming giphys', async () => {
136+
render(getAttachmentComponent({ attachment }, { isMyMessage: false }));
137+
138+
await waitFor(() => {
139+
const style = screen.getByTestId('giphy-attachment').props.style;
140+
expect(style).toEqual(
141+
expect.arrayContaining([
142+
expect.objectContaining({
143+
backgroundColor: lightTheme.semantics.chatBgAttachmentIncoming,
144+
}),
145+
]),
146+
);
147+
});
148+
});
149+
118150
it('"giphy" attachment size should be customisable', async () => {
119151
attachment.giphy = giphy;
120152
render(getAttachmentComponent({ attachment, giphyVersion: 'fixed_height' }));

0 commit comments

Comments
 (0)