@sendbird/uikit-react-native-foundation 3.2.0 → 3.3.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.
- package/lib/commonjs/components/TextInput/index.js +10 -3
- package/lib/commonjs/components/TextInput/index.js.map +1 -1
- package/lib/commonjs/index.js +9 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/styles/createStyleSheet.js +4 -0
- package/lib/commonjs/styles/createStyleSheet.js.map +1 -1
- package/lib/commonjs/ui/Avatar/AvatarStack.js +96 -0
- package/lib/commonjs/ui/Avatar/AvatarStack.js.map +1 -0
- package/lib/commonjs/ui/Avatar/index.js +3 -1
- package/lib/commonjs/ui/Avatar/index.js.map +1 -1
- package/lib/commonjs/ui/TypingIndicatorBubble/index.js +118 -0
- package/lib/commonjs/ui/TypingIndicatorBubble/index.js.map +1 -0
- package/lib/module/components/TextInput/index.js +10 -3
- package/lib/module/components/TextInput/index.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/styles/createStyleSheet.js +4 -0
- package/lib/module/styles/createStyleSheet.js.map +1 -1
- package/lib/module/ui/Avatar/AvatarStack.js +88 -0
- package/lib/module/ui/Avatar/AvatarStack.js.map +1 -0
- package/lib/module/ui/Avatar/index.js +3 -1
- package/lib/module/ui/Avatar/index.js.map +1 -1
- package/lib/module/ui/TypingIndicatorBubble/index.js +108 -0
- package/lib/module/ui/TypingIndicatorBubble/index.js.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -3
- package/lib/typescript/src/ui/Avatar/AvatarStack.d.ts +16 -0
- package/lib/typescript/src/ui/Avatar/index.d.ts +14 -0
- package/lib/typescript/src/ui/TypingIndicatorBubble/index.d.ts +10 -0
- package/package.json +3 -3
- package/src/components/TextInput/index.tsx +10 -3
- package/src/index.ts +4 -4
- package/src/styles/createStyleSheet.ts +4 -0
- package/src/ui/Avatar/AvatarStack.tsx +103 -0
- package/src/ui/Avatar/index.tsx +2 -0
- package/src/ui/TypingIndicatorBubble/index.tsx +120 -0
|
@@ -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;
|
package/src/ui/Avatar/index.tsx
CHANGED
|
@@ -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
|
});
|
|
@@ -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;
|