@droppii-org/chat-mobile 0.2.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/LICENSE +20 -0
- package/README.md +101 -0
- package/lib/module/assets/images/icon_bot.png +0 -0
- package/lib/module/assets/images/index.js +9 -0
- package/lib/module/assets/images/index.js.map +1 -0
- package/lib/module/assets/images/tag_bot.png +0 -0
- package/lib/module/assets/images/tag_mall.png +0 -0
- package/lib/module/build-ignore.d.js +2 -0
- package/lib/module/build-ignore.d.js.map +1 -0
- package/lib/module/components/Avatar/Avatar.js +81 -0
- package/lib/module/components/Avatar/Avatar.js.map +1 -0
- package/lib/module/components/Avatar/Avatar.types.js +2 -0
- package/lib/module/components/Avatar/Avatar.types.js.map +1 -0
- package/lib/module/components/Avatar/Avatar.utils.js +44 -0
- package/lib/module/components/Avatar/Avatar.utils.js.map +1 -0
- package/lib/module/components/Avatar/AvatarBadge.js +28 -0
- package/lib/module/components/Avatar/AvatarBadge.js.map +1 -0
- package/lib/module/components/Avatar/DoubleAvatar.js +74 -0
- package/lib/module/components/Avatar/DoubleAvatar.js.map +1 -0
- package/lib/module/components/Avatar/SingleAvatar.js +53 -0
- package/lib/module/components/Avatar/SingleAvatar.js.map +1 -0
- package/lib/module/components/Avatar/index.js +7 -0
- package/lib/module/components/Avatar/index.js.map +1 -0
- package/lib/module/components/ThreadCard/AvatarSection.js +37 -0
- package/lib/module/components/ThreadCard/AvatarSection.js.map +1 -0
- package/lib/module/components/ThreadCard/NamePrefixIcon.js +36 -0
- package/lib/module/components/ThreadCard/NamePrefixIcon.js.map +1 -0
- package/lib/module/components/ThreadCard/ThreadCard.js +132 -0
- package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -0
- package/lib/module/components/ThreadCard/UnreadBadge.js +35 -0
- package/lib/module/components/ThreadCard/UnreadBadge.js.map +1 -0
- package/lib/module/components/ThreadCard/index.js +7 -0
- package/lib/module/components/ThreadCard/index.js.map +1 -0
- package/lib/module/components/ThreadCard/thread-card.utils.js +51 -0
- package/lib/module/components/ThreadCard/thread-card.utils.js.map +1 -0
- package/lib/module/core/index.js +11 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/core/useChatListener.js +62 -0
- package/lib/module/core/useChatListener.js.map +1 -0
- package/lib/module/core/useUserListener.js +72 -0
- package/lib/module/core/useUserListener.js.map +1 -0
- package/lib/module/hooks/query-keys.js +10 -0
- package/lib/module/hooks/query-keys.js.map +1 -0
- package/lib/module/hooks/useChatMessages.js +163 -0
- package/lib/module/hooks/useChatMessages.js.map +1 -0
- package/lib/module/hooks/useConversationList.js +51 -0
- package/lib/module/hooks/useConversationList.js.map +1 -0
- package/lib/module/index.js +14 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/screens/chat-detail/ChatAttachmentPanel.js +106 -0
- package/lib/module/screens/chat-detail/ChatAttachmentPanel.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatComposer.js +288 -0
- package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatDay.js +65 -0
- package/lib/module/screens/chat-detail/ChatDay.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatDetail.js +104 -0
- package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatDetailHeader.js +92 -0
- package/lib/module/screens/chat-detail/ChatDetailHeader.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatList.js +145 -0
- package/lib/module/screens/chat-detail/ChatList.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatLoadEarlier.js +23 -0
- package/lib/module/screens/chat-detail/ChatLoadEarlier.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatQuickActions.js +85 -0
- package/lib/module/screens/chat-detail/ChatQuickActions.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatScrollToBottom.js +12 -0
- package/lib/module/screens/chat-detail/ChatScrollToBottom.js.map +1 -0
- package/lib/module/screens/chat-detail/ChatTextBubble.js +62 -0
- package/lib/module/screens/chat-detail/ChatTextBubble.js.map +1 -0
- package/lib/module/screens/chat-detail/constants.js +59 -0
- package/lib/module/screens/chat-detail/constants.js.map +1 -0
- package/lib/module/screens/chat-detail/index.js +12 -0
- package/lib/module/screens/chat-detail/index.js.map +1 -0
- package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js +24 -0
- package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js.map +1 -0
- package/lib/module/screens/chat-detail/messages/types.js +4 -0
- package/lib/module/screens/chat-detail/messages/types.js.map +1 -0
- package/lib/module/screens/chat-detail/types.js +4 -0
- package/lib/module/screens/chat-detail/types.js.map +1 -0
- package/lib/module/screens/chat-detail/useChatActionPress.js +11 -0
- package/lib/module/screens/chat-detail/useChatActionPress.js.map +1 -0
- package/lib/module/screens/inbox/Inbox.js +134 -0
- package/lib/module/screens/inbox/Inbox.js.map +1 -0
- package/lib/module/screens/inbox/MessagesTab.js +58 -0
- package/lib/module/screens/inbox/MessagesTab.js.map +1 -0
- package/lib/module/screens/inbox/index.js +5 -0
- package/lib/module/screens/inbox/index.js.map +1 -0
- package/lib/module/services/apis.js +41 -0
- package/lib/module/services/apis.js.map +1 -0
- package/lib/module/services/index.js +5 -0
- package/lib/module/services/index.js.map +1 -0
- package/lib/module/services/message.js +38 -0
- package/lib/module/services/message.js.map +1 -0
- package/lib/module/store/conversation.js +89 -0
- package/lib/module/store/conversation.js.map +1 -0
- package/lib/module/store/index.js +6 -0
- package/lib/module/store/index.js.map +1 -0
- package/lib/module/store/storeConfig.js +19 -0
- package/lib/module/store/storeConfig.js.map +1 -0
- package/lib/module/store/user.js +25 -0
- package/lib/module/store/user.js.map +1 -0
- package/lib/module/translation/index.js +24 -0
- package/lib/module/translation/index.js.map +1 -0
- package/lib/module/translation/resources/i18n.js +10 -0
- package/lib/module/translation/resources/i18n.js.map +1 -0
- package/lib/module/types/auth.js +9 -0
- package/lib/module/types/auth.js.map +1 -0
- package/lib/module/types/chat.js +26 -0
- package/lib/module/types/chat.js.map +1 -0
- package/lib/module/types/message.js +16 -0
- package/lib/module/types/message.js.map +1 -0
- package/lib/module/utils/conversation.js +61 -0
- package/lib/module/utils/conversation.js.map +1 -0
- package/lib/module/utils/giftedChatMessage.js +90 -0
- package/lib/module/utils/giftedChatMessage.js.map +1 -0
- package/lib/module/utils/message.js +68 -0
- package/lib/module/utils/message.js.map +1 -0
- package/lib/module/utils/resolveMessageType.js +44 -0
- package/lib/module/utils/resolveMessageType.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/assets/images/index.d.ts +7 -0
- package/lib/typescript/src/assets/images/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/Avatar.d.ts +4 -0
- package/lib/typescript/src/components/Avatar/Avatar.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/Avatar.types.d.ts +18 -0
- package/lib/typescript/src/components/Avatar/Avatar.types.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/Avatar.utils.d.ts +14 -0
- package/lib/typescript/src/components/Avatar/Avatar.utils.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts +7 -0
- package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts +13 -0
- package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts +12 -0
- package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts.map +1 -0
- package/lib/typescript/src/components/Avatar/index.d.ts +6 -0
- package/lib/typescript/src/components/Avatar/index.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts +8 -0
- package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts +8 -0
- package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts +11 -0
- package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts +6 -0
- package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/index.d.ts +5 -0
- package/lib/typescript/src/components/ThreadCard/index.d.ts.map +1 -0
- package/lib/typescript/src/components/ThreadCard/thread-card.utils.d.ts +4 -0
- package/lib/typescript/src/components/ThreadCard/thread-card.utils.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +3 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/core/useChatListener.d.ts +2 -0
- package/lib/typescript/src/core/useChatListener.d.ts.map +1 -0
- package/lib/typescript/src/core/useUserListener.d.ts +2 -0
- package/lib/typescript/src/core/useUserListener.d.ts.map +1 -0
- package/lib/typescript/src/hooks/query-keys.d.ts +9 -0
- package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useChatMessages.d.ts +21 -0
- package/lib/typescript/src/hooks/useChatMessages.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useConversationList.d.ts +8 -0
- package/lib/typescript/src/hooks/useConversationList.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +14 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts +4 -0
- package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts +4 -0
- package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatList.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatList.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts +2 -0
- package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/constants.d.ts +17 -0
- package/lib/typescript/src/screens/chat-detail/constants.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/index.d.ts +13 -0
- package/lib/typescript/src/screens/chat-detail/index.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/messages/types.d.ts +13 -0
- package/lib/typescript/src/screens/chat-detail/messages/types.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/types.d.ts +86 -0
- package/lib/typescript/src/screens/chat-detail/types.d.ts.map +1 -0
- package/lib/typescript/src/screens/chat-detail/useChatActionPress.d.ts +3 -0
- package/lib/typescript/src/screens/chat-detail/useChatActionPress.d.ts.map +1 -0
- package/lib/typescript/src/screens/inbox/Inbox.d.ts +10 -0
- package/lib/typescript/src/screens/inbox/Inbox.d.ts.map +1 -0
- package/lib/typescript/src/screens/inbox/MessagesTab.d.ts +7 -0
- package/lib/typescript/src/screens/inbox/MessagesTab.d.ts.map +1 -0
- package/lib/typescript/src/screens/inbox/index.d.ts +3 -0
- package/lib/typescript/src/screens/inbox/index.d.ts.map +1 -0
- package/lib/typescript/src/services/apis.d.ts +12 -0
- package/lib/typescript/src/services/apis.d.ts.map +1 -0
- package/lib/typescript/src/services/index.d.ts +3 -0
- package/lib/typescript/src/services/index.d.ts.map +1 -0
- package/lib/typescript/src/services/message.d.ts +21 -0
- package/lib/typescript/src/services/message.d.ts.map +1 -0
- package/lib/typescript/src/store/conversation.d.ts +24 -0
- package/lib/typescript/src/store/conversation.d.ts.map +1 -0
- package/lib/typescript/src/store/index.d.ts +4 -0
- package/lib/typescript/src/store/index.d.ts.map +1 -0
- package/lib/typescript/src/store/storeConfig.d.ts +4 -0
- package/lib/typescript/src/store/storeConfig.d.ts.map +1 -0
- package/lib/typescript/src/store/user.d.ts +12 -0
- package/lib/typescript/src/store/user.d.ts.map +1 -0
- package/lib/typescript/src/translation/index.d.ts +4 -0
- package/lib/typescript/src/translation/index.d.ts.map +1 -0
- package/lib/typescript/src/translation/resources/i18n.d.ts +5 -0
- package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -0
- package/lib/typescript/src/types/auth.d.ts +24 -0
- package/lib/typescript/src/types/auth.d.ts.map +1 -0
- package/lib/typescript/src/types/chat.d.ts +99 -0
- package/lib/typescript/src/types/chat.d.ts.map +1 -0
- package/lib/typescript/src/types/message.d.ts +15 -0
- package/lib/typescript/src/types/message.d.ts.map +1 -0
- package/lib/typescript/src/utils/conversation.d.ts +10 -0
- package/lib/typescript/src/utils/conversation.d.ts.map +1 -0
- package/lib/typescript/src/utils/giftedChatMessage.d.ts +10 -0
- package/lib/typescript/src/utils/giftedChatMessage.d.ts.map +1 -0
- package/lib/typescript/src/utils/message.d.ts +15 -0
- package/lib/typescript/src/utils/message.d.ts.map +1 -0
- package/lib/typescript/src/utils/resolveMessageType.d.ts +4 -0
- package/lib/typescript/src/utils/resolveMessageType.d.ts.map +1 -0
- package/package.json +209 -0
- package/src/assets/images/icon_bot.png +0 -0
- package/src/assets/images/index.ts +7 -0
- package/src/assets/images/tag_bot.png +0 -0
- package/src/assets/images/tag_mall.png +0 -0
- package/src/build-ignore.d.ts +24 -0
- package/src/components/Avatar/Avatar.tsx +105 -0
- package/src/components/Avatar/Avatar.types.ts +17 -0
- package/src/components/Avatar/Avatar.utils.ts +49 -0
- package/src/components/Avatar/AvatarBadge.tsx +29 -0
- package/src/components/Avatar/DoubleAvatar.tsx +89 -0
- package/src/components/Avatar/SingleAvatar.tsx +74 -0
- package/src/components/Avatar/index.ts +5 -0
- package/src/components/ThreadCard/AvatarSection.tsx +42 -0
- package/src/components/ThreadCard/NamePrefixIcon.tsx +45 -0
- package/src/components/ThreadCard/ThreadCard.tsx +145 -0
- package/src/components/ThreadCard/UnreadBadge.tsx +35 -0
- package/src/components/ThreadCard/index.ts +4 -0
- package/src/components/ThreadCard/thread-card.utils.ts +68 -0
- package/src/core/index.ts +10 -0
- package/src/core/useChatListener.ts +85 -0
- package/src/core/useUserListener.ts +86 -0
- package/src/hooks/query-keys.ts +11 -0
- package/src/hooks/useChatMessages.ts +243 -0
- package/src/hooks/useConversationList.ts +57 -0
- package/src/index.tsx +36 -0
- package/src/screens/chat-detail/ChatAttachmentPanel.tsx +142 -0
- package/src/screens/chat-detail/ChatComposer.tsx +412 -0
- package/src/screens/chat-detail/ChatDay.tsx +73 -0
- package/src/screens/chat-detail/ChatDetail.tsx +118 -0
- package/src/screens/chat-detail/ChatDetailHeader.tsx +114 -0
- package/src/screens/chat-detail/ChatList.tsx +187 -0
- package/src/screens/chat-detail/ChatLoadEarlier.tsx +20 -0
- package/src/screens/chat-detail/ChatQuickActions.tsx +108 -0
- package/src/screens/chat-detail/ChatScrollToBottom.tsx +8 -0
- package/src/screens/chat-detail/ChatTextBubble.tsx +73 -0
- package/src/screens/chat-detail/constants.ts +76 -0
- package/src/screens/chat-detail/index.ts +33 -0
- package/src/screens/chat-detail/messages/ChatMessageBubble.tsx +24 -0
- package/src/screens/chat-detail/messages/types.ts +14 -0
- package/src/screens/chat-detail/types.ts +97 -0
- package/src/screens/chat-detail/useChatActionPress.ts +17 -0
- package/src/screens/inbox/Inbox.tsx +164 -0
- package/src/screens/inbox/MessagesTab.tsx +62 -0
- package/src/screens/inbox/index.ts +2 -0
- package/src/services/apis.ts +60 -0
- package/src/services/index.ts +2 -0
- package/src/services/message.ts +61 -0
- package/src/store/conversation.ts +116 -0
- package/src/store/index.ts +3 -0
- package/src/store/storeConfig.ts +19 -0
- package/src/store/user.ts +26 -0
- package/src/translation/index.ts +30 -0
- package/src/translation/resources/i18n.ts +8 -0
- package/src/types/auth.ts +25 -0
- package/src/types/chat.ts +118 -0
- package/src/types/message.ts +17 -0
- package/src/utils/conversation.ts +106 -0
- package/src/utils/giftedChatMessage.ts +137 -0
- package/src/utils/message.ts +136 -0
- package/src/utils/resolveMessageType.ts +49 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Keyboard,
|
|
4
|
+
Platform,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
TextInput,
|
|
7
|
+
type NativeSyntheticEvent,
|
|
8
|
+
type TextInputContentSizeChangeEventData,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import Reanimated, {
|
|
11
|
+
runOnJS,
|
|
12
|
+
useAnimatedReaction,
|
|
13
|
+
useAnimatedStyle,
|
|
14
|
+
useSharedValue,
|
|
15
|
+
withTiming,
|
|
16
|
+
} from 'react-native-reanimated';
|
|
17
|
+
import {
|
|
18
|
+
useKeyboardState,
|
|
19
|
+
useReanimatedKeyboardAnimation,
|
|
20
|
+
} from 'react-native-keyboard-controller';
|
|
21
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
22
|
+
import { KContainer, KImage, KColors, KSpacingValue } from '@droppii/libs';
|
|
23
|
+
import { ChatQuickActions } from './ChatQuickActions';
|
|
24
|
+
import { ChatAttachmentPanel } from './ChatAttachmentPanel';
|
|
25
|
+
import { getAttachmentPanelHeight } from './constants';
|
|
26
|
+
import type { ChatComposerProps } from './types';
|
|
27
|
+
|
|
28
|
+
const ACCESSORY_ANIMATION_MS = 250;
|
|
29
|
+
const ACCESSORY_SETTLE_MS = 150;
|
|
30
|
+
const IS_IOS = Platform.OS === 'ios';
|
|
31
|
+
const INPUT_FONT_SIZE = 16;
|
|
32
|
+
const INPUT_LINE_HEIGHT = 22.4;
|
|
33
|
+
const INPUT_MAX_HEIGHT = INPUT_LINE_HEIGHT * 5;
|
|
34
|
+
|
|
35
|
+
export const ChatComposer = memo(
|
|
36
|
+
({
|
|
37
|
+
value,
|
|
38
|
+
placeholder = 'Nhập tin nhắn...',
|
|
39
|
+
onChangeText,
|
|
40
|
+
onSend,
|
|
41
|
+
onPressAttach,
|
|
42
|
+
onPressEmoji,
|
|
43
|
+
quickActions,
|
|
44
|
+
attachmentActions,
|
|
45
|
+
onQuickActionPress,
|
|
46
|
+
onAttachmentAction,
|
|
47
|
+
renderQuickAction,
|
|
48
|
+
renderAttachmentAction,
|
|
49
|
+
attachmentColumns,
|
|
50
|
+
}: ChatComposerProps) => {
|
|
51
|
+
const hasAttachmentActions = !!attachmentActions?.length;
|
|
52
|
+
const inputRef = useRef<TextInput>(null);
|
|
53
|
+
const isSwitchingToAttachmentRef = useRef(false);
|
|
54
|
+
const [isAttachmentOpen, setIsAttachmentOpen] = useState(false);
|
|
55
|
+
const [isInputFocused, setIsInputFocused] = useState(false);
|
|
56
|
+
const [isInputWrapped, setIsInputWrapped] = useState(false);
|
|
57
|
+
const insets = useSafeAreaInsets();
|
|
58
|
+
|
|
59
|
+
const isKeyboardVisible = useKeyboardState((state) => state.isVisible);
|
|
60
|
+
const keyboardHeight = useKeyboardState((state) => state.height);
|
|
61
|
+
const { progress: keyboardProgress } = useReanimatedKeyboardAnimation();
|
|
62
|
+
|
|
63
|
+
const panelHeight = useMemo(
|
|
64
|
+
() =>
|
|
65
|
+
hasAttachmentActions
|
|
66
|
+
? getAttachmentPanelHeight(
|
|
67
|
+
attachmentActions.length,
|
|
68
|
+
attachmentColumns
|
|
69
|
+
)
|
|
70
|
+
: 0,
|
|
71
|
+
[attachmentActions, attachmentColumns, hasAttachmentActions]
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const attachmentHeightSV = useSharedValue(0);
|
|
75
|
+
const panelHeightSV = useSharedValue(panelHeight);
|
|
76
|
+
const switchKeyboardHeightSV = useSharedValue(0);
|
|
77
|
+
const isKeyboardToAttachmentSwitchSV = useSharedValue(false);
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
panelHeightSV.value = panelHeight;
|
|
81
|
+
}, [panelHeight, panelHeightSV]);
|
|
82
|
+
|
|
83
|
+
const openAttachment = useCallback(() => {
|
|
84
|
+
attachmentHeightSV.value = withTiming(panelHeight, {
|
|
85
|
+
duration: ACCESSORY_ANIMATION_MS,
|
|
86
|
+
});
|
|
87
|
+
setIsAttachmentOpen(true);
|
|
88
|
+
}, [attachmentHeightSV, panelHeight]);
|
|
89
|
+
|
|
90
|
+
const closeAttachment = useCallback(() => {
|
|
91
|
+
attachmentHeightSV.value = withTiming(0, {
|
|
92
|
+
duration: ACCESSORY_ANIMATION_MS,
|
|
93
|
+
});
|
|
94
|
+
setIsAttachmentOpen(false);
|
|
95
|
+
}, [attachmentHeightSV]);
|
|
96
|
+
|
|
97
|
+
const finishKeyboardToAttachmentSwitch = useCallback(() => {
|
|
98
|
+
if (!isSwitchingToAttachmentRef.current) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
isSwitchingToAttachmentRef.current = false;
|
|
103
|
+
isKeyboardToAttachmentSwitchSV.value = false;
|
|
104
|
+
|
|
105
|
+
const targetHeight = panelHeightSV.value;
|
|
106
|
+
const startHeight = switchKeyboardHeightSV.value;
|
|
107
|
+
|
|
108
|
+
if (Math.abs(startHeight - targetHeight) < 1) {
|
|
109
|
+
attachmentHeightSV.value = targetHeight;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
attachmentHeightSV.value = withTiming(targetHeight, {
|
|
114
|
+
duration: ACCESSORY_SETTLE_MS,
|
|
115
|
+
});
|
|
116
|
+
}, [
|
|
117
|
+
attachmentHeightSV,
|
|
118
|
+
isKeyboardToAttachmentSwitchSV,
|
|
119
|
+
panelHeightSV,
|
|
120
|
+
switchKeyboardHeightSV,
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (!isKeyboardVisible && isSwitchingToAttachmentRef.current) {
|
|
125
|
+
finishKeyboardToAttachmentSwitch();
|
|
126
|
+
}
|
|
127
|
+
}, [finishKeyboardToAttachmentSwitch, isKeyboardVisible]);
|
|
128
|
+
|
|
129
|
+
useAnimatedReaction(
|
|
130
|
+
() => ({
|
|
131
|
+
switching: isKeyboardToAttachmentSwitchSV.value,
|
|
132
|
+
progress: keyboardProgress.value,
|
|
133
|
+
}),
|
|
134
|
+
(current, previous) => {
|
|
135
|
+
if (
|
|
136
|
+
current.switching &&
|
|
137
|
+
current.progress === 0 &&
|
|
138
|
+
(previous?.progress ?? 1) > 0
|
|
139
|
+
) {
|
|
140
|
+
runOnJS(finishKeyboardToAttachmentSwitch)();
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
[finishKeyboardToAttachmentSwitch]
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (isSwitchingToAttachmentRef.current) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (isKeyboardVisible && isAttachmentOpen) {
|
|
152
|
+
closeAttachment();
|
|
153
|
+
}
|
|
154
|
+
}, [closeAttachment, isAttachmentOpen, isKeyboardVisible]);
|
|
155
|
+
|
|
156
|
+
const accessorySlotStyle = useAnimatedStyle(() => {
|
|
157
|
+
if (isKeyboardToAttachmentSwitchSV.value) {
|
|
158
|
+
return {
|
|
159
|
+
height: switchKeyboardHeightSV.value * (1 - keyboardProgress.value),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
height: attachmentHeightSV.value,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const handleSend = useCallback(() => {
|
|
169
|
+
onSend?.();
|
|
170
|
+
}, [onSend]);
|
|
171
|
+
|
|
172
|
+
const handleToggleAttachment = useCallback(() => {
|
|
173
|
+
if (!hasAttachmentActions) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (isAttachmentOpen) {
|
|
178
|
+
closeAttachment();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
onPressAttach?.();
|
|
183
|
+
inputRef.current?.blur();
|
|
184
|
+
|
|
185
|
+
if (isKeyboardVisible && keyboardHeight > 0) {
|
|
186
|
+
isSwitchingToAttachmentRef.current = true;
|
|
187
|
+
switchKeyboardHeightSV.value = keyboardHeight;
|
|
188
|
+
isKeyboardToAttachmentSwitchSV.value = true;
|
|
189
|
+
setIsAttachmentOpen(true);
|
|
190
|
+
Keyboard.dismiss();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
openAttachment();
|
|
195
|
+
}, [
|
|
196
|
+
closeAttachment,
|
|
197
|
+
isAttachmentOpen,
|
|
198
|
+
isKeyboardVisible,
|
|
199
|
+
keyboardHeight,
|
|
200
|
+
isKeyboardToAttachmentSwitchSV,
|
|
201
|
+
onPressAttach,
|
|
202
|
+
hasAttachmentActions,
|
|
203
|
+
openAttachment,
|
|
204
|
+
switchKeyboardHeightSV,
|
|
205
|
+
]);
|
|
206
|
+
|
|
207
|
+
const handleInputFocus = useCallback(() => {
|
|
208
|
+
setIsInputFocused(true);
|
|
209
|
+
|
|
210
|
+
if (!isAttachmentOpen) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
closeAttachment();
|
|
215
|
+
}, [closeAttachment, isAttachmentOpen]);
|
|
216
|
+
|
|
217
|
+
const handleInputBlur = useCallback(() => {
|
|
218
|
+
setIsInputFocused(false);
|
|
219
|
+
}, []);
|
|
220
|
+
|
|
221
|
+
const handleInputContentSizeChange = useCallback(
|
|
222
|
+
(event: NativeSyntheticEvent<TextInputContentSizeChangeEventData>) => {
|
|
223
|
+
const { height } = event.nativeEvent.contentSize;
|
|
224
|
+
setIsInputWrapped(height > INPUT_LINE_HEIGHT + 4);
|
|
225
|
+
},
|
|
226
|
+
[]
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const isMultilineInput = useMemo(() => {
|
|
230
|
+
if (!value) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return value.includes('\n') || isInputWrapped;
|
|
235
|
+
}, [isInputWrapped, value]);
|
|
236
|
+
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
if (!value) {
|
|
239
|
+
setIsInputWrapped(false);
|
|
240
|
+
}
|
|
241
|
+
}, [value]);
|
|
242
|
+
|
|
243
|
+
const renderEmojiNode = useCallback(
|
|
244
|
+
() => (
|
|
245
|
+
<KContainer.Touchable
|
|
246
|
+
marginR="0.5rem"
|
|
247
|
+
onPress={onPressEmoji}
|
|
248
|
+
activeOpacity={0.7}
|
|
249
|
+
>
|
|
250
|
+
<KImage.VectorIcons
|
|
251
|
+
name="sticker-o"
|
|
252
|
+
size={22}
|
|
253
|
+
color={KColors.gray.normal}
|
|
254
|
+
/>
|
|
255
|
+
</KContainer.Touchable>
|
|
256
|
+
),
|
|
257
|
+
[onPressEmoji]
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const inputRowStyle = useMemo(
|
|
261
|
+
() => ({
|
|
262
|
+
paddingBottom:
|
|
263
|
+
isAttachmentOpen || isKeyboardVisible ? 8 : insets.bottom + 12,
|
|
264
|
+
}),
|
|
265
|
+
[insets.bottom, isAttachmentOpen, isKeyboardVisible]
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
<KContainer.View background={'rgba(131, 137, 157, 0.05)'}>
|
|
270
|
+
<ChatQuickActions
|
|
271
|
+
actions={quickActions}
|
|
272
|
+
onActionPress={onQuickActionPress}
|
|
273
|
+
renderAction={renderQuickAction}
|
|
274
|
+
/>
|
|
275
|
+
|
|
276
|
+
<KContainer.View
|
|
277
|
+
row
|
|
278
|
+
alignItems
|
|
279
|
+
paddingH="0.75rem"
|
|
280
|
+
paddingT="0.75rem"
|
|
281
|
+
paddingB="0.75rem"
|
|
282
|
+
style={inputRowStyle}
|
|
283
|
+
>
|
|
284
|
+
{hasAttachmentActions ? (
|
|
285
|
+
<KContainer.Touchable
|
|
286
|
+
onPress={handleToggleAttachment}
|
|
287
|
+
center
|
|
288
|
+
br="round"
|
|
289
|
+
>
|
|
290
|
+
<KImage.VectorIcons
|
|
291
|
+
name={isAttachmentOpen ? 'close-circle-o' : 'plus-circle-o'}
|
|
292
|
+
size={24}
|
|
293
|
+
color={
|
|
294
|
+
isAttachmentOpen
|
|
295
|
+
? KColors.palette.primary.w400
|
|
296
|
+
: KColors.palette.gray.w600
|
|
297
|
+
}
|
|
298
|
+
/>
|
|
299
|
+
</KContainer.Touchable>
|
|
300
|
+
) : null}
|
|
301
|
+
|
|
302
|
+
<KContainer.View
|
|
303
|
+
flex
|
|
304
|
+
marginL={hasAttachmentActions ? '0.75rem' : undefined}
|
|
305
|
+
style={styles.inputWrapper}
|
|
306
|
+
>
|
|
307
|
+
<KContainer.View
|
|
308
|
+
row
|
|
309
|
+
alignItems={isMultilineInput ? 'flex-end' : 'center'}
|
|
310
|
+
brW={1}
|
|
311
|
+
brC={
|
|
312
|
+
isInputFocused
|
|
313
|
+
? KColors.palette.primary.w400
|
|
314
|
+
: KColors.palette.gray.w100
|
|
315
|
+
}
|
|
316
|
+
background={KColors.white}
|
|
317
|
+
paddingL="0.75rem"
|
|
318
|
+
style={styles.inputContainer}
|
|
319
|
+
>
|
|
320
|
+
<KContainer.View marginR="0.75rem">
|
|
321
|
+
<KImage.VectorIcons
|
|
322
|
+
name="chat-suggest-o"
|
|
323
|
+
size={24}
|
|
324
|
+
color={KColors.gray.normal}
|
|
325
|
+
/>
|
|
326
|
+
</KContainer.View>
|
|
327
|
+
|
|
328
|
+
<TextInput
|
|
329
|
+
ref={inputRef}
|
|
330
|
+
placeholder={placeholder}
|
|
331
|
+
placeholderTextColor={KColors.palette.gray.w200}
|
|
332
|
+
value={value}
|
|
333
|
+
onChangeText={onChangeText}
|
|
334
|
+
onFocus={handleInputFocus}
|
|
335
|
+
onBlur={handleInputBlur}
|
|
336
|
+
onContentSizeChange={handleInputContentSizeChange}
|
|
337
|
+
multiline
|
|
338
|
+
blurOnSubmit={false}
|
|
339
|
+
scrollEnabled
|
|
340
|
+
allowFontScaling={false}
|
|
341
|
+
underlineColorAndroid={KColors.transparent}
|
|
342
|
+
selectionColor={KColors.selector}
|
|
343
|
+
textAlignVertical={isMultilineInput ? 'top' : 'center'}
|
|
344
|
+
style={[styles.textInput]}
|
|
345
|
+
/>
|
|
346
|
+
|
|
347
|
+
{renderEmojiNode()}
|
|
348
|
+
</KContainer.View>
|
|
349
|
+
</KContainer.View>
|
|
350
|
+
|
|
351
|
+
<KContainer.Touchable
|
|
352
|
+
onPress={handleSend}
|
|
353
|
+
width={40}
|
|
354
|
+
height={40}
|
|
355
|
+
center
|
|
356
|
+
br="round"
|
|
357
|
+
background={KColors.palette.primary.w400}
|
|
358
|
+
marginL="0.75rem"
|
|
359
|
+
>
|
|
360
|
+
<KImage.VectorIcons
|
|
361
|
+
name="send"
|
|
362
|
+
provider="MaterialCommunityIcons"
|
|
363
|
+
size={20}
|
|
364
|
+
color={KColors.white}
|
|
365
|
+
/>
|
|
366
|
+
</KContainer.Touchable>
|
|
367
|
+
</KContainer.View>
|
|
368
|
+
|
|
369
|
+
{hasAttachmentActions ? (
|
|
370
|
+
<Reanimated.View
|
|
371
|
+
style={[styles.accessorySlot, accessorySlotStyle]}
|
|
372
|
+
pointerEvents={isAttachmentOpen ? 'auto' : 'none'}
|
|
373
|
+
>
|
|
374
|
+
<ChatAttachmentPanel
|
|
375
|
+
actions={attachmentActions}
|
|
376
|
+
columns={attachmentColumns}
|
|
377
|
+
onActionPress={onAttachmentAction}
|
|
378
|
+
renderAction={renderAttachmentAction}
|
|
379
|
+
/>
|
|
380
|
+
</Reanimated.View>
|
|
381
|
+
) : null}
|
|
382
|
+
</KContainer.View>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
ChatComposer.displayName = 'ChatComposer';
|
|
388
|
+
|
|
389
|
+
const styles = StyleSheet.create({
|
|
390
|
+
accessorySlot: {
|
|
391
|
+
overflow: 'hidden',
|
|
392
|
+
backgroundColor: KColors.palette.gray.w25,
|
|
393
|
+
},
|
|
394
|
+
inputWrapper: {
|
|
395
|
+
overflow: 'hidden',
|
|
396
|
+
},
|
|
397
|
+
inputContainer: {
|
|
398
|
+
borderRadius: KSpacingValue['1.25rem'],
|
|
399
|
+
minHeight: 48,
|
|
400
|
+
paddingVertical: IS_IOS ? 4 : 0,
|
|
401
|
+
},
|
|
402
|
+
textInput: {
|
|
403
|
+
flex: 1,
|
|
404
|
+
maxHeight: INPUT_MAX_HEIGHT,
|
|
405
|
+
fontSize: INPUT_FONT_SIZE,
|
|
406
|
+
lineHeight: INPUT_LINE_HEIGHT,
|
|
407
|
+
color: KColors.palette.gray.w900,
|
|
408
|
+
paddingVertical: IS_IOS ? 0 : 4,
|
|
409
|
+
paddingHorizontal: IS_IOS ? 2 : 0,
|
|
410
|
+
marginVertical: IS_IOS ? 0 : -8,
|
|
411
|
+
},
|
|
412
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { memo, useMemo } from 'react';
|
|
2
|
+
import { KContainer, KLabel } from '@droppii/libs';
|
|
3
|
+
import type { DayProps } from 'react-native-gifted-chat';
|
|
4
|
+
import { CHAT_BUBBLE_COLORS } from './constants';
|
|
5
|
+
|
|
6
|
+
const formatTime = (date: Date) =>
|
|
7
|
+
date.toLocaleTimeString('vi-VN', {
|
|
8
|
+
hour: '2-digit',
|
|
9
|
+
minute: '2-digit',
|
|
10
|
+
hour12: false,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const formatDayLabel = (createdAt: Date | number): string | null => {
|
|
14
|
+
const date = new Date(createdAt);
|
|
15
|
+
if (Number.isNaN(date.getTime())) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const today = new Date();
|
|
20
|
+
today.setHours(0, 0, 0, 0);
|
|
21
|
+
|
|
22
|
+
const messageDay = new Date(date);
|
|
23
|
+
messageDay.setHours(0, 0, 0, 0);
|
|
24
|
+
|
|
25
|
+
if (messageDay.getTime() === today.getTime()) {
|
|
26
|
+
return `${formatTime(date)} Hôm nay`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const yesterday = new Date(today);
|
|
30
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
31
|
+
|
|
32
|
+
if (messageDay.getTime() === yesterday.getTime()) {
|
|
33
|
+
return `${formatTime(date)} Hôm qua`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (messageDay.getFullYear() === today.getFullYear()) {
|
|
37
|
+
return `${formatTime(date)} ${date.toLocaleDateString('vi-VN', {
|
|
38
|
+
day: 'numeric',
|
|
39
|
+
month: 'long',
|
|
40
|
+
})}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return `${formatTime(date)} ${date.toLocaleDateString('vi-VN', {
|
|
44
|
+
day: 'numeric',
|
|
45
|
+
month: 'long',
|
|
46
|
+
year: 'numeric',
|
|
47
|
+
})}`;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const ChatDay = memo(
|
|
51
|
+
({ createdAt, containerStyle, wrapperStyle }: DayProps) => {
|
|
52
|
+
const dateStr = useMemo(
|
|
53
|
+
() => (createdAt == null ? null : formatDayLabel(createdAt)),
|
|
54
|
+
[createdAt]
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (!dateStr) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<KContainer.View center marginV="0.5rem" style={containerStyle}>
|
|
63
|
+
<KContainer.View style={wrapperStyle}>
|
|
64
|
+
<KLabel.Text typo="TextXsNormal" color={CHAT_BUBBLE_COLORS.dayLabel}>
|
|
65
|
+
{dateStr}
|
|
66
|
+
</KLabel.Text>
|
|
67
|
+
</KContainer.View>
|
|
68
|
+
</KContainer.View>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
ChatDay.displayName = 'ChatDay';
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { memo, useState, useCallback } from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import { KeyboardAvoidingView } from 'react-native-keyboard-controller';
|
|
4
|
+
import { KContainer } from '@droppii/libs';
|
|
5
|
+
import ChatDetailHeader from './ChatDetailHeader';
|
|
6
|
+
import { ChatList } from './ChatList';
|
|
7
|
+
import { ChatComposer } from './ChatComposer';
|
|
8
|
+
import type { ChatDetailProps } from './types';
|
|
9
|
+
|
|
10
|
+
const ChatDetail = memo(
|
|
11
|
+
({
|
|
12
|
+
title,
|
|
13
|
+
subtitle,
|
|
14
|
+
avatarUri,
|
|
15
|
+
avatarFullName,
|
|
16
|
+
chatType,
|
|
17
|
+
showAddMember,
|
|
18
|
+
onBack,
|
|
19
|
+
onPressSearch,
|
|
20
|
+
onPressAddMember,
|
|
21
|
+
onPressMenu,
|
|
22
|
+
onPressAvatar,
|
|
23
|
+
messages = [],
|
|
24
|
+
currentUserId,
|
|
25
|
+
renderChat,
|
|
26
|
+
onLoadEarlier,
|
|
27
|
+
isLoading,
|
|
28
|
+
isLoadingEarlier,
|
|
29
|
+
hasMoreEarlier,
|
|
30
|
+
quickActions,
|
|
31
|
+
inputValue,
|
|
32
|
+
inputPlaceholder,
|
|
33
|
+
onChangeInput,
|
|
34
|
+
onSend,
|
|
35
|
+
onPressAttach,
|
|
36
|
+
onPressEmoji,
|
|
37
|
+
attachmentActions,
|
|
38
|
+
onQuickActionPress,
|
|
39
|
+
onAttachmentAction,
|
|
40
|
+
renderQuickAction,
|
|
41
|
+
renderAttachmentAction,
|
|
42
|
+
attachmentColumns,
|
|
43
|
+
}: ChatDetailProps) => {
|
|
44
|
+
const [internalInput, setInternalInput] = useState('');
|
|
45
|
+
|
|
46
|
+
const handleChangeInput = useCallback(
|
|
47
|
+
(text: string) => {
|
|
48
|
+
if (onChangeInput) {
|
|
49
|
+
onChangeInput(text);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
setInternalInput(text);
|
|
53
|
+
},
|
|
54
|
+
[onChangeInput]
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const currentInput = inputValue ?? internalInput;
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<KContainer.Page flex edges={['bottom']}>
|
|
61
|
+
<ChatDetailHeader
|
|
62
|
+
title={title}
|
|
63
|
+
subtitle={subtitle}
|
|
64
|
+
avatarUri={avatarUri}
|
|
65
|
+
avatarFullName={avatarFullName}
|
|
66
|
+
chatType={chatType}
|
|
67
|
+
showAddMember={showAddMember}
|
|
68
|
+
onBack={onBack}
|
|
69
|
+
onPressSearch={onPressSearch}
|
|
70
|
+
onPressAddMember={onPressAddMember}
|
|
71
|
+
onPressMenu={onPressMenu}
|
|
72
|
+
onPressAvatar={onPressAvatar}
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
<KeyboardAvoidingView
|
|
76
|
+
style={styles.keyboardAvoiding}
|
|
77
|
+
behavior="padding"
|
|
78
|
+
>
|
|
79
|
+
<ChatList
|
|
80
|
+
messages={messages}
|
|
81
|
+
currentUserId={currentUserId}
|
|
82
|
+
renderChat={renderChat}
|
|
83
|
+
onLoadEarlier={onLoadEarlier}
|
|
84
|
+
isLoading={isLoading}
|
|
85
|
+
isLoadingEarlier={isLoadingEarlier}
|
|
86
|
+
hasMoreEarlier={hasMoreEarlier}
|
|
87
|
+
/>
|
|
88
|
+
|
|
89
|
+
<ChatComposer
|
|
90
|
+
value={currentInput}
|
|
91
|
+
placeholder={inputPlaceholder}
|
|
92
|
+
onChangeText={handleChangeInput}
|
|
93
|
+
onSend={onSend}
|
|
94
|
+
onPressAttach={onPressAttach}
|
|
95
|
+
onPressEmoji={onPressEmoji}
|
|
96
|
+
quickActions={quickActions}
|
|
97
|
+
attachmentActions={attachmentActions}
|
|
98
|
+
onQuickActionPress={onQuickActionPress}
|
|
99
|
+
onAttachmentAction={onAttachmentAction}
|
|
100
|
+
renderQuickAction={renderQuickAction}
|
|
101
|
+
renderAttachmentAction={renderAttachmentAction}
|
|
102
|
+
attachmentColumns={attachmentColumns}
|
|
103
|
+
/>
|
|
104
|
+
</KeyboardAvoidingView>
|
|
105
|
+
</KContainer.Page>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
ChatDetail.displayName = 'ChatDetail';
|
|
111
|
+
|
|
112
|
+
const styles = StyleSheet.create({
|
|
113
|
+
keyboardAvoiding: {
|
|
114
|
+
flex: 1,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export default ChatDetail;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { memo, useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
KNavigation,
|
|
4
|
+
KContainer,
|
|
5
|
+
KImage,
|
|
6
|
+
KLabel,
|
|
7
|
+
KColors,
|
|
8
|
+
} from '@droppii/libs';
|
|
9
|
+
import { Avatar } from '../../components/Avatar';
|
|
10
|
+
import type { ChatDetailHeaderProps } from './types';
|
|
11
|
+
|
|
12
|
+
const ChatDetailHeader = memo(
|
|
13
|
+
({
|
|
14
|
+
title,
|
|
15
|
+
subtitle,
|
|
16
|
+
avatarUri,
|
|
17
|
+
avatarFullName,
|
|
18
|
+
showAddMember = false,
|
|
19
|
+
onBack,
|
|
20
|
+
onPressSearch,
|
|
21
|
+
onPressAddMember,
|
|
22
|
+
onPressMenu,
|
|
23
|
+
onPressAvatar,
|
|
24
|
+
}: ChatDetailHeaderProps) => {
|
|
25
|
+
const rightButtons = useMemo(() => {
|
|
26
|
+
const buttons = [
|
|
27
|
+
{
|
|
28
|
+
id: 'search',
|
|
29
|
+
index: 2,
|
|
30
|
+
icon: {
|
|
31
|
+
vectorName: 'search-o',
|
|
32
|
+
},
|
|
33
|
+
onPress: onPressSearch,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'menu',
|
|
37
|
+
index: 0,
|
|
38
|
+
icon: {
|
|
39
|
+
vectorName: 'align-justify-o',
|
|
40
|
+
},
|
|
41
|
+
onPress: onPressMenu,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
if (showAddMember) {
|
|
46
|
+
buttons.splice(1, 0, {
|
|
47
|
+
id: 'add-member',
|
|
48
|
+
index: 1,
|
|
49
|
+
icon: {
|
|
50
|
+
vectorName: 'user-add-o',
|
|
51
|
+
},
|
|
52
|
+
onPress: onPressAddMember,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return buttons;
|
|
57
|
+
}, [onPressSearch, onPressAddMember, onPressMenu, showAddMember]);
|
|
58
|
+
|
|
59
|
+
const leftNode = useMemo(
|
|
60
|
+
() => (
|
|
61
|
+
<KContainer.View row alignItems marginR="0.25rem">
|
|
62
|
+
<KContainer.Touchable onPress={onBack} height={40} width={40} center>
|
|
63
|
+
<KImage.VectorIcons
|
|
64
|
+
name="arrow-left-o"
|
|
65
|
+
size={24}
|
|
66
|
+
color={KColors.primary.normal}
|
|
67
|
+
/>
|
|
68
|
+
</KContainer.Touchable>
|
|
69
|
+
|
|
70
|
+
<Avatar
|
|
71
|
+
source={avatarUri}
|
|
72
|
+
fullName={avatarFullName ?? title}
|
|
73
|
+
size="md"
|
|
74
|
+
onPress={onPressAvatar}
|
|
75
|
+
/>
|
|
76
|
+
</KContainer.View>
|
|
77
|
+
),
|
|
78
|
+
[avatarFullName, avatarUri, onBack, onPressAvatar, title]
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const subTitleNode = useMemo(() => {
|
|
82
|
+
if (!subtitle) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<KLabel.Text
|
|
88
|
+
typo="TextSmNormal"
|
|
89
|
+
color={KColors.palette.gray.w500}
|
|
90
|
+
numberOfLines={1}
|
|
91
|
+
>
|
|
92
|
+
{subtitle}
|
|
93
|
+
</KLabel.Text>
|
|
94
|
+
);
|
|
95
|
+
}, [subtitle]);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<KNavigation.Header
|
|
99
|
+
theme="light"
|
|
100
|
+
alignment="left"
|
|
101
|
+
size="small"
|
|
102
|
+
leftNode={leftNode}
|
|
103
|
+
title={title}
|
|
104
|
+
subTitle={subTitleNode}
|
|
105
|
+
initRightButtons={rightButtons}
|
|
106
|
+
shadow
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
ChatDetailHeader.displayName = 'ChatDetailHeader';
|
|
113
|
+
|
|
114
|
+
export default ChatDetailHeader;
|