Skip to content

Commit 22579c9

Browse files
committed
fix: add emoji fallback icon
1 parent d981ebe commit 22579c9

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

packages/uikit-react-native/src/components/ReactionAddons/MessageReactionAddon.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react';
22
import { Pressable } from 'react-native';
33

4-
import type { Emoji } from '@sendbird/chat';
5-
import { createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
4+
import { Icon, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
65
import { useForceUpdate, useGroupChannelHandler } from '@sendbird/uikit-tools';
7-
import type { SendbirdBaseChannel, SendbirdBaseMessage, SendbirdReaction } from '@sendbird/uikit-utils';
6+
import type { SendbirdBaseChannel, SendbirdBaseMessage, SendbirdEmoji, SendbirdReaction } from '@sendbird/uikit-utils';
87
import { getReactionCount } from '@sendbird/uikit-utils';
98

109
import { DEFAULT_LONG_PRESS_DELAY } from '../../constants';
@@ -33,7 +32,7 @@ const createOnPressReaction = (
3332
const createReactionButtons = (
3433
channel: SendbirdBaseChannel,
3534
message: SendbirdBaseMessage,
36-
getEmoji: (key: string) => Emoji,
35+
getEmoji: (key: string) => SendbirdEmoji | undefined,
3736
emojiLimit: number,
3837
onOpenReactionList: () => void,
3938
onOpenReactionUserList: (focusIndex: number) => void,
@@ -50,18 +49,21 @@ const createReactionButtons = (
5049
onLongPress={() => onOpenReactionUserList(index)}
5150
delayLongPress={DEFAULT_LONG_PRESS_DELAY}
5251
>
53-
{({ pressed }) => (
54-
<ReactionRoundedButton
55-
url={getEmoji(reaction.key).url}
56-
count={getReactionCount(reaction)}
57-
reacted={pressed || reaction.hasCurrentUserReacted}
58-
style={
59-
reactionAddonType === 'default'
60-
? [isNotLastOfRow && styles.marginEnd, isNotLastOfCol && styles.marginBottom]
61-
: [styles.marginEnd, styles.marginBottom]
62-
}
63-
/>
64-
)}
52+
{({ pressed }) => {
53+
const emoji = getEmoji(reaction.key);
54+
return (
55+
<ReactionRoundedButton
56+
source={emoji ? { uri: emoji.url } : Icon.Assets.question}
57+
count={getReactionCount(reaction)}
58+
reacted={pressed || reaction.hasCurrentUserReacted}
59+
style={
60+
reactionAddonType === 'default'
61+
? [isNotLastOfRow && styles.marginEnd, isNotLastOfCol && styles.marginBottom]
62+
: [styles.marginEnd, styles.marginBottom]
63+
}
64+
/>
65+
);
66+
}}
6567
</Pressable>
6668
);
6769
});

packages/uikit-react-native/src/components/ReactionAddons/ReactionRoundedButton.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import React from 'react';
2-
import { StyleProp, View, ViewStyle } from 'react-native';
2+
import { ImageProps, StyleProp, View, ViewStyle } from 'react-native';
33

44
import { Icon, Image, Text, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
55
import { truncatedCount } from '@sendbird/uikit-utils';
66

77
type Props = {
8-
url: string;
8+
source: ImageProps['source'];
99
count: number;
1010
reacted: boolean;
1111
style: StyleProp<ViewStyle>;
12+
/**
13+
* @deprecated Please use `source` instead
14+
* */
15+
url?: string;
1216
};
1317

14-
const ReactionRoundedButton = ({ url, count, reacted, style }: Props) => {
18+
const ReactionRoundedButton = ({ source, count, reacted, style, url }: Props) => {
1519
const { colors } = useUIKitTheme();
1620
const color = colors.ui.reaction.rounded;
1721

@@ -23,7 +27,7 @@ const ReactionRoundedButton = ({ url, count, reacted, style }: Props) => {
2327
style,
2428
]}
2529
>
26-
<Image source={{ uri: url }} style={styles.emoji} />
30+
<Image source={source ? source : { uri: url }} style={styles.emoji} />
2731
<Text caption4 color={colors.onBackground01} numberOfLines={1} style={styles.count}>
2832
{truncatedCount(count, 99, '')}
2933
</Text>

packages/uikit-react-native/src/components/ReactionBottomSheets/ReactionUserListBottomSheet.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import { Animated, Easing, I18nManager, Pressable, ScrollView, View, useWindowDi
44
import {
55
Avatar,
66
Divider,
7+
Icon,
78
Image,
89
Modal,
910
Text,
1011
createStyleSheet,
1112
useUIKitTheme,
1213
} from '@sendbird/uikit-react-native-foundation';
13-
import { SendbirdReaction, getReactionCount, truncatedCount, useSafeAreaPadding } from '@sendbird/uikit-utils';
14+
import {
15+
SendbirdEmoji,
16+
SendbirdReaction,
17+
getReactionCount,
18+
truncatedCount,
19+
useSafeAreaPadding,
20+
} from '@sendbird/uikit-utils';
1421

1522
import type { ReactionBottomSheetProps } from './index';
1623

@@ -81,7 +88,7 @@ const ReactionUserListBottomSheet = ({
8188
{reactions.map((reaction, index) => {
8289
const isFocused = focusedReaction?.key === reaction.key;
8390
const isLastItem = reactions.length - 1 === index;
84-
const emoji = emojiManager.allEmojiMap[reaction.key];
91+
const emoji = emojiManager.allEmojiMap[reaction.key] as SendbirdEmoji | undefined;
8592

8693
return (
8794
<Pressable
@@ -102,7 +109,7 @@ const ReactionUserListBottomSheet = ({
102109
}
103110
}}
104111
>
105-
<Image source={{ uri: emoji.url }} style={styles.tabEmoji} />
112+
<Image source={emoji ? { uri: emoji.url } : Icon.Assets.question} style={styles.tabEmoji} />
106113
<Text button color={isFocused ? color.selected.highlight : color.enabled.highlight}>
107114
{truncatedCount(getReactionCount(reaction))}
108115
</Text>

0 commit comments

Comments
 (0)