@sendbird/uikit-react-native-foundation 3.2.0 → 3.4.0

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 (40) hide show
  1. package/lib/commonjs/components/TextInput/index.js +10 -3
  2. package/lib/commonjs/components/TextInput/index.js.map +1 -1
  3. package/lib/commonjs/index.js +9 -2
  4. package/lib/commonjs/index.js.map +1 -1
  5. package/lib/commonjs/styles/createStyleSheet.js +4 -0
  6. package/lib/commonjs/styles/createStyleSheet.js.map +1 -1
  7. package/lib/commonjs/ui/Avatar/AvatarStack.js +96 -0
  8. package/lib/commonjs/ui/Avatar/AvatarStack.js.map +1 -0
  9. package/lib/commonjs/ui/Avatar/index.js +3 -1
  10. package/lib/commonjs/ui/Avatar/index.js.map +1 -1
  11. package/lib/commonjs/ui/Prompt/index.js +4 -2
  12. package/lib/commonjs/ui/Prompt/index.js.map +1 -1
  13. package/lib/commonjs/ui/TypingIndicatorBubble/index.js +118 -0
  14. package/lib/commonjs/ui/TypingIndicatorBubble/index.js.map +1 -0
  15. package/lib/module/components/TextInput/index.js +10 -3
  16. package/lib/module/components/TextInput/index.js.map +1 -1
  17. package/lib/module/index.js +3 -2
  18. package/lib/module/index.js.map +1 -1
  19. package/lib/module/styles/createStyleSheet.js +4 -0
  20. package/lib/module/styles/createStyleSheet.js.map +1 -1
  21. package/lib/module/ui/Avatar/AvatarStack.js +88 -0
  22. package/lib/module/ui/Avatar/AvatarStack.js.map +1 -0
  23. package/lib/module/ui/Avatar/index.js +3 -1
  24. package/lib/module/ui/Avatar/index.js.map +1 -1
  25. package/lib/module/ui/Prompt/index.js +4 -2
  26. package/lib/module/ui/Prompt/index.js.map +1 -1
  27. package/lib/module/ui/TypingIndicatorBubble/index.js +108 -0
  28. package/lib/module/ui/TypingIndicatorBubble/index.js.map +1 -0
  29. package/lib/typescript/src/index.d.ts +4 -3
  30. package/lib/typescript/src/ui/Avatar/AvatarStack.d.ts +16 -0
  31. package/lib/typescript/src/ui/Avatar/index.d.ts +14 -0
  32. package/lib/typescript/src/ui/TypingIndicatorBubble/index.d.ts +10 -0
  33. package/package.json +3 -3
  34. package/src/components/TextInput/index.tsx +10 -3
  35. package/src/index.ts +4 -4
  36. package/src/styles/createStyleSheet.ts +4 -0
  37. package/src/ui/Avatar/AvatarStack.tsx +103 -0
  38. package/src/ui/Avatar/index.tsx +2 -0
  39. package/src/ui/Prompt/index.tsx +1 -1
  40. package/src/ui/TypingIndicatorBubble/index.tsx +120 -0
package/src/index.ts CHANGED
@@ -26,14 +26,13 @@ export { default as BottomSheet } from './ui/BottomSheet';
26
26
  export { default as Button } from './ui/Button';
27
27
  export { default as ChannelFrozenBanner } from './ui/ChannelFrozenBanner';
28
28
  export { DialogProvider, useActionMenu, useAlert, usePrompt, useBottomSheet } from './ui/Dialog';
29
+ export { default as GroupChannelMessage } from './ui/GroupChannelMessage';
30
+ export type { GroupChannelMessageProps } from './ui/GroupChannelMessage';
31
+ export { default as GroupChannelPreview } from './ui/GroupChannelPreview';
29
32
  export { default as Header } from './ui/Header';
30
33
  export { default as LoadingSpinner } from './ui/LoadingSpinner';
31
34
  export { default as MenuBar } from './ui/MenuBar';
32
35
  export type { MenuBarProps } from './ui/MenuBar';
