@ethora/chat-component-rn 26.4.1
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 +661 -0
- package/README.md +148 -0
- package/empty-shim.js +15 -0
- package/index.js +13 -0
- package/metro.js +72 -0
- package/package.json +99 -0
- package/src/api.config.ts +34 -0
- package/src/assets/BG.png +0 -0
- package/src/assets/BG.tsx +56 -0
- package/src/assets/File.svg +4 -0
- package/src/assets/ForzaCare.png +0 -0
- package/src/assets/ForzaCare.tsx +27 -0
- package/src/assets/icons.tsx +685 -0
- package/src/assets/images.tsx +41 -0
- package/src/assets/test.xml +243 -0
- package/src/components/AuthForms/Login.tsx +295 -0
- package/src/components/AuthForms/LoginAnonym.tsx +68 -0
- package/src/components/AuthForms/Register.tsx +8 -0
- package/src/components/ContextMenu/ContextMenuComponents.tsx +87 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +244 -0
- package/src/components/ExampleComponents/CustomMessage.tsx +92 -0
- package/src/components/ExampleComponents/CustomTypingIndicatorExamples.tsx +239 -0
- package/src/components/Header/HeaderRoomList.tsx +104 -0
- package/src/components/InputComponents/AudioInput.tsx +24 -0
- package/src/components/InputComponents/AudioRecorder.tsx +100 -0
- package/src/components/InputComponents/MediaInput.tsx +114 -0
- package/src/components/InputComponents/RecordingIndicator.tsx +77 -0
- package/src/components/InputComponents/Search.tsx +135 -0
- package/src/components/InputComponents/TextInput.tsx +66 -0
- package/src/components/MainComponents/ChatHeader.tsx +163 -0
- package/src/components/MainComponents/ChatRoom.tsx +392 -0
- package/src/components/MainComponents/ChatWrapper.tsx +318 -0
- package/src/components/MainComponents/ChooseChatMessage.tsx +44 -0
- package/src/components/MainComponents/ConnectionBanner.tsx +33 -0
- package/src/components/MainComponents/EditWrapper.tsx +72 -0
- package/src/components/MainComponents/LoginWrapper.tsx +134 -0
- package/src/components/MainComponents/MediaMessage.tsx +55 -0
- package/src/components/MainComponents/MessageContainer.tsx +122 -0
- package/src/components/MainComponents/MessageList.tsx +429 -0
- package/src/components/MainComponents/NoMessagesPlaceholder.tsx +49 -0
- package/src/components/MainComponents/ProfileImagePlaceholder.tsx +143 -0
- package/src/components/MainComponents/RNStyled.tsx +34 -0
- package/src/components/MainComponents/ReduxWrapper.tsx +40 -0
- package/src/components/MainComponents/RoomList.tsx +246 -0
- package/src/components/MainComponents/Select.tsx +165 -0
- package/src/components/MainComponents/Switch.tsx +73 -0
- package/src/components/MainComponents/SystemMessage.tsx +42 -0
- package/src/components/Menu/HeaderRoomListMenu.tsx +169 -0
- package/src/components/MenuRoom/MenuRoom.tsx +46 -0
- package/src/components/MessageBubble/Avatar.tsx +84 -0
- package/src/components/MessageBubble/BottomReplyContainer.tsx +117 -0
- package/src/components/MessageBubble/CustomDivider.tsx +10 -0
- package/src/components/MessageBubble/DeletedMessage.tsx +36 -0
- package/src/components/MessageBubble/Message.tsx +400 -0
- package/src/components/MessageBubble/MessageInteractions.tsx +247 -0
- package/src/components/MessageBubble/MessageReaction.tsx +149 -0
- package/src/components/MessageBubble/MessageReply.tsx +50 -0
- package/src/components/MessageBubble/MessageTranslations.tsx +30 -0
- package/src/components/Modals/AddMembersModal/AddMembersModal.tsx +142 -0
- package/src/components/Modals/ChatProfileModal/ChatProfileModal.tsx +471 -0
- package/src/components/Modals/ChatProfileModal/DeleteChatModal.tsx +91 -0
- package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +298 -0
- package/src/components/Modals/Modal/Modal.tsx +52 -0
- package/src/components/Modals/ModalHeaderComponent.tsx +41 -0
- package/src/components/Modals/ModalSelectMedia/ModalSelectMedia.tsx +285 -0
- package/src/components/Modals/ModalWrapper/ModalWrapper.tsx +103 -0
- package/src/components/Modals/NewChatModal/ModalContent.tsx +151 -0
- package/src/components/Modals/NewChatModal/NewChatModal.tsx +391 -0
- package/src/components/Modals/NewChatModal/UpdNewChatModal.tsx +136 -0
- package/src/components/Modals/SelectUsersModal/SelectUsersModal.tsx +134 -0
- package/src/components/Modals/SettingsModals/BlockedUsers/BlockedUsersModal.tsx +63 -0
- package/src/components/Modals/SettingsModals/DocumentShares/DocumentSharesModal.tsx +115 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.tsx +121 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/StyledComponents.ts +0 -0
- package/src/components/Modals/SettingsModals/ProfileShares/ProfileShares.tsx +65 -0
- package/src/components/Modals/SettingsModals/Referrals/Referrals.tsx +90 -0
- package/src/components/Modals/SettingsModals/SharedStyledComponents.ts +74 -0
- package/src/components/Modals/SettingsModals/Visibility/RadioInput.tsx +59 -0
- package/src/components/Modals/SettingsModals/Visibility/StyledComponents.ts +32 -0
- package/src/components/Modals/SettingsModals/Visibility/VisibilityModal.tsx +146 -0
- package/src/components/Modals/UserProfileModal/EditUserModal.tsx +163 -0
- package/src/components/Modals/UserProfileModal/UserProfileModal.tsx +410 -0
- package/src/components/Modals/UserSettingsModal/UserSettingsModal.tsx +85 -0
- package/src/components/Modals/styledModalComponents.tsx +181 -0
- package/src/components/OperationalModal/OperationalModal.tsx +78 -0
- package/src/components/RoomComponents/ChatRoomItem.tsx +219 -0
- package/src/components/RoomComponents/LastMessageItem.tsx +47 -0
- package/src/components/RoomComponents/styled/LastAudioMessage.tsx +62 -0
- package/src/components/RoomComponents/styled/LastMessageEmoji.tsx +26 -0
- package/src/components/RoomComponents/styled/LastMessageFile.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessageVideo.tsx +70 -0
- package/src/components/RoomComponents/styled/LastTextMessage.tsx +65 -0
- package/src/components/RoomComponents/styled/StyledRoomComponents.ts +53 -0
- package/src/components/SortDropDown/index.tsx +76 -0
- package/src/components/Thread/ThreadHeader.tsx +41 -0
- package/src/components/Thread/ThreadWrapper.tsx +270 -0
- package/src/components/Toast/Toast.tsx +128 -0
- package/src/components/Toast/index.ts +13 -0
- package/src/components/UsersList/StyledComponents.ts +30 -0
- package/src/components/UsersList/UsersList.tsx +112 -0
- package/src/components/styled/ActionButton.tsx +40 -0
- package/src/components/styled/AudioMessage.tsx +82 -0
- package/src/components/styled/Button.tsx +107 -0
- package/src/components/styled/ChatWrapperBox.tsx +9 -0
- package/src/components/styled/DateLabel.tsx +77 -0
- package/src/components/styled/Loader.tsx +65 -0
- package/src/components/styled/MediaFilePreview.tsx +42 -0
- package/src/components/styled/MediaModal.tsx +54 -0
- package/src/components/styled/MessageImage.tsx +54 -0
- package/src/components/styled/NewMessageLabel.tsx +50 -0
- package/src/components/styled/RoomListComponents/index.tsx +164 -0
- package/src/components/styled/SendInput.tsx +297 -0
- package/src/components/styled/StyledComponents.ts +320 -0
- package/src/components/styled/StyledInput.tsx +101 -0
- package/src/components/styled/StyledInputComponents/AudioComponents.tsx +1 -0
- package/src/components/styled/StyledInputComponents/Composing.tsx +97 -0
- package/src/components/styled/StyledInputComponents/CustomTypingIndicator.tsx +261 -0
- package/src/components/styled/StyledInputComponents/MediaComponents.tsx +90 -0
- package/src/components/styled/StyledInputComponents/StyledInputComponents.tsx +131 -0
- package/src/components/styled/StyledInputComponents/VideoComponents.tsx +49 -0
- package/src/components/styled/TreadLabel.tsx +50 -0
- package/src/components/styled/UnsupportedType.tsx +95 -0
- package/src/components/styled/VideoMessage.tsx +68 -0
- package/src/context/MessageNotificationContext.tsx +335 -0
- package/src/context/PushNotificationProvider.tsx +78 -0
- package/src/context/ToastContext.tsx +63 -0
- package/src/context/toastProvider.tsx +0 -0
- package/src/context/xmppProvider.tsx +364 -0
- package/src/helpers/block_scroll.ts +95 -0
- package/src/helpers/chatAutoEnterer.ts +46 -0
- package/src/helpers/checkUniqueUsers.tsx +31 -0
- package/src/helpers/constants/CHAT_TYPES.ts +6 -0
- package/src/helpers/constants/LANGUAGE_OPTIONS.ts +14 -0
- package/src/helpers/constants/LOCAL_STORAGE.ts +3 -0
- package/src/helpers/constants/MESSAGE_INTERACTIONS.ts +29 -0
- package/src/helpers/constants/MODAL_TYPES.ts +57 -0
- package/src/helpers/constants/PLATFORM_CONSTANTS.ts +3 -0
- package/src/helpers/createMainMessageForThread.ts +23 -0
- package/src/helpers/createMessageFromXml.ts +118 -0
- package/src/helpers/createRoomFromApi.tsx +27 -0
- package/src/helpers/createUserNameFromSetUser.ts +15 -0
- package/src/helpers/dateComparison.ts +12 -0
- package/src/helpers/debounce.ts +10 -0
- package/src/helpers/ensureScopedChatCache.ts +61 -0
- package/src/helpers/extractUniqueMembersFromRooms.ts +45 -0
- package/src/helpers/formatNumberWithCommas.ts +3 -0
- package/src/helpers/getBooleanFromString.ts +7 -0
- package/src/helpers/getDataFromXml.ts +80 -0
- package/src/helpers/getNumberFromString.ts +5 -0
- package/src/helpers/getRoomsWithRetry.ts +45 -0
- package/src/helpers/getTintedColor.ts +28 -0
- package/src/helpers/getUnnamedUsers.ts +39 -0
- package/src/helpers/handleCopyClick.ts +3 -0
- package/src/helpers/handleXmppError.ts +14 -0
- package/src/helpers/hashcolor.ts +34 -0
- package/src/helpers/historyPreloadScheduler.ts +264 -0
- package/src/helpers/initRoomsPresence.ts +32 -0
- package/src/helpers/initXmppRooms.tsx +71 -0
- package/src/helpers/insertMessageWithDelimiter.ts +96 -0
- package/src/helpers/isChatIdPresentInArray.ts +54 -0
- package/src/helpers/localStorageUser.ts +9 -0
- package/src/helpers/markdownParser.tsx +295 -0
- package/src/helpers/nanoToMs.ts +3 -0
- package/src/helpers/parseMessageBody.tsx +516 -0
- package/src/helpers/parseUrls.tsx +42 -0
- package/src/helpers/resolveInitBeforeLoadUser.ts +240 -0
- package/src/helpers/storeConsole.ts +26 -0
- package/src/helpers/transformTranslatations.ts +16 -0
- package/src/helpers/updateMessagesTillLast.tsx +104 -0
- package/src/helpers/updatedChatLastTimestamps.ts +29 -0
- package/src/helpers/validator.ts +20 -0
- package/src/helpers/walletUsername.ts +12 -0
- package/src/hooks/hooks.ts +6 -0
- package/src/hooks/useChatSettingState.tsx +38 -0
- package/src/hooks/useChatWrapperInit.ts +266 -0
- package/src/hooks/useComposing.tsx +59 -0
- package/src/hooks/useCustomTypingIndicator.tsx +193 -0
- package/src/hooks/useEventHandlers.tsx +81 -0
- package/src/hooks/useGetNewArchRoom.tsx +57 -0
- package/src/hooks/useHeapSender.tsx +88 -0
- package/src/hooks/useLocalStorage.tsx +53 -0
- package/src/hooks/useLogout.tsx +31 -0
- package/src/hooks/useMessageHeapState.tsx +11 -0
- package/src/hooks/useMessageLoaderQueue.tsx +90 -0
- package/src/hooks/useMessageQueue.ts +146 -0
- package/src/hooks/usePendingNotification.ts +49 -0
- package/src/hooks/usePrevious.tsx +15 -0
- package/src/hooks/usePushNotifications.ts +106 -0
- package/src/hooks/useQRCodeChatHandler.ts +58 -0
- package/src/hooks/useRoomInitialization.tsx +160 -0
- package/src/hooks/useRoomState.tsx +47 -0
- package/src/hooks/useRoomUrl.tsx +41 -0
- package/src/hooks/useSendMessage.tsx +306 -0
- package/src/hooks/useUnreadMessagesCounter.ts +55 -0
- package/src/hooks/useXmppInitialization.ts +148 -0
- package/src/main.ts +45 -0
- package/src/networking/api-requests/auth.api.ts +140 -0
- package/src/networking/api-requests/push.api.ts +55 -0
- package/src/networking/api-requests/roomMembers.api.ts +20 -0
- package/src/networking/api-requests/rooms.api.ts +142 -0
- package/src/networking/api-requests/user.api.ts +65 -0
- package/src/networking/apiClient.ts +149 -0
- package/src/networking/helpers/refreshChecker.ts +13 -0
- package/src/networking/stanzaHandlers.ts +418 -0
- package/src/networking/xmpp/actionSetTimestampToPrivateStore.xmpp.ts +37 -0
- package/src/networking/xmpp/allRoomPresences.xmpp.ts +10 -0
- package/src/networking/xmpp/createPrivateRoom.xmpp.ts +26 -0
- package/src/networking/xmpp/createRoom.xmpp.ts +35 -0
- package/src/networking/xmpp/createRoomPresence.xmpp.ts +74 -0
- package/src/networking/xmpp/createTimeoutPromise.xmpp.ts +15 -0
- package/src/networking/xmpp/deleteMessage.xmpp.ts +19 -0
- package/src/networking/xmpp/editMessage.xmpp.ts +46 -0
- package/src/networking/xmpp/getChatsPrivateStoreRequest.xmpp.ts +57 -0
- package/src/networking/xmpp/getHistory.xmpp.ts +140 -0
- package/src/networking/xmpp/getLastMessageArchive.xmpp.ts +24 -0
- package/src/networking/xmpp/getRoomInfo.xmpp.ts +15 -0
- package/src/networking/xmpp/getRoomMembers.xmpp.ts +13 -0
- package/src/networking/xmpp/getRooms.xmpp.ts +43 -0
- package/src/networking/xmpp/getRoomsPaged.xmpp.ts +59 -0
- package/src/networking/xmpp/handlePong.xmpp.ts +7 -0
- package/src/networking/xmpp/handleStanzas.xmpp.ts +55 -0
- package/src/networking/xmpp/inviteRoomRequest.xmpp.ts +25 -0
- package/src/networking/xmpp/leaveTheRoom.xmpp.ts +15 -0
- package/src/networking/xmpp/listenerManager.ts +116 -0
- package/src/networking/xmpp/presenceInRoom.xmpp.ts +57 -0
- package/src/networking/xmpp/roomConfig.xmpp.ts +71 -0
- package/src/networking/xmpp/sendMediaMessage.xmpp.ts +97 -0
- package/src/networking/xmpp/sendMessageReaction.xmpp.ts +41 -0
- package/src/networking/xmpp/sendPing.xmpp.ts +21 -0
- package/src/networking/xmpp/sendTextMessage.xmpp.ts +99 -0
- package/src/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.ts +44 -0
- package/src/networking/xmpp/sendTypingRequest.xmpp.ts +26 -0
- package/src/networking/xmpp/setChatsPrivateStoreRequest.xmpp.ts +48 -0
- package/src/networking/xmpp/setMeAsOwner.xmpp.ts +52 -0
- package/src/networking/xmpp/setRoomImage.xmpp.ts +26 -0
- package/src/networking/xmpp/setVCard.xmpp.ts +19 -0
- package/src/networking/xmpp/subscribeToRoomMessages.xmpp.ts +75 -0
- package/src/networking/xmppClient.ts +603 -0
- package/src/roomStore/Middleware/logoutMiddleware.tsx +24 -0
- package/src/roomStore/Middleware/newMessageMidlleware.tsx +87 -0
- package/src/roomStore/Middleware/reactionsMiddleware.tsx +77 -0
- package/src/roomStore/Middleware/testMiddleware.tsx +20 -0
- package/src/roomStore/Middleware/unreadMidlleware.tsx +58 -0
- package/src/roomStore/chatSettingsSlice.ts +178 -0
- package/src/roomStore/index.ts +68 -0
- package/src/roomStore/persistence.ts +152 -0
- package/src/roomStore/roomHeapSlice.ts +37 -0
- package/src/roomStore/roomsSlice.ts +353 -0
- package/src/services/pushNotifications.ts +170 -0
- package/src/services/pushSubscriptionService.ts +145 -0
- package/src/types/messages.ts +61 -0
- package/src/types/models/action.model.ts +30 -0
- package/src/types/models/config.model.ts +16 -0
- package/src/types/models/customComponents.model.ts +53 -0
- package/src/types/models/language.model.ts +11 -0
- package/src/types/models/media.model.ts +5 -0
- package/src/types/models/message.model.ts +69 -0
- package/src/types/models/modal.model.ts +9 -0
- package/src/types/models/room.model.ts +120 -0
- package/src/types/models/user.model.ts +90 -0
- package/src/types/models/xmpp.model.ts +155 -0
- package/src/types/types.ts +505 -0
- package/src/utils/PriorityQueue.ts +47 -0
- package/src/utils/actionHelpers.ts +40 -0
- package/src/utils/actionLogger.ts +64 -0
- package/src/utils/clientRegistry.ts +80 -0
- package/src/utils/devLogger.ts +197 -0
- package/src/utils/messageNotificationManager.ts +108 -0
- package/src/utils/resendMessage.ts +87 -0
- package/src/utils/toastEmitter.ts +27 -0
- package/src/utils/xmppMemoryMonitor.ts +63 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import styled from 'styled-components/native';
|
|
3
|
+
import { TouchableOpacity, Image, Text } from 'react-native';
|
|
4
|
+
import { EditIcon } from '../../assets/icons';
|
|
5
|
+
import {
|
|
6
|
+
AvatarCircle,
|
|
7
|
+
AvatarImage,
|
|
8
|
+
InitialsText,
|
|
9
|
+
Overlay,
|
|
10
|
+
RemoveButton,
|
|
11
|
+
RemoveButtonText,
|
|
12
|
+
Wrapper,
|
|
13
|
+
} from '../styled/StyledComponents';
|
|
14
|
+
import { nameToColor } from '../../helpers/hashcolor';
|
|
15
|
+
|
|
16
|
+
interface ProfileImagePlaceholderProps {
|
|
17
|
+
name?: string;
|
|
18
|
+
icon?: string | { uri: string } | string | File | null;
|
|
19
|
+
click?: {
|
|
20
|
+
onPress: () => void;
|
|
21
|
+
isClick: boolean;
|
|
22
|
+
};
|
|
23
|
+
size?: number;
|
|
24
|
+
upload?: {
|
|
25
|
+
onUpload: (image: any) => void;
|
|
26
|
+
active: boolean;
|
|
27
|
+
};
|
|
28
|
+
remove?: {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
onRemoveClick: () => void;
|
|
31
|
+
};
|
|
32
|
+
role?: string;
|
|
33
|
+
active?: boolean;
|
|
34
|
+
placeholderIcon?: React.ReactNode;
|
|
35
|
+
disableOverlay?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const ProfileImagePlaceholder: React.FC<
|
|
39
|
+
ProfileImagePlaceholderProps
|
|
40
|
+
> = ({
|
|
41
|
+
name,
|
|
42
|
+
icon,
|
|
43
|
+
click,
|
|
44
|
+
size = 64,
|
|
45
|
+
upload,
|
|
46
|
+
remove,
|
|
47
|
+
role,
|
|
48
|
+
active = false,
|
|
49
|
+
placeholderIcon,
|
|
50
|
+
disableOverlay,
|
|
51
|
+
}) => {
|
|
52
|
+
const backgroundColor = useMemo(() => {
|
|
53
|
+
if(!name) {
|
|
54
|
+
return { backgroundColor: 'transparent' };
|
|
55
|
+
}
|
|
56
|
+
return nameToColor(name);
|
|
57
|
+
}, [name]);
|
|
58
|
+
|
|
59
|
+
const getTwoUppercaseLetters = (fullName: string) => {
|
|
60
|
+
if (!fullName) {return '';}
|
|
61
|
+
|
|
62
|
+
const words = fullName.trim().split(' ').filter(word => word.length > 0);
|
|
63
|
+
|
|
64
|
+
if (words.length === 0) {return '';}
|
|
65
|
+
|
|
66
|
+
if (words.length >= 2) {
|
|
67
|
+
const firstLetter = /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[0]?.[0] || '')
|
|
68
|
+
? words[0][0].toUpperCase()
|
|
69
|
+
: '';
|
|
70
|
+
const secondLetter = /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[1]?.[0] || '')
|
|
71
|
+
? words[1][0].toUpperCase()
|
|
72
|
+
: '';
|
|
73
|
+
return firstLetter + secondLetter;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (words.length === 1 && words[0].length >= 2) {
|
|
77
|
+
const firstLetter = /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[0][0] || '')
|
|
78
|
+
? words[0][0].toUpperCase()
|
|
79
|
+
: '';
|
|
80
|
+
const secondLetter = /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[0][1] || '')
|
|
81
|
+
? words[0][1].toUpperCase()
|
|
82
|
+
: '';
|
|
83
|
+
return firstLetter + secondLetter;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (words.length === 1 && words[0].length === 1) {
|
|
87
|
+
return /^[a-zA-Zа-яА-ЯёЁ]$/.test(words[0][0] || '')
|
|
88
|
+
? words[0][0].toUpperCase()
|
|
89
|
+
: '';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return '';
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const getInitials = () => (!icon && name ? getTwoUppercaseLetters(name) : '');
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Wrapper
|
|
99
|
+
bgColor={icon ? 'transparent' : backgroundColor?.backgroundColor}
|
|
100
|
+
size={size}
|
|
101
|
+
isClickable={active || !!upload?.active}
|
|
102
|
+
>
|
|
103
|
+
<AvatarCircle
|
|
104
|
+
bgColor={icon ? 'transparent' : backgroundColor?.backgroundColor}
|
|
105
|
+
size={size}
|
|
106
|
+
isClickable={active || !!upload?.active}
|
|
107
|
+
onPress={
|
|
108
|
+
upload?.active
|
|
109
|
+
? upload.onUpload
|
|
110
|
+
: click?.isClick
|
|
111
|
+
? click.onPress
|
|
112
|
+
: undefined
|
|
113
|
+
}
|
|
114
|
+
>
|
|
115
|
+
{icon ? (
|
|
116
|
+
<AvatarImage
|
|
117
|
+
source={typeof icon === 'string' ? { uri: icon } : icon}
|
|
118
|
+
size={size}
|
|
119
|
+
/>
|
|
120
|
+
) : placeholderIcon ? (
|
|
121
|
+
placeholderIcon
|
|
122
|
+
) : (
|
|
123
|
+
// Black initials on the pastel hash-color bg — white text
|
|
124
|
+
// on these light backgrounds is unreadable (matches web's
|
|
125
|
+
// default-color behavior).
|
|
126
|
+
<InitialsText size={size} color="#141414">
|
|
127
|
+
{getInitials()}
|
|
128
|
+
</InitialsText>
|
|
129
|
+
)}
|
|
130
|
+
{upload?.active && !disableOverlay && (
|
|
131
|
+
<Overlay>
|
|
132
|
+
<EditIcon style={{ fontSize: size / 2 }} color="#141414" />
|
|
133
|
+
</Overlay>
|
|
134
|
+
)}
|
|
135
|
+
</AvatarCircle>
|
|
136
|
+
{remove?.enabled && icon && role !== 'participant' && (
|
|
137
|
+
<RemoveButton onPress={remove.onRemoveClick}>
|
|
138
|
+
<RemoveButtonText>×</RemoveButtonText>
|
|
139
|
+
</RemoveButton>
|
|
140
|
+
)}
|
|
141
|
+
</Wrapper>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {View, Text, Button} from 'react-native';
|
|
2
|
+
import styled from 'styled-components/native';
|
|
3
|
+
|
|
4
|
+
export const Container = styled.View`
|
|
5
|
+
display: flex;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
align-items: center;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
padding: 20px;
|
|
10
|
+
gap: 8px;
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
export const Message = styled.Text`
|
|
14
|
+
font-size: 16px;
|
|
15
|
+
color: #333;
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
export const OrDelimiter = styled.Text`
|
|
19
|
+
font-size: 14px;
|
|
20
|
+
color: #666;
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
export const CustomButton = styled.TouchableOpacity`
|
|
24
|
+
width: 100%;
|
|
25
|
+
background-color: #007bff;
|
|
26
|
+
padding: 10px;
|
|
27
|
+
border-radius: 4px;
|
|
28
|
+
align-items: center;
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
export const ButtonText = styled.Text`
|
|
32
|
+
color: #fff;
|
|
33
|
+
font-size: 16px;
|
|
34
|
+
`;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, {useMemo} from 'react';
|
|
2
|
+
import {Provider} from 'react-redux';
|
|
3
|
+
import {store} from '../../roomStore';
|
|
4
|
+
import {ConfigUser, IConfig, MessageProps} from '../../types/types';
|
|
5
|
+
import {XmppProvider} from '../../context/xmppProvider.tsx';
|
|
6
|
+
import {MessageNotificationProvider} from '../../context/MessageNotificationContext.tsx';
|
|
7
|
+
import {ToastProvider} from '../../context/ToastContext.tsx';
|
|
8
|
+
import LoginWrapper from './LoginWrapper.tsx';
|
|
9
|
+
// Side-effect import: attaches globalThis.useStoreConsole when enabled.
|
|
10
|
+
import '../../helpers/storeConsole';
|
|
11
|
+
|
|
12
|
+
interface ChatWrapperProps {
|
|
13
|
+
token?: string;
|
|
14
|
+
roomJID?: string;
|
|
15
|
+
user?: ConfigUser;
|
|
16
|
+
loginData?: {email: string; password: string};
|
|
17
|
+
MainComponentStyles?: React.CSSProperties;
|
|
18
|
+
CustomMessageComponent?: React.ComponentType<MessageProps>;
|
|
19
|
+
config?: IConfig;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const ReduxWrapper: React.FC<ChatWrapperProps> = React.memo(
|
|
23
|
+
({...props}) => {
|
|
24
|
+
const memoizedConfig = useMemo(() => {
|
|
25
|
+
return props.config;
|
|
26
|
+
}, [props.config]);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Provider store={store}>
|
|
30
|
+
<XmppProvider config={memoizedConfig}>
|
|
31
|
+
<ToastProvider>
|
|
32
|
+
<MessageNotificationProvider config={memoizedConfig}>
|
|
33
|
+
<LoginWrapper config={memoizedConfig} {...props} />
|
|
34
|
+
</MessageNotificationProvider>
|
|
35
|
+
</ToastProvider>
|
|
36
|
+
</XmppProvider>
|
|
37
|
+
</Provider>
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
);
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import React, {
|
|
4
|
+
useState,
|
|
5
|
+
useEffect,
|
|
6
|
+
useCallback,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import {
|
|
11
|
+
View,
|
|
12
|
+
StyleSheet,
|
|
13
|
+
FlatList,
|
|
14
|
+
Pressable,
|
|
15
|
+
Animated,
|
|
16
|
+
Text,
|
|
17
|
+
TouchableOpacity,
|
|
18
|
+
} from 'react-native';
|
|
19
|
+
import { IRoom } from '../../types/types';
|
|
20
|
+
import { SearchInput } from '../InputComponents/Search';
|
|
21
|
+
import { BurgerMenuIcon, SearchIcon } from '../../assets/icons';
|
|
22
|
+
import ChatRoomItem from '../RoomComponents/ChatRoomItem';
|
|
23
|
+
import { useChatSettingState } from '../../hooks/useChatSettingState';
|
|
24
|
+
import Button from '../styled/Button';
|
|
25
|
+
import { HeaderRoomList } from '../Header/HeaderRoomList';
|
|
26
|
+
import { HeaderRoomListMenu } from '../Menu/HeaderRoomListMenu';
|
|
27
|
+
|
|
28
|
+
const LONG_PRESS_THRESHOLD = 200;
|
|
29
|
+
|
|
30
|
+
interface RoomListProps {
|
|
31
|
+
chats: IRoom[];
|
|
32
|
+
burgerMenu?: boolean;
|
|
33
|
+
onRoomClick?: (chat: IRoom) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const RoomList: React.FC<RoomListProps> = ({
|
|
37
|
+
chats,
|
|
38
|
+
burgerMenu = false,
|
|
39
|
+
onRoomClick,
|
|
40
|
+
}) => {
|
|
41
|
+
const { config } = useChatSettingState();
|
|
42
|
+
|
|
43
|
+
const [open, setOpen] = useState(false);
|
|
44
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
45
|
+
const [isLongPress, setIsLongPress] = useState(false);
|
|
46
|
+
const [isDrawerOpen, setDrawerOpen] = useState(false);
|
|
47
|
+
|
|
48
|
+
const pressTimer = useRef<NodeJS.Timeout | null>(null);
|
|
49
|
+
const containerRef = useRef<View>(null);
|
|
50
|
+
|
|
51
|
+
const drawerAnimation = useRef(new Animated.Value(0)).current;
|
|
52
|
+
const overlayAnimation = useRef(new Animated.Value(0)).current;
|
|
53
|
+
|
|
54
|
+
const handlePressIn = useCallback(() => {
|
|
55
|
+
setIsLongPress(false);
|
|
56
|
+
pressTimer.current = setTimeout(() => {
|
|
57
|
+
setIsLongPress(true);
|
|
58
|
+
}, LONG_PRESS_THRESHOLD);
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
const handlePressOut = useCallback(() => {
|
|
62
|
+
if (pressTimer.current) {
|
|
63
|
+
clearTimeout(pressTimer.current);
|
|
64
|
+
}
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
const performClick = useCallback(
|
|
68
|
+
(chat: IRoom) => {
|
|
69
|
+
if (!isLongPress) {
|
|
70
|
+
onRoomClick?.(chat);
|
|
71
|
+
}
|
|
72
|
+
setOpen(false);
|
|
73
|
+
},
|
|
74
|
+
[onRoomClick, isLongPress]
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const handleSearchChange = useCallback((text: string) => {
|
|
78
|
+
setSearchTerm(text);
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
81
|
+
const getLastMessage = useCallback(
|
|
82
|
+
(chat: IRoom) => chat?.messages?.[chat?.messages.length - 1],
|
|
83
|
+
[]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const filteredChats = useMemo(() => {
|
|
87
|
+
const lowerCaseSearchTerm = searchTerm.toLowerCase();
|
|
88
|
+
const chatsMap = new Map<string, IRoom[]>();
|
|
89
|
+
|
|
90
|
+
if (!chatsMap.has(lowerCaseSearchTerm)) {
|
|
91
|
+
const result = chats
|
|
92
|
+
.filter((chat) => {
|
|
93
|
+
const hay = `${chat?.title || ''} ${chat?.name || ''}`.toLowerCase();
|
|
94
|
+
return hay.includes(lowerCaseSearchTerm);
|
|
95
|
+
})
|
|
96
|
+
.sort((a, b) => {
|
|
97
|
+
if (getLastMessage(a)?.id && getLastMessage(b)?.id) {
|
|
98
|
+
return Number(getLastMessage(b).id) - Number(getLastMessage(a).id);
|
|
99
|
+
} else if (getLastMessage(a)?.id) {
|
|
100
|
+
return -1;
|
|
101
|
+
} else if (getLastMessage(b)?.id) {
|
|
102
|
+
return 1;
|
|
103
|
+
}
|
|
104
|
+
return -1;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
chatsMap.set(lowerCaseSearchTerm, result);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return chatsMap.get(lowerCaseSearchTerm) || [];
|
|
111
|
+
}, [chats, searchTerm]);
|
|
112
|
+
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (burgerMenu) {
|
|
115
|
+
// Since React Native doesn't have a native mouse event, we won't use `mousedown`
|
|
116
|
+
// A listener for "blur" event (on touch outside) or "TouchableWithoutFeedback" may be used for mobile
|
|
117
|
+
}
|
|
118
|
+
}, [burgerMenu]);
|
|
119
|
+
|
|
120
|
+
const toggleDrawer = () => {
|
|
121
|
+
if (isDrawerOpen) {
|
|
122
|
+
closeDrawer();
|
|
123
|
+
} else {
|
|
124
|
+
setDrawerOpen(true);
|
|
125
|
+
Animated.parallel([
|
|
126
|
+
Animated.timing(drawerAnimation, {
|
|
127
|
+
toValue: 1,
|
|
128
|
+
duration: 300,
|
|
129
|
+
useNativeDriver: true,
|
|
130
|
+
}),
|
|
131
|
+
Animated.timing(overlayAnimation, {
|
|
132
|
+
toValue: 1,
|
|
133
|
+
duration: 300,
|
|
134
|
+
useNativeDriver: true,
|
|
135
|
+
}),
|
|
136
|
+
]).start();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const closeDrawer = () => {
|
|
141
|
+
Animated.parallel([
|
|
142
|
+
Animated.timing(drawerAnimation, {
|
|
143
|
+
toValue: 0,
|
|
144
|
+
duration: 300,
|
|
145
|
+
useNativeDriver: true,
|
|
146
|
+
}),
|
|
147
|
+
Animated.timing(overlayAnimation, {
|
|
148
|
+
toValue: 0,
|
|
149
|
+
duration: 300,
|
|
150
|
+
useNativeDriver: true,
|
|
151
|
+
}),
|
|
152
|
+
]).start(() => {
|
|
153
|
+
setDrawerOpen(false);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<>
|
|
159
|
+
{burgerMenu && !open && (
|
|
160
|
+
<Button
|
|
161
|
+
style={{
|
|
162
|
+
padding: 8,
|
|
163
|
+
borderRadius: 16,
|
|
164
|
+
backgroundColor: 'transparent',
|
|
165
|
+
}}
|
|
166
|
+
color="black"
|
|
167
|
+
unstyled
|
|
168
|
+
EndIcon={<BurgerMenuIcon color={config?.colors?.primary} />}
|
|
169
|
+
onPress={() => setOpen(!open)}
|
|
170
|
+
/>
|
|
171
|
+
)}
|
|
172
|
+
<View
|
|
173
|
+
ref={containerRef}
|
|
174
|
+
style={[styles.container, config?.roomListStyles]}
|
|
175
|
+
>
|
|
176
|
+
{(open || !burgerMenu) && (
|
|
177
|
+
<>
|
|
178
|
+
<View style={styles.scrollContainer}>
|
|
179
|
+
<HeaderRoomList setDrawerOpen={toggleDrawer} />
|
|
180
|
+
<FlatList
|
|
181
|
+
data={filteredChats}
|
|
182
|
+
keyExtractor={(item) => item.jid}
|
|
183
|
+
renderItem={({ item }) => (
|
|
184
|
+
<Pressable
|
|
185
|
+
onPress={() => performClick(item)}
|
|
186
|
+
onPressIn={handlePressIn}
|
|
187
|
+
onPressOut={handlePressOut}
|
|
188
|
+
>
|
|
189
|
+
<ChatRoomItem chat={item} config={config} />
|
|
190
|
+
</Pressable>
|
|
191
|
+
)}
|
|
192
|
+
ListHeaderComponent={
|
|
193
|
+
<SearchInput
|
|
194
|
+
icon={<SearchIcon height={20} />}
|
|
195
|
+
value={searchTerm}
|
|
196
|
+
onChangeText={handleSearchChange}
|
|
197
|
+
placeholder="Search..."
|
|
198
|
+
/>
|
|
199
|
+
}
|
|
200
|
+
style={styles.chatList}
|
|
201
|
+
/>
|
|
202
|
+
|
|
203
|
+
<HeaderRoomListMenu
|
|
204
|
+
closeDrawer={closeDrawer}
|
|
205
|
+
drawerAnimation={drawerAnimation}
|
|
206
|
+
overlayAnimation={overlayAnimation}
|
|
207
|
+
isDrawerOpen={isDrawerOpen}
|
|
208
|
+
/>
|
|
209
|
+
</View>
|
|
210
|
+
</>
|
|
211
|
+
)}
|
|
212
|
+
</View>
|
|
213
|
+
</>
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const styles = StyleSheet.create({
|
|
218
|
+
burgerButton: {
|
|
219
|
+
fontSize: 24,
|
|
220
|
+
padding: 10,
|
|
221
|
+
color: '#333',
|
|
222
|
+
},
|
|
223
|
+
container: {
|
|
224
|
+
width: '100%',
|
|
225
|
+
height: '100%',
|
|
226
|
+
flex: 1,
|
|
227
|
+
backgroundColor: '#fff',
|
|
228
|
+
},
|
|
229
|
+
scrollContainer: {
|
|
230
|
+
flexGrow: 1,
|
|
231
|
+
},
|
|
232
|
+
headerContainer: {
|
|
233
|
+
flexDirection: 'row',
|
|
234
|
+
alignItems: 'center',
|
|
235
|
+
padding: 16,
|
|
236
|
+
justifyContent: 'space-between',
|
|
237
|
+
},
|
|
238
|
+
chatList: {
|
|
239
|
+
flex: 1,
|
|
240
|
+
paddingTop: 10,
|
|
241
|
+
paddingHorizontal: 8,
|
|
242
|
+
backgroundColor: '#FAFAFA',
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
export default RoomList;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import styled from 'styled-components/native';
|
|
3
|
+
import {
|
|
4
|
+
Animated,
|
|
5
|
+
TextInput,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
FlatList,
|
|
8
|
+
Keyboard,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { Iso639_1Codes } from '../../types/types';
|
|
11
|
+
|
|
12
|
+
const SelectWrapper = styled.View`
|
|
13
|
+
position: relative;
|
|
14
|
+
width: 100%;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
const SelectBox = styled.TouchableOpacity<{
|
|
18
|
+
isOpen: boolean;
|
|
19
|
+
borderColor?: string;
|
|
20
|
+
}>`
|
|
21
|
+
border: ${({ borderColor }) =>
|
|
22
|
+
borderColor ? `1px solid ${borderColor}` : '1px solid #ccc'};
|
|
23
|
+
padding: 10px;
|
|
24
|
+
flex-direction: row;
|
|
25
|
+
justify-content: space-between;
|
|
26
|
+
align-items: center;
|
|
27
|
+
background-color: #fff;
|
|
28
|
+
border-radius: 5px;
|
|
29
|
+
box-shadow: ${({ isOpen }) =>
|
|
30
|
+
isOpen ? '0px 4px 8px rgba(0, 0, 0, 0.1)' : 'none'};
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const Placeholder = styled.Text`
|
|
34
|
+
color: #aaa;
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const Icon = styled(Animated.Text)`
|
|
38
|
+
margin-left: 10px;
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
const Dropdown = styled.View`
|
|
42
|
+
position: absolute;
|
|
43
|
+
top: 100%;
|
|
44
|
+
left: 0;
|
|
45
|
+
right: 0;
|
|
46
|
+
background-color: #fff;
|
|
47
|
+
max-height: 200px;
|
|
48
|
+
border: 1px solid #ccc;
|
|
49
|
+
border-radius: 5px;
|
|
50
|
+
z-index: 100;
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const SearchBox = styled.TextInput`
|
|
54
|
+
width: 100%;
|
|
55
|
+
padding: 10px;
|
|
56
|
+
border-bottom-width: 1px;
|
|
57
|
+
border-color: #ccc;
|
|
58
|
+
box-sizing: border-box;
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
const DropdownItem = styled.TouchableOpacity`
|
|
62
|
+
padding: 10px;
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const DropdownItemText = styled.Text`
|
|
66
|
+
color: #000;
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
interface SelectProps {
|
|
70
|
+
options: { name: string; id: Iso639_1Codes }[];
|
|
71
|
+
placeholder: string;
|
|
72
|
+
onSelect: (selected: { name: string; id: Iso639_1Codes }) => void;
|
|
73
|
+
accentColor?: string;
|
|
74
|
+
selectedValue: { name: string; id: string } | null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const Select: React.FC<SelectProps> = ({
|
|
78
|
+
options,
|
|
79
|
+
placeholder,
|
|
80
|
+
onSelect,
|
|
81
|
+
accentColor,
|
|
82
|
+
selectedValue = null,
|
|
83
|
+
}) => {
|
|
84
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
85
|
+
const [selected, setSelected] = useState<{ name: string; id: string } | null>(
|
|
86
|
+
selectedValue
|
|
87
|
+
);
|
|
88
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
89
|
+
const rotationAnim = useRef(new Animated.Value(0)).current;
|
|
90
|
+
|
|
91
|
+
const toggleDropdown = () => {
|
|
92
|
+
setIsOpen((prev) => !prev);
|
|
93
|
+
Animated.timing(rotationAnim, {
|
|
94
|
+
toValue: isOpen ? 0 : 1,
|
|
95
|
+
duration: 300,
|
|
96
|
+
useNativeDriver: true,
|
|
97
|
+
}).start();
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const handleSelect = (option: { name: string; id: Iso639_1Codes }) => {
|
|
101
|
+
setSelected(option);
|
|
102
|
+
onSelect(option);
|
|
103
|
+
setIsOpen(false);
|
|
104
|
+
setSearchTerm('');
|
|
105
|
+
Keyboard.dismiss();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const filteredOptions = options.filter((option) =>
|
|
109
|
+
option.name.toLowerCase().includes(searchTerm.toLowerCase())
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const rotateInterpolation = rotationAnim.interpolate({
|
|
113
|
+
inputRange: [0, 1],
|
|
114
|
+
outputRange: ['0deg', '180deg'],
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<SelectWrapper>
|
|
119
|
+
<SelectBox
|
|
120
|
+
isOpen={isOpen}
|
|
121
|
+
onPress={toggleDropdown}
|
|
122
|
+
borderColor={accentColor}
|
|
123
|
+
>
|
|
124
|
+
{selected ? (
|
|
125
|
+
<Placeholder>{selected.name}</Placeholder>
|
|
126
|
+
) : (
|
|
127
|
+
<Placeholder>{placeholder}</Placeholder>
|
|
128
|
+
)}
|
|
129
|
+
<Icon
|
|
130
|
+
style={{
|
|
131
|
+
transform: [{ rotate: rotateInterpolation }],
|
|
132
|
+
color: accentColor,
|
|
133
|
+
}}
|
|
134
|
+
>
|
|
135
|
+
▼
|
|
136
|
+
</Icon>
|
|
137
|
+
</SelectBox>
|
|
138
|
+
{isOpen && (
|
|
139
|
+
<Dropdown>
|
|
140
|
+
<SearchBox
|
|
141
|
+
placeholder="Search..."
|
|
142
|
+
value={searchTerm}
|
|
143
|
+
onChangeText={setSearchTerm}
|
|
144
|
+
/>
|
|
145
|
+
<FlatList
|
|
146
|
+
data={filteredOptions}
|
|
147
|
+
keyExtractor={(item) => item.id}
|
|
148
|
+
renderItem={({ item }) => (
|
|
149
|
+
<DropdownItem onPress={() => handleSelect(item)}>
|
|
150
|
+
<DropdownItemText>{item.name}</DropdownItemText>
|
|
151
|
+
</DropdownItem>
|
|
152
|
+
)}
|
|
153
|
+
ListEmptyComponent={
|
|
154
|
+
<DropdownItem>
|
|
155
|
+
<DropdownItemText>No options found</DropdownItemText>
|
|
156
|
+
</DropdownItem>
|
|
157
|
+
}
|
|
158
|
+
/>
|
|
159
|
+
</Dropdown>
|
|
160
|
+
)}
|
|
161
|
+
</SelectWrapper>
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export default Select;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React, { useCallback, useRef, useState } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
import styled from 'styled-components/native';
|
|
4
|
+
|
|
5
|
+
const SwitchContainer = styled.Pressable<{ isOn: boolean; bgColor?: string }>`
|
|
6
|
+
width: 34px;
|
|
7
|
+
height: 18px;
|
|
8
|
+
background-color: ${({ isOn, bgColor }) =>
|
|
9
|
+
isOn ? (bgColor ? bgColor : '#0056d2') : '#8C8C8C'};
|
|
10
|
+
border-radius: 100px;
|
|
11
|
+
display: flex;
|
|
12
|
+
transition: background-color 0.3s;
|
|
13
|
+
padding: 2px;
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
const Toggle = styled(Animated.View)`
|
|
17
|
+
width: 15px;
|
|
18
|
+
height: 15px;
|
|
19
|
+
background-color: white;
|
|
20
|
+
border-radius: 100px;
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
interface SwitchProps {
|
|
24
|
+
onToggle: (isOn: boolean) => void;
|
|
25
|
+
bgColor?: string;
|
|
26
|
+
onSwitchOn?: () => void;
|
|
27
|
+
onSwitchOff?: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const Switch: React.FC<SwitchProps> = ({
|
|
31
|
+
onSwitchOn,
|
|
32
|
+
onSwitchOff,
|
|
33
|
+
onToggle,
|
|
34
|
+
bgColor,
|
|
35
|
+
}) => {
|
|
36
|
+
const [isOn, setIsOn] = useState(false);
|
|
37
|
+
const translateX = useRef(new Animated.Value(0)).current;
|
|
38
|
+
|
|
39
|
+
const toggleSwitch = () => {
|
|
40
|
+
const nextState = !isOn;
|
|
41
|
+
|
|
42
|
+
Animated.timing(translateX, {
|
|
43
|
+
toValue: nextState ? 15 : 0,
|
|
44
|
+
duration: 300,
|
|
45
|
+
useNativeDriver: true,
|
|
46
|
+
}).start();
|
|
47
|
+
|
|
48
|
+
if (nextState) {
|
|
49
|
+
onSwitchOn?.();
|
|
50
|
+
} else {
|
|
51
|
+
onSwitchOff?.();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setIsOn(nextState);
|
|
55
|
+
onToggle(nextState);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<SwitchContainer
|
|
60
|
+
isOn={isOn}
|
|
61
|
+
onPress={toggleSwitch}
|
|
62
|
+
accessibilityRole="switch"
|
|
63
|
+
accessibilityState={{ checked: isOn }}
|
|
64
|
+
accessibilityLabel="Toggle switch"
|
|
65
|
+
accessibilityHint="Double tap to toggle on or off"
|
|
66
|
+
bgColor={bgColor}
|
|
67
|
+
>
|
|
68
|
+
<Toggle style={{ transform: [{ translateX }] }} />
|
|
69
|
+
</SwitchContainer>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default Switch;
|