@sendbird/uikit-react-native 3.12.2 → 3.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/lib/commonjs/components/ReactionAddons/BottomSheetReactionAddon.js +57 -27
  2. package/lib/commonjs/components/ReactionAddons/BottomSheetReactionAddon.js.map +1 -1
  3. package/lib/commonjs/components/ReactionAddons/MessageReactionAddon.js +46 -17
  4. package/lib/commonjs/components/ReactionAddons/MessageReactionAddon.js.map +1 -1
  5. package/lib/commonjs/components/ReactionBottomSheets/ReactionListBottomSheet.js +52 -30
  6. package/lib/commonjs/components/ReactionBottomSheets/ReactionListBottomSheet.js.map +1 -1
  7. package/lib/commonjs/version.js +1 -1
  8. package/lib/commonjs/version.js.map +1 -1
  9. package/lib/module/components/ReactionAddons/BottomSheetReactionAddon.js +56 -26
  10. package/lib/module/components/ReactionAddons/BottomSheetReactionAddon.js.map +1 -1
  11. package/lib/module/components/ReactionAddons/MessageReactionAddon.js +45 -17
  12. package/lib/module/components/ReactionAddons/MessageReactionAddon.js.map +1 -1
  13. package/lib/module/components/ReactionBottomSheets/ReactionListBottomSheet.js +51 -29
  14. package/lib/module/components/ReactionBottomSheets/ReactionListBottomSheet.js.map +1 -1
  15. package/lib/module/version.js +1 -1
  16. package/lib/module/version.js.map +1 -1
  17. package/lib/typescript/src/components/ReactionAddons/BottomSheetReactionAddon.d.ts +1 -1
  18. package/lib/typescript/src/containers/SendbirdUIKitContainer.d.ts +1 -1
  19. package/lib/typescript/src/hooks/useChannelInputItems.d.ts +1 -1
  20. package/lib/typescript/src/version.d.ts +1 -1
  21. package/package.json +5 -5
  22. package/src/components/ReactionAddons/BottomSheetReactionAddon.tsx +65 -18
  23. package/src/components/ReactionAddons/MessageReactionAddon.tsx +61 -25
  24. package/src/components/ReactionBottomSheets/ReactionListBottomSheet.tsx +61 -27
  25. package/src/version.ts +1 -1
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { ImageProps, Pressable } from 'react-native';
1
+ import React, { useState } from 'react';
2
+ import { ImageProps, Pressable, StyleProp, ViewStyle } from 'react-native';
3
3
 
4
4
  import { createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
5
5
  import { useForceUpdate, useGroupChannelHandler } from '@sendbird/uikit-tools';
@@ -29,6 +29,51 @@ const createOnPressReaction = (
29
29
  };
30
30
  };
31
31
 
32
+ const ReactionPressable = ({
33
+ reaction,
34
+ channel,
35
+ message,
36
+ source,
37
+ onOpenReactionUserList,
38
+ index,
39
+ style,
40
+ }: {
41
+ reaction: SendbirdReaction;
42
+ channel: SendbirdBaseChannel;
43
+ message: SendbirdBaseMessage;
44
+ source: ImageProps['source'];
45
+ onOpenReactionUserList: (focusIndex: number) => void;
46
+ index: number;
47
+ style: StyleProp<ViewStyle>;
48
+ }) => {
49
+ const [pressed, setPressed] = useState(false);
50
+ return (
51
+ <Pressable
52
+ onPress={createOnPressReaction(reaction, channel, message, reaction.hasCurrentUserReacted)}
53
+ onLongPress={() => onOpenReactionUserList(index)}
54
+ delayLongPress={DEFAULT_LONG_PRESS_DELAY}
55
+ onPressIn={() => setPressed(true)}
56
+ onPressOut={() => setPressed(false)}
57
+ >
58
+ <ReactionRoundedButton
59
+ source={source}
60
+ count={getReactionCount(reaction)}
61
+ reacted={pressed || reaction.hasCurrentUserReacted}
62
+ style={style}
63
+ />
64
+ </Pressable>
65
+ );
66
+ };
67
+
68
+ const ReactionMorePressable = ({ onPress }: { onPress: () => void }) => {
69
+ const [pressed, setPressed] = useState(false);
70
+ return (
71
+ <Pressable onPress={onPress} onPressIn={() => setPressed(true)} onPressOut={() => setPressed(false)}>
72
+ <ReactionRoundedButton.More pressed={pressed} />
73
+ </Pressable>
74
+ );
75
+ };
76
+
32
77
  const createReactionButtons = (
33
78
  channel: SendbirdBaseChannel,
34
79
  message: SendbirdBaseMessage,
@@ -43,33 +88,24 @@ const createReactionButtons = (
43
88
  const isNotLastOfRow = index % NUM_COL !== NUM_COL - 1;
44
89
  const isNotLastOfCol = index < NUM_COL && reactions.length >= NUM_COL;
45
90
  return (
46
- <Pressable
91
+ <ReactionPressable
47
92
  key={reaction.key}
48
- onPress={createOnPressReaction(reaction, channel, message, reaction.hasCurrentUserReacted)}
49
- onLongPress={() => onOpenReactionUserList(index)}
50
- delayLongPress={DEFAULT_LONG_PRESS_DELAY}
51
- >
52
- {({ pressed }) => (
53
- <ReactionRoundedButton
54
- source={getIconSource(reaction.key)}
55
- count={getReactionCount(reaction)}
56
- reacted={pressed || reaction.hasCurrentUserReacted}
57
- style={
58
- reactionAddonType === 'default'
59
- ? [isNotLastOfRow && styles.marginEnd, isNotLastOfCol && styles.marginBottom]
60
- : [styles.marginEnd, styles.marginBottom]
61
- }
62
- />
63
- )}
64
- </Pressable>
93
+ reaction={reaction}
94
+ channel={channel}
95
+ message={message}
96
+ source={getIconSource(reaction.key)}
97
+ onOpenReactionUserList={onOpenReactionUserList}
98
+ index={index}
99
+ style={
100
+ reactionAddonType === 'default'
101
+ ? [isNotLastOfRow && styles.marginEnd, isNotLastOfCol && styles.marginBottom]
102
+ : [styles.marginEnd, styles.marginBottom]
103
+ }
104
+ />
65
105
  );
66
106
  });