33
- export { default as GroupChannelMessage } from './ui/GroupChannelMessage';
34
- export type { GroupChannelMessageProps } from './ui/GroupChannelMessage';
35
- export { default as GroupChannelPreview } from './ui/GroupChannelPreview';
36
-
37
36
  export { default as OpenChannelMessage } from './ui/OpenChannelMessage';
38
37
  export type { OpenChannelMessageProps } from './ui/OpenChannelMessage';
39
38
  export { default as OpenChannelPreview } from './ui/OpenChannelPreview';
@@ -42,6 +41,7 @@ export { default as Placeholder } from './ui/Placeholder';
42
41
  export { default as ProfileCard } from './ui/ProfileCard';
43
42
  export { default as Prompt } from './ui/Prompt';
44
43
  export { default as Toast, useToast, ToastProvider } from './ui/Toast';
44
+ export { default as TypingIndicatorBubble } from './ui/TypingIndicatorBubble';
45
45
 
46
46
  /** Styles **/
47
47
  export { default as createSelectByColorScheme } from './styles/createSelectByColorScheme';
@@ -18,11 +18,15 @@ const preProcessor: Partial<StylePreprocessor> = {
18
18
  'height': SCALE_FACTOR_WITH_STR,
19
19
  'width': SCALE_FACTOR_WITH_STR,
20
20
  'padding': SCALE_FACTOR_WITH_STR,
21
+ 'paddingVertical': SCALE_FACTOR_WITH_STR,
22
+ 'paddingHorizontal': SCALE_FACTOR_WITH_STR,
21
23
  'paddingTop': SCALE_FACTOR_WITH_STR,
22
24
  'paddingBottom': SCALE_FACTOR_WITH_STR,
23
25
  'paddingLeft': SCALE_FACTOR_WITH_STR,
24
26
  'paddingRight': SCALE_FACTOR_WITH_STR,
25
27
  'margin': SCALE_FACTOR_WITH_STR,
28
+ 'marginVertical': SCALE_FACTOR_WITH_STR,
29
+ 'marginHorizontal': SCALE_FACTOR_WITH_STR,
26
30
  'marginTop': SCALE_FACTOR_WITH_STR,
27
31
  'marginBottom': SCALE_FACTOR_WITH_STR,
28
32
  'marginLeft': SCALE_FACTOR_WITH_STR,
@@ -0,0 +1,103 @@
1
+ import React, { ReactElement } from 'react';
2
+ import { StyleProp, View, ViewStyle } from 'react-native';
3
+
4
+ import Text from '../../components/Text';
5
+ import useUIKitTheme from '../../theme/useUIKitTheme';
6
+
7
+ const DEFAULT_MAX = 3;
8
+ const DEFAULT_BORDER_WIDTH = 2;
9
+ const DEFAULT_AVATAR_GAP = -4;
10
+ const DEFAULT_AVATAR_SIZE = 26;
11
+ const DEFAULT_REMAINS_MAX = 99;
12
+
13
+ type Props = React.PropsWithChildren<{
14
+ size?: number;
15
+ containerStyle?: StyleProp<ViewStyle>;
16
+ maxAvatar?: number;
17
+ avatarGap?: number;
18
+ styles?: {
19
+ borderWidth?: number;
20
+ borderColor?: string;
21
+ remainsTextColor?: string;
22
+ remainsBackgroundColor?: string;
23
+ };
24
+ }>;
25
+
26
+ const AvatarStack = ({
27
+ children,
28
+ containerStyle,
29
+ styles,
30
+ maxAvatar = DEFAULT_MAX,
31
+ size = DEFAULT_AVATAR_SIZE,
32
+ avatarGap = DEFAULT_AVATAR_GAP,
33
+ }: Props) => {
34
+ const { colors, palette, select } = useUIKitTheme();
35
+ const defaultStyles = {
36
+ borderWidth: DEFAULT_BORDER_WIDTH,
37
+ borderColor: colors.background,
38
+ remainsTextColor: colors.onBackground02,
39
+ remainsBackgroundColor: select({ light: palette.background100, dark: palette.background600 }),
40
+ };
41
+ const avatarStyles = { ...defaultStyles, ...styles };
42
+
43
+ const childrenArray = React.Children.toArray(children).filter((it) => React.isValidElement(it));
44
+ const remains = childrenArray.length - maxAvatar;
45
+ const shouldRenderRemains = remains > 0;
46
+
47
+ const actualSize = size + avatarStyles.borderWidth * 2;
48
+ const actualGap = avatarGap - avatarStyles.borderWidth;
49
+
50
+ const renderAvatars = () => {
51
+ return childrenArray.slice(0, maxAvatar).map((child, index) =>
52
+ React.cloneElement(child as ReactElement, {
53
+ size: actualSize,
54
+ containerStyle: {
55
+ left: actualGap * index,
56
+ borderWidth: avatarStyles.borderWidth,
57
+ borderColor: avatarStyles.borderColor,
58
+ },
59
+ }),
60
+ );
61
+ };
62
+
63
+ const renderRemainsCount = () => {
64
+ if (!shouldRenderRemains) return null;
65
+ return (
66
+ <View
67
+ style={[
68
+ avatarStyles,
69
+ {
70
+ left: actualGap * maxAvatar,
71
+ width: actualSize,
72
+ height: actualSize,
73
+ borderRadius: actualSize / 2,
74
+ alignItems: 'center',
75
+ justifyContent: 'center',
76
+ backgroundColor: avatarStyles.remainsBackgroundColor,
77
+ },
78
+ ]}
79
+ >
80
+ <Text style={{ color: avatarStyles.remainsTextColor, fontSize: 8 }} caption4>
81
+ {`+${Math.min(remains, DEFAULT_REMAINS_MAX)}`}
82
+ </Text>
83
+ </View>
84
+ );
85
+ };
86
+
87
+ const calculateWidth = () => {
88
+ const widthEach = actualSize + actualGap;
89
+ const avatarCountOffset = shouldRenderRemains ? 1 : 0;
90
+ const avatarCount = shouldRenderRemains ? maxAvatar : childrenArray.length;
91
+ const count = avatarCount + avatarCountOffset;
92
+ return widthEach * count + avatarStyles.borderWidth;
93
+ };
94
+
95
+ return (
96
+ <View style={[containerStyle, { left: -avatarStyles.borderWidth, flexDirection: 'row', width: calculateWidth() }]}>
97
+ {renderAvatars()}
98
+ {renderRemainsCount()}
99
+ </View>
100
+ );
101
+ };
102
+
103
+ export default AvatarStack;
@@ -9,6 +9,7 @@ import createStyleSheet from '../../styles/createStyleSheet';
9
9
  import useUIKitTheme from '../../theme/useUIKitTheme';
10
10
  import AvatarGroup from './AvatarGroup';
11
11
  import AvatarIcon from './AvatarIcon';
12
+ import AvatarStack from './AvatarStack';
12
13
 
13
14
  type Props = {
14
15
  uri?: string;
@@ -68,4 +69,5 @@ const styles = createStyleSheet({
68
69
  export default Object.assign(Avatar, {
69
70
  Group: AvatarGroup,
70
71
  Icon: AvatarIcon,
72
+ Stack: AvatarStack,
71
73
  });
@@ -98,7 +98,7 @@ const Prompt = ({
98
98
  variant={'underline'}
99
99
  value={text}
100
100
  onChangeText={setText}
101
- style={{ paddingHorizontal: 0, paddingVertical: 10 }}
101
+ style={{ paddingLeft: 0, paddingRight: 0, paddingTop: 10, paddingBottom: 10 }}
102
102
  />
103
103
  </View>
104
104
 
@@ -0,0 +1,120 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { Animated, Easing, StyleProp, ViewStyle } from 'react-native';
3
+
4
+ import type { SendbirdUser } from '@sendbird/uikit-utils';
5
+
6
+ import Box from '../../components/Box';
7
+ import createStyleSheet from '../../styles/createStyleSheet';
8
+ import useUIKitTheme from '../../theme/useUIKitTheme';
9
+ import Avatar from '../Avatar';
10
+
11
+ type Props = {
12
+ typingUsers: SendbirdUser[];
13
+ containerStyle?: StyleProp<ViewStyle>;
14
+ maxAvatar?: number;
15
+ };
16
+
17
+ const TypingIndicatorBubble = ({ typingUsers, containerStyle, maxAvatar }: Props) => {
18
+ const { select, palette, colors } = useUIKitTheme();
19
+
20
+ if (typingUsers.length === 0) return null;
21
+
22
+ return (
23
+ <Box flexDirection={'row'} justifyContent={'flex-start'} alignItems={'center'} style={containerStyle}>
24
+ <Avatar.Stack
25
+ size={26}
26
+ maxAvatar={maxAvatar}
27
+ styles={{
28
+ remainsTextColor: colors.onBackground02,
29
+ remainsBackgroundColor: select({ light: palette.background100, dark: palette.background400 }),
30
+ }}
31
+ containerStyle={{ marginRight: 12 }}
32
+ >
33
+ {typingUsers.map((user, index) => (
34
+ <Avatar key={index} uri={user.profileUrl} />
35
+ ))}
36
+ </Avatar.Stack>
37
+ <TypingDots
38
+ dotColor={select({ light: palette.background100, dark: palette.background400 })}
39
+ backgroundColor={colors.onBackground02}
40
+ />
41
+ </Box>
42
+ );
43
+ };
44
+
45
+ type TypingDotsProps = {
46
+ dotColor: string;
47
+ backgroundColor: string;
48
+ };
49
+ const TypingDots = ({ dotColor, backgroundColor }: TypingDotsProps) => {
50
+ const animation = useRef(new Animated.Value(0)).current;
51
+ const dots = matrix.map(([timeline, scale, opacity]) => [
52
+ animation.interpolate({ inputRange: timeline, outputRange: scale, extrapolate: 'clamp' }),
53
+ animation.interpolate({ inputRange: timeline, outputRange: opacity, extrapolate: 'clamp' }),
54
+ ]);
55
+
56
+ useEffect(() => {
57
+ const animated = Animated.loop(
58
+ Animated.timing(animation, { toValue: 1.4, duration: 1400, easing: Easing.linear, useNativeDriver: true }),
59
+ );
60
+ animated.start();
61
+ return () => animated.reset();
62
+ }, []);
63
+
64
+ return (
65
+ <Box
66
+ flexDirection={'row'}
67
+ alignItems={'center'}
68
+ justifyContent={'center'}
69
+ borderRadius={16}
70
+ paddingHorizontal={12}
71
+ height={34}
72
+ backgroundColor={dotColor}
73
+ >
74
+ {dots.map(([scale, opacity], index) => {
75
+ return (
76
+ <Animated.View
77
+ key={index}
78
+ style={[
79
+ styles.dot,
80
+ {
81
+ marginRight: index === dots.length - 1 ? 0 : 6,
82
+ opacity: opacity,
83
+ transform: [{ scale: scale }],
84
+ backgroundColor: backgroundColor,
85
+ },
86
+ ]}
87
+ />
88
+ );
89
+ })}
90
+ </Box>
91
+ );
92
+ };
93
+
94
+ const matrix = [
95
+ [
96
+ [0.4, 0.7, 1.0],
97
+ [1.0, 1.2, 1.0],
98
+ [0.12, 0.38, 0.12],
99
+ ],
100
+ [
101
+ [0.6, 0.9, 1.2],
102
+ [1.0, 1.2, 1.0],
103
+ [0.12, 0.38, 0.12],
104
+ ],
105
+ [
106
+ [0.8, 1.1, 1.4],
107
+ [1.0, 1.2, 1.0],
108
+ [0.12, 0.38, 0.12],
109
+ ],
110
+ ];
111
+
112
+ const styles = createStyleSheet({
113
+ dot: {
114
+ width: 8,
115
+ height: 8,
116
+ borderRadius: 4,
117
+ },
118
+ });
119
+
120
+ export default TypingIndicatorBubble;