67
107
  if (buttons.length < emojiLimit) {
68
- buttons.push(
69
- <Pressable key={REACTION_MORE_KEY} onPress={onOpenReactionList}>
70
- {({ pressed }) => <ReactionRoundedButton.More pressed={pressed} />}
71
- </Pressable>,
72
- );
108
+ buttons.push(<ReactionMorePressable key={REACTION_MORE_KEY} onPress={onOpenReactionList} />);
73
109
  }
74
110
 
75
111
  return buttons;
@@ -1,13 +1,63 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { FlatList, Pressable, View, useWindowDimensions } from 'react-native';
3
3
 
4
4
  import type { BaseMessage } from '@sendbird/chat/message';
5
5
  import { Image, Modal, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
6
6
  import { Logger, useSafeAreaPadding } from '@sendbird/uikit-utils';
7
+ import type { SendbirdBaseChannel, SendbirdBaseMessage } from '@sendbird/uikit-utils';
7
8
 
8
9
  import { UNKNOWN_USER_ID } from '../../constants';
9
10
  import type { ReactionBottomSheetProps } from './index';
10
11
 
12
+ const ReactionEmojiPressable = ({
13
+ emojiKey,
14
+ url,
15
+ message,
16
+ channel,
17
+ currentUserId,
18
+ selectedBackground,
19
+ enabledBackground,
20
+ onClose,
21
+ }: {
22
+ emojiKey: string;
23
+ url: string;
24
+ message: SendbirdBaseMessage | undefined;
25
+ channel: SendbirdBaseChannel | undefined;
26
+ currentUserId: string | undefined;
27
+ selectedBackground: string;
28
+ enabledBackground: string;
29
+ onClose: () => Promise<void>;
30
+ }) => {
31
+ const [pressed, setPressed] = useState(false);
32
+
33
+ const reactedUserIds = message?.reactions?.find((it) => it.key === emojiKey)?.userIds ?? [];
34
+ const idx = reactedUserIds.indexOf(currentUserId ?? UNKNOWN_USER_ID);
35
+ const reacted = idx > -1;
36
+
37
+ return (
38
+ <Pressable
39
+ onPress={async () => {
40
+ if (message && channel) {
41
+ const action = (msg: BaseMessage, key: string) => {
42
+ return reacted ? channel.deleteReaction(msg, key) : channel.addReaction(msg, key);
43
+ };
44
+
45
+ action(message, emojiKey).catch((error) => {
46
+ const operation = reacted ? 'remove' : 'add';
47
+ Logger.warn(`Failed to ${operation} reaction (emojiKey=${emojiKey})`, error);
48
+ });
49
+ }
50
+ await onClose();
51
+ }}
52
+ onPressIn={() => setPressed(true)}
53
+ onPressOut={() => setPressed(false)}
54
+ style={[styles.button, { backgroundColor: reacted || pressed ? selectedBackground : enabledBackground }]}
55
+ >
56
+ <Image source={{ uri: url }} style={styles.emoji} />
57
+ </Pressable>
58
+ );
59
+ };
60
+
11
61
  const NUM_COLUMN = 6;
12
62
  const ReactionListBottomSheet = ({ visible, onClose, onDismiss, reactionCtx, chatCtx }: ReactionBottomSheetProps) => {
13
63
  const { width } = useWindowDimensions();
@@ -45,34 +95,18 @@ const ReactionListBottomSheet = ({ visible, onClose, onDismiss, reactionCtx, cha
45
95
  contentContainerStyle={styles.flatlist}
46
96
  ItemSeparatorComponent={() => <View style={{ height: 16 }} />}
47
97
  renderItem={({ item: { key, url } }) => {
48
- const reactedUserIds = message?.reactions?.find((it) => it.key === key)?.userIds ?? [];
49
-
50
- const idx = reactedUserIds.indexOf(currentUser?.userId ?? UNKNOWN_USER_ID);
51
- const reacted = idx > -1;
52
-
53
98
  return (
54
99
  <View style={styles.emojiItem}>
55
- <Pressable
56
- key={key}
57
- onPress={async () => {
58
- if (message && channel) {
59
- const action = (message: BaseMessage, key: string) => {
60
- return reacted ? channel.deleteReaction(message, key) : channel.addReaction(message, key);
61
- };
62
-
63
- action(message, key).catch((error) => {
64
- Logger.warn('Failed to reaction', error);
65
- });
66
- }
67
- await onClose();
68
- }}
69
- style={({ pressed }) => [
70
- styles.button,
71
- { backgroundColor: reacted || pressed ? color.selected.background : color.enabled.background },
72
- ]}
73
- >
74
- <Image source={{ uri: url }} style={styles.emoji} />
75
- </Pressable>
100
+ <ReactionEmojiPressable
101
+ emojiKey={key}
102
+ url={url}
103
+ message={message}
104
+ channel={channel}
105
+ currentUserId={currentUser?.userId}
106
+ selectedBackground={color.selected.background}
107
+ enabledBackground={color.enabled.background}
108
+ onClose={onClose}
109
+ />
76
110
  </View>
77
111
  );
78
112
  }}
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- const VERSION = '3.12.2';
1
+ const VERSION = '3.12.3';
2
2
  export default VERSION;