agora-appbuilder-core 2.2.0 → 2.3.0-beta.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 (280) hide show
  1. package/Readme.md +7 -1
  2. package/package.json +4 -3
  3. package/template/Gulpfile.js +306 -87
  4. package/template/_gitignore +4 -1
  5. package/template/_package-lock.json +2297 -2533
  6. package/template/agora-rn-uikit/.git/HEAD +1 -1
  7. package/template/agora-rn-uikit/.git/config +3 -3
  8. package/template/agora-rn-uikit/.git/index +0 -0
  9. package/template/agora-rn-uikit/.git/logs/HEAD +2 -2
  10. package/template/agora-rn-uikit/.git/logs/refs/heads/master +1 -1
  11. package/template/agora-rn-uikit/.git/logs/refs/heads/release/fpe-1.0.0 +1 -0
  12. package/template/agora-rn-uikit/.git/logs/refs/remotes/origin/HEAD +1 -1
  13. package/template/agora-rn-uikit/.git/objects/pack/pack-f274a85fccfc9b5112d154bb3b6d34cb4b8dedde.idx +0 -0
  14. package/template/agora-rn-uikit/.git/objects/pack/{pack-0061d00cd98162a329a32b537488a35d0abeb069.pack → pack-f274a85fccfc9b5112d154bb3b6d34cb4b8dedde.pack} +0 -0
  15. package/template/agora-rn-uikit/.git/packed-refs +5 -1
  16. package/template/agora-rn-uikit/.git/refs/heads/release/fpe-1.0.0 +1 -0
  17. package/template/agora-rn-uikit/src/AgoraUIKit.tsx +23 -20
  18. package/template/agora-rn-uikit/src/Contexts/LocalUserContext.tsx +13 -8
  19. package/template/agora-rn-uikit/src/Contexts/PropsContext.tsx +25 -9
  20. package/template/agora-rn-uikit/src/Contexts/RenderContext.tsx +10 -0
  21. package/template/agora-rn-uikit/src/Contexts/RtcContext.tsx +11 -5
  22. package/template/agora-rn-uikit/src/Controls/BtnTemplate.tsx +6 -2
  23. package/template/agora-rn-uikit/src/Controls/ImageIcon.tsx +1 -1
  24. package/template/agora-rn-uikit/src/Controls/Local/EndCall.tsx +6 -2
  25. package/template/agora-rn-uikit/src/Controls/Local/LocalAudioMute.tsx +2 -2
  26. package/template/agora-rn-uikit/src/Controls/Local/LocalVideoMute.tsx +2 -2
  27. package/template/agora-rn-uikit/src/Controls/Local/SwitchCamera.tsx +6 -2
  28. package/template/agora-rn-uikit/src/Controls/LocalControls.tsx +11 -6
  29. package/template/agora-rn-uikit/src/Controls/Remote/RemoteAudioMute.tsx +10 -6
  30. package/template/agora-rn-uikit/src/Controls/Remote/RemoteSwap.tsx +7 -6
  31. package/template/agora-rn-uikit/src/Controls/Remote/RemoteVideoMute.tsx +6 -5
  32. package/template/agora-rn-uikit/src/Controls/RemoteControls.tsx +3 -3
  33. package/template/agora-rn-uikit/src/Reducer/LocalMuteAudio.ts +16 -13
  34. package/template/agora-rn-uikit/src/Reducer/LocalMuteVideo.ts +16 -13
  35. package/template/agora-rn-uikit/src/Reducer/RemoteAudioStateChanged.ts +13 -13
  36. package/template/agora-rn-uikit/src/Reducer/RemoteVideoStateChanged.ts +16 -13
  37. package/template/agora-rn-uikit/src/Reducer/UpdateDualStreamMode.ts +28 -31
  38. package/template/agora-rn-uikit/src/Reducer/UserJoined.ts +48 -35
  39. package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteAudio.ts +11 -13
  40. package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteVideo.ts +11 -13
  41. package/template/agora-rn-uikit/src/Reducer/UserOffline.ts +18 -15
  42. package/template/agora-rn-uikit/src/Rtc/Create.tsx +14 -2
  43. package/template/agora-rn-uikit/src/Rtc/Join.tsx +19 -3
  44. package/template/agora-rn-uikit/src/RtcConfigure.tsx +161 -44
  45. package/template/agora-rn-uikit/src/Utils/useLocalUid.ts +8 -0
  46. package/template/agora-rn-uikit/src/Views/MaxVideoView.native.tsx +8 -6
  47. package/template/agora-rn-uikit/src/Views/MaxVideoView.tsx +8 -6
  48. package/template/agora-rn-uikit/src/Views/MinVideoView.tsx +18 -9
  49. package/template/agora-rn-uikit/src/index.ts +12 -12
  50. package/template/babel.config.js +17 -1
  51. package/template/bridge/rtc/webNg/RtcEngine.ts +34 -28
  52. package/template/bridge/rtc/webNg/SurfaceView.tsx +3 -2
  53. package/template/bridge/rtc/webNg/Types.ts +14 -0
  54. package/template/bridge/rtc/webNg/index.ts +5 -2
  55. package/template/bridge/rtm/web/index.ts +13 -7
  56. package/template/electron-builder.js +3 -2
  57. package/template/esbuild.rsdk.go +226 -0
  58. package/template/{src/subComponents/LayoutEnum.tsx → esbuildConfigTransform.js} +1 -5
  59. package/template/fpe-api/components.ts +42 -0
  60. package/template/fpe-api/context.ts +45 -0
  61. package/template/fpe-api/fpeEvents.ts +9 -0
  62. package/template/fpe-api/index.ts +21 -0
  63. package/template/fpe-api/install.ts +128 -0
  64. package/template/fpe-api/typeDefinition.ts +143 -0
  65. package/template/fpe-api/useFpe.tsx +35 -0
  66. package/template/fpe-api/utils.ts +62 -0
  67. package/template/fpe-implementation/createHook.ts +33 -0
  68. package/template/fpe-implementation/dummyFpe.ts +17 -0
  69. package/template/fpe-implementation/index.ts +1 -0
  70. package/template/fpe-todo.txt +14 -0
  71. package/template/fpe.config.js +25 -0
  72. package/template/global.d.ts +4 -0
  73. package/template/index.rsdk.tsx +27 -0
  74. package/template/index.wsdk.tsx +27 -0
  75. package/template/package-lock.json +2297 -2533
  76. package/template/package.json +28 -12
  77. package/template/react-native-toast-message/src/index.js +9 -10
  78. package/template/react-native-toast-message/src/index.wsdk.js +419 -0
  79. package/template/src/App.tsx +97 -65
  80. package/template/src/AppWrapper.tsx +79 -0
  81. package/template/src/SDKAppWrapper.tsx +67 -0
  82. package/template/src/atoms/PrimaryButton.tsx +14 -8
  83. package/template/src/atoms/TextInput.tsx +13 -5
  84. package/template/src/components/Chat.tsx +171 -139
  85. package/template/src/components/ChatContext.ts +14 -22
  86. package/template/src/components/ColorConfigure.tsx +2 -2
  87. package/template/src/components/Controls.native.tsx +72 -62
  88. package/template/src/components/Controls.tsx +90 -69
  89. package/template/src/components/DeviceConfigure.tsx +1 -1
  90. package/template/src/components/DeviceContext.tsx +14 -7
  91. package/template/src/components/GraphQLProvider.tsx +9 -2
  92. package/template/src/components/GridVideo.tsx +20 -159
  93. package/template/src/components/HostControlView.tsx +54 -15
  94. package/template/src/components/Navbar.tsx +408 -157
  95. package/template/src/components/NetworkQualityContext.tsx +29 -22
  96. package/template/src/components/ParticipantsView.tsx +97 -119
  97. package/template/src/components/PinnedVideo.tsx +41 -188
  98. package/template/src/components/Precall.native.tsx +131 -97
  99. package/template/src/components/Precall.tsx +193 -158
  100. package/template/src/components/RTMConfigure.tsx +320 -398
  101. package/template/src/components/Router.sdk.ts +20 -0
  102. package/template/src/components/SessionContext.tsx +6 -3
  103. package/template/src/components/Settings.native.tsx +3 -0
  104. package/template/src/components/Settings.tsx +65 -31
  105. package/template/src/components/SettingsView.tsx +14 -8
  106. package/template/src/components/Share.tsx +188 -220
  107. package/template/src/components/StorageContext.tsx +5 -5
  108. package/template/src/components/StoreToken.tsx +5 -1
  109. package/template/src/components/chat-messages/useChatMessages.tsx +202 -0
  110. package/template/src/components/chat-notification/useChatNotification.tsx +78 -0
  111. package/template/src/components/chat-ui/useChatUIControl.tsx +66 -0
  112. package/template/src/components/common/Error.tsx +54 -0
  113. package/template/src/components/common/Logo.tsx +35 -0
  114. package/template/src/components/common/index.tsx +8 -0
  115. package/template/src/components/contexts/LiveStreamDataContext.tsx +79 -0
  116. package/template/src/components/contexts/ScreenShareContext.tsx +47 -0
  117. package/template/src/components/contexts/WhiteboardContext.tsx +59 -0
  118. package/template/src/components/dimension/DimensionContext.ts +27 -0
  119. package/template/src/components/dimension/DimensionProvider.tsx +34 -0
  120. package/template/src/components/livestream/LiveStreamContext.tsx +293 -272
  121. package/template/src/components/livestream/Types.ts +26 -7
  122. package/template/src/components/livestream/index.ts +13 -2
  123. package/template/src/components/livestream/views/LiveStreamControls.tsx +5 -1
  124. package/template/src/components/meeting-info/useMeetingInfo.tsx +63 -0
  125. package/template/src/components/meeting-info/useSetMeetingInfo.tsx +38 -0
  126. package/template/src/components/participants/AllAudienceParticipants.tsx +26 -21
  127. package/template/src/components/participants/AllHostParticipants.tsx +36 -53
  128. package/template/src/components/participants/MeParticipant.tsx +9 -10
  129. package/template/src/components/participants/ParticipantName.tsx +2 -1
  130. package/template/src/components/participants/RemoteParticipants.tsx +3 -3
  131. package/template/src/components/precall/LocalMute.native.tsx +91 -0
  132. package/template/src/components/precall/LocalMute.tsx +90 -0
  133. package/template/src/components/precall/VideoPreview.native.tsx +35 -0
  134. package/template/src/components/precall/VideoPreview.tsx +33 -0
  135. package/template/src/components/precall/index.tsx +28 -0
  136. package/template/src/components/precall/joinCallBtn.native.tsx +69 -0
  137. package/template/src/components/precall/joinCallBtn.tsx +91 -0
  138. package/template/src/components/precall/meetingTitle.tsx +26 -0
  139. package/template/src/components/precall/selectDevice.tsx +46 -0
  140. package/template/src/components/precall/textInput.tsx +43 -0
  141. package/template/src/components/precall/usePreCall.tsx +41 -0
  142. package/template/src/components/styles.ts +20 -3
  143. package/template/src/components/useShareLink.tsx +222 -0
  144. package/template/src/components/useWakeLock.tsx +3 -3
  145. package/template/src/custom-events/CustomEvents.ts +197 -0
  146. package/template/src/custom-events/index.tsx +4 -0
  147. package/template/src/custom-events/types.ts +51 -0
  148. package/template/src/language/default-labels/commonLabels.ts +21 -0
  149. package/template/src/language/default-labels/createScreenLabels.ts +22 -0
  150. package/template/src/language/default-labels/index.ts +38 -0
  151. package/template/src/language/default-labels/joinScreenLabels.ts +13 -0
  152. package/template/src/language/default-labels/precallScreenLabels.ts +33 -0
  153. package/template/src/language/default-labels/shareLinkScreenLabels.ts +44 -0
  154. package/template/src/language/default-labels/videoCallScreenLabels.ts +189 -0
  155. package/template/src/language/i18nTypes.ts +10 -0
  156. package/template/src/language/index.ts +18 -0
  157. package/template/src/language/useLanguage.tsx +92 -0
  158. package/template/src/pages/Authenticate.tsx +21 -15
  159. package/template/src/pages/Create.tsx +176 -159
  160. package/template/src/pages/Join.tsx +44 -32
  161. package/template/src/pages/VideoCall.tsx +134 -406
  162. package/template/src/pages/create/useCreate.tsx +37 -0
  163. package/template/src/pages/video-call/CustomLayout.ts +17 -0
  164. package/template/src/pages/video-call/CustomUserContextHolder.tsx +12 -0
  165. package/template/src/pages/video-call/DefaultLayouts.ts +65 -0
  166. package/template/src/pages/video-call/NameWithMicStatus.tsx +62 -0
  167. package/template/src/pages/video-call/RenderComponent.tsx +52 -0
  168. package/template/src/pages/video-call/VideoCallScreen.tsx +191 -0
  169. package/template/src/pages/video-call/VideoComponent.tsx +34 -0
  170. package/template/src/pages/video-call/VideoRenderer.tsx +86 -0
  171. package/template/src/pages/video-call/index.ts +20 -0
  172. package/template/src/rtm/RTMEngine.ts +58 -0
  173. package/template/src/rtm/utils.ts +28 -0
  174. package/template/src/rtm-events/EventUtils.ts +268 -0
  175. package/template/src/rtm-events/EventsQueue.ts +38 -0
  176. package/template/src/rtm-events/constants.ts +40 -0
  177. package/template/src/rtm-events/index.tsx +8 -0
  178. package/template/src/rtm-events/types.ts +7 -0
  179. package/template/src/subComponents/ChatBubble.tsx +18 -11
  180. package/template/src/subComponents/ChatContainer.tsx +78 -29
  181. package/template/src/subComponents/ChatInput.tsx +146 -70
  182. package/template/src/subComponents/CopyJoinInfo.tsx +52 -67
  183. package/template/src/subComponents/Error.tsx +35 -24
  184. package/template/src/subComponents/LanguageSelector.tsx +85 -0
  185. package/template/src/subComponents/LayoutIconDropdown.native.tsx +163 -0
  186. package/template/src/subComponents/LayoutIconDropdown.tsx +198 -0
  187. package/template/src/subComponents/LocalAudioMute.tsx +52 -30
  188. package/template/src/subComponents/LocalEndCall.tsx +52 -0
  189. package/template/src/subComponents/LocalSwitchCamera.tsx +61 -0
  190. package/template/src/subComponents/LocalVideoMute.tsx +48 -30
  191. package/template/src/subComponents/LogoutButton.tsx +20 -5
  192. package/template/src/subComponents/NetworkQualityPill.tsx +43 -13
  193. package/template/src/subComponents/OpenInNativeButton.tsx +3 -2
  194. package/template/src/subComponents/Recording.tsx +46 -138
  195. package/template/src/subComponents/RemoteAudioMute.tsx +30 -34
  196. package/template/src/subComponents/RemoteEndCall.tsx +18 -7
  197. package/template/src/subComponents/RemoteVideoMute.tsx +17 -9
  198. package/template/src/subComponents/ScreenShareNotice.tsx +40 -40
  199. package/template/src/subComponents/SelectDevice.tsx +88 -45
  200. package/template/src/subComponents/SelectOAuth.tsx +30 -6
  201. package/template/src/subComponents/SidePanelButtons.ts +39 -0
  202. package/template/src/subComponents/TextWithTooltip.native.tsx +2 -1
  203. package/template/src/subComponents/TextWithTooltip.tsx +15 -20
  204. package/template/src/subComponents/chat/ChatParticipants.tsx +31 -32
  205. package/template/src/subComponents/livestream/ApprovedLiveStreamControlsView.tsx +7 -3
  206. package/template/src/subComponents/livestream/CurrentLiveStreamRequestsView.tsx +32 -18
  207. package/template/src/subComponents/livestream/controls/LocalRaiseHand.tsx +22 -8
  208. package/template/src/subComponents/livestream/controls/RemoteLiveStreamApprovedRequestRecall.tsx +12 -7
  209. package/template/src/subComponents/livestream/controls/RemoteLiveStreamRequestApprove.tsx +24 -27
  210. package/template/src/subComponents/livestream/controls/RemoteLiveStreamRequestReject.tsx +23 -26
  211. package/template/src/subComponents/livestream/index.ts +10 -2
  212. package/template/src/subComponents/recording/useRecording.tsx +209 -0
  213. package/template/src/subComponents/recording/useRecordingLayoutQuery.tsx +64 -0
  214. package/template/src/subComponents/screenshare/ScreenshareButton.native.tsx +18 -0
  215. package/template/src/subComponents/screenshare/ScreenshareButton.tsx +59 -31
  216. package/template/src/subComponents/screenshare/ScreenshareConfigure.native.tsx +57 -52
  217. package/template/src/subComponents/screenshare/ScreenshareConfigure.tsx +97 -138
  218. package/template/src/subComponents/screenshare/useScreenshare.tsx +29 -0
  219. package/template/src/subComponents/toastConfig.tsx +25 -20
  220. package/template/src/utils/IsAttendeeUser.ts +34 -0
  221. package/template/src/utils/SdkEvents.ts +68 -0
  222. package/template/src/utils/common.tsx +40 -0
  223. package/template/src/utils/eventEmitter.ts +29 -0
  224. package/template/src/utils/getMeetingInvite.ts +30 -0
  225. package/template/src/utils/index.tsx +11 -2
  226. package/template/src/utils/isAudioEnabled.ts +29 -0
  227. package/template/src/utils/isHostUser.ts +33 -0
  228. package/template/src/utils/isMobileOrTablet.native.ts +5 -0
  229. package/template/src/utils/{mobileWebTest.tsx → isMobileOrTablet.ts} +5 -2
  230. package/template/src/utils/isPSTNUser.ts +30 -0
  231. package/template/src/utils/isSDK.sdk.ts +5 -0
  232. package/template/src/utils/isSDK.ts +5 -0
  233. package/template/src/utils/isScreenShareUser.ts +31 -0
  234. package/template/src/utils/isVideoEnabled.ts +29 -0
  235. package/template/src/utils/useButtonTemplate.tsx +43 -0
  236. package/template/src/utils/useCreateMeeting.ts +74 -0
  237. package/template/src/utils/useGetLiveStreamingRequests.ts +24 -0
  238. package/template/src/utils/useGetMeetingPhrase.ts +68 -0
  239. package/template/src/utils/useGetName.ts +20 -0
  240. package/template/src/{subComponents/screenshare/ScreenshareContext.tsx → utils/useGroupMessages.ts} +10 -7
  241. package/template/src/utils/useJoinMeeting.ts +120 -0
  242. package/template/src/utils/useLayout.tsx +40 -0
  243. package/template/src/utils/useLiveStreamingUids.ts +26 -0
  244. package/template/src/utils/useMutePSTN.ts +43 -0
  245. package/template/src/utils/useMuteToggleLocal.ts +109 -0
  246. package/template/src/utils/useNavParams.ts +6 -0
  247. package/template/src/utils/useNavigateTo.ts +8 -0
  248. package/template/src/utils/usePrivateMessages.ts +33 -0
  249. package/template/src/utils/useRemoteEndCall.ts +27 -0
  250. package/template/src/utils/useRemoteMute.ts +64 -0
  251. package/template/src/utils/useSendControlMessage.ts +51 -0
  252. package/template/src/utils/useSendMessage.ts +40 -0
  253. package/template/src/utils/useSetName.ts +20 -0
  254. package/template/src/utils/useSetUnreadMessageCount.ts +43 -0
  255. package/template/src/utils/useSidePanel.tsx +41 -0
  256. package/template/src/utils/useString.ts +61 -0
  257. package/template/src/utils/useUnreadMessageCount.ts +50 -0
  258. package/template/src/utils/useUserList.ts +26 -0
  259. package/template/tsconfig.json +4 -4
  260. package/template/tsconfig_fpeApi.json +103 -0
  261. package/template/tsconfig_rsdk_index.json +105 -0
  262. package/template/tsconfig_wsdk_index.json +104 -0
  263. package/template/webpack.commons.js +40 -16
  264. package/template/webpack.main.config.js +2 -1
  265. package/template/webpack.renderer.config.js +1 -1
  266. package/template/webpack.rsdk.config.js +33 -0
  267. package/template/webpack.ts.config.js +89 -0
  268. package/template/webpack.web.config.js +8 -1
  269. package/template/webpack.wsdk.config.js +34 -0
  270. package/template/agora-rn-uikit/.git/logs/refs/heads/ab-dev-auto +0 -1
  271. package/template/agora-rn-uikit/.git/objects/pack/pack-0061d00cd98162a329a32b537488a35d0abeb069.idx +0 -0
  272. package/template/agora-rn-uikit/.git/refs/heads/ab-dev-auto +0 -1
  273. package/template/agora-rn-uikit/src/Contexts/MaxUidContext.tsx +0 -7
  274. package/template/agora-rn-uikit/src/Contexts/MinUidContext.tsx +0 -8
  275. package/template/src/components/participants/context/ParticipantContext.tsx +0 -97
  276. package/template/src/subComponents/ScreenshareButton.tsx +0 -257
  277. package/template/src/subComponents/SwitchCamera.tsx +0 -35
  278. package/template/src/utils/hasBrandLogo.tsx +0 -3
  279. package/template/src/utils/mobileWebTest.native.tsx +0 -5
  280. package/template/src/utils/shouldAuthenticate.tsx +0 -7
@@ -6,15 +6,21 @@
6
6
  "scripts": {
7
7
  "android": "react-native run-android",
8
8
  "android:build": "npm run android:build:unix",
9
- "android:build:unix": "cd android && ./gradlew assembleRelease",
10
- "android:build:windows": "cd android && gradlew.bat assembleRelease",
9
+ "android:build:unix": "cross-env TARGET=android gulp androidUnix",
10
+ "android:build:windows": "cross-env TARGET=android gulp androidWin",
11
11
  "ios": "cd ios && ls | grep .xcworkspace | xargs open",
12
12
  "ios:build": "cd ios && ls | grep .xcworkspace | xargs open",
13
13
  "start": "react-native start",
14
14
  "web": "cross-env TARGET=web NODE_ENV=development webpack-dev-server --hot --open --config webpack.web.config.js",
15
+ "ts": "cross-env TARGET=web NODE_ENV=production webpack --config webpack.ts.config.js",
15
16
  "web:build": "cross-env TARGET=web NODE_ENV=production webpack --config webpack.web.config.js",
16
- "electron:start": "cross-env NODE_ENV=development gulp development",
17
- "electron:build": "cross-env NODE_ENV=production gulp build",
17
+ "web-sdk": "cross-env TARGET=wsdk NODE_ENV=development gulp webSdk",
18
+ "web-sdk:build": "cross-env TARGET=wsdk NODE_ENV=production gulp webSdk",
19
+ "react-sdk": "cross-env TARGET=rsdk NODE_ENV=development gulp reactSdk",
20
+ "react-sdk:build": "cross-env TARGET=rsdk NODE_ENV=production gulp reactSdk",
21
+ "react-sdk-esbuild": "cross-env TARGET=rsdk NODE_ENV=production gulp reactSdkEsbuild",
22
+ "electron:start": "cross-env NODE_ENV=development gulp electron_development",
23
+ "electron:build": "cross-env NODE_ENV=production gulp electron_build",
18
24
  "windows": "cross-env TARGET=windows npm run electron:start",
19
25
  "windows:build": "cross-env TARGET=windows npm run electron:build",
20
26
  "mac": "cross-env TARGET=mac npm run electron:start",
@@ -58,6 +64,7 @@
58
64
  "nosleep.js": "0.12.0",
59
65
  "react": "16.13.1",
60
66
  "react-dom": "16.13.1",
67
+ "react-is": "18.0.0",
61
68
  "react-native": "0.63.3",
62
69
  "react-native-agora": "3.4.2",
63
70
  "react-native-hyperlink": "0.0.19",
@@ -78,20 +85,23 @@
78
85
  "@babel/preset-typescript": "7.13.0",
79
86
  "@babel/runtime": "7.14.0",
80
87
  "@bam.tech/react-native-make": "3.0.3",
81
- "@pmmmwh/react-refresh-webpack-plugin": "0.3.3",
88
+ "@pmmmwh/react-refresh-webpack-plugin": "0.5.5",
82
89
  "@react-native-community/eslint-config": "1.1.0",
83
90
  "@types/jest": "25.2.3",
91
+ "@types/react-is": "17.0.3",
84
92
  "@types/react-native": "0.67.6",
85
93
  "@types/react-native-keep-awake": "2.0.2",
86
94
  "@types/react-router-dom": "5.1.7",
87
95
  "@types/react-router-native": "5.1.0",
88
96
  "@types/react-test-renderer": "16.9.5",
89
97
  "@types/webpack-dev-server": "3.11.4",
98
+ "@types/webpack-env": "^1.16.4",
90
99
  "@typescript-eslint/eslint-plugin": "2.34.0",
91
100
  "@typescript-eslint/parser": "2.34.0",
92
- "babel-jest": "25.5.1",
93
- "babel-loader": "8.2.2",
94
- "babel-plugin-transform-define": "2.0.0",
101
+ "babel-jest": "27.5.1",
102
+ "babel-loader": "8.2.4",
103
+ "babel-plugin-module-resolver": "4.1.0",
104
+ "babel-plugin-transform-define": "2.0.1",
95
105
  "cross-env": "7.0.3",
96
106
  "del": "5.1.0",
97
107
  "electron": "16.0.1",
@@ -100,18 +110,24 @@
100
110
  "eslint": "6.8.0",
101
111
  "file-loader": "6.2.0",
102
112
  "gulp": "4.0.2",
113
+ "gulp-concat": "^2.6.1",
114
+ "gulp-header": "^2.0.9",
115
+ "gulp-replace": "^1.1.3",
103
116
  "html-webpack-plugin": "4.5.2",
117
+ "ignore-loader": "^0.1.2",
104
118
  "jest": "25.5.4",
105
119
  "metro-react-native-babel-preset": "0.59.0",
106
120
  "prettier": "2.3.1",
107
121
  "react-devtools-electron": "4.7.0",
108
- "react-refresh": "0.8.3",
122
+ "react-refresh": "0.12.0",
109
123
  "react-test-renderer": "16.13.1",
124
+ "ts-loader": "^8.3.0",
110
125
  "typescript": "3.9.9",
111
- "webpack": "4.46.0",
112
- "webpack-cli": "3.3.12",
113
- "webpack-dev-server": "3.11.2",
126
+ "webpack": "5.72.0",
127
+ "webpack-cli": "^4.10.0",
128
+ "webpack-dev-server": "4.8.1",
114
129
  "webpack-merge": "5.8.0",
130
+ "webpack-node-externals": "3.0.0",
115
131
  "yargs": "15.4.1"
116
132
  },
117
133
  "jest": {
@@ -343,13 +343,8 @@ class Toast extends Component {
343
343
  }
344
344
 
345
345
  getBaseStyle(position = 'bottom', keyboardHeight) {
346
- const {
347
- topOffset,
348
- bottomOffset,
349
- keyboardOffset,
350
- height,
351
- animation
352
- } = this.state;
346
+ const { topOffset, bottomOffset, keyboardOffset, height, animation } =
347
+ this.state;
353
348
  const offset = position === 'bottom' ? bottomOffset : topOffset;
354
349
 
355
350
  // +5 px to completely hide the toast under StatusBar (on Android)
@@ -358,14 +353,14 @@ class Toast extends Component {
358
353
 
359
354
  const translateY = animation.interpolate({
360
355
  inputRange: [0, 1, 2],
361
- outputRange
356
+ outputRange: [0, 1, 0]
362
357
  });
363
358
 
364
359
  return [
365
360
  styles.base,
366
361
  styles[position],
367
362
  {
368
- transform: [{ translateY }]
363
+ opacity: translateY
369
364
  }
370
365
  ];
371
366
  }
@@ -383,7 +378,11 @@ class Toast extends Component {
383
378
  <Animated.View
384
379
  testID='animatedView'
385
380
  onLayout={this.onLayout}
386
- style={[baseStyle, style, {zIndex: 100}]} //added zindex
381
+ style={[
382
+ baseStyle,
383
+ style,
384
+ { zIndex: 100, display: this.state.isVisible || this.state.inProgress ? 'flex' : 'none' }
385
+ ]} //added zindex
387
386
  {...this.panResponder.panHandlers}>
388
387
  {this.renderContent(this.props)}
389
388
  </Animated.View>
@@ -0,0 +1,419 @@
1
+ import React, { Component } from 'react';
2
+ import { Animated, PanResponder, Keyboard } from 'react-native';
3
+ import PropTypes from 'prop-types';
4
+
5
+ import SuccessToast from './components/success';
6
+ import ErrorToast from './components/error';
7
+ import InfoToast from './components/info';
8
+ import { complement } from './utils/arr';
9
+ import { includeKeys } from './utils/obj';
10
+ import { stylePropType } from './utils/prop-types';
11
+ import { isIOS } from './utils/platform';
12
+ import styles from './styles';
13
+
14
+ const FRICTION = 8;
15
+
16
+ const defaultComponentsConfig = {
17
+ // eslint-disable-next-line react/prop-types
18
+ success: ({ hide, ...rest }) => (
19
+ <SuccessToast {...rest} onTrailingIconPress={hide} />
20
+ ),
21
+ // eslint-disable-next-line react/prop-types
22
+ error: ({ hide, ...rest }) => (
23
+ <ErrorToast {...rest} onTrailingIconPress={hide} />
24
+ ),
25
+ // eslint-disable-next-line react/prop-types
26
+ info: ({ hide, ...rest }) => (
27
+ <InfoToast {...rest} onTrailingIconPress={hide} />
28
+ )
29
+ };
30
+
31
+ function shouldSetPanResponder(gesture) {
32
+ const { dx, dy } = gesture;
33
+ // Fixes onPress handler https://github.com/calintamas/react-native-toast-message/issues/113
34
+ return Math.abs(dx) > 2 || Math.abs(dy) > 2;
35
+ }
36
+
37
+ const getInitialState = ({
38
+ topOffset,
39
+ bottomOffset,
40
+ keyboardOffset,
41
+ visibilityTime,
42
+ height,
43
+ autoHide,
44
+ position,
45
+ type
46
+ }) => ({
47
+ // layout
48
+ topOffset,
49
+ bottomOffset,
50
+ keyboardOffset,
51
+ height,
52
+ position,
53
+ type,
54
+
55
+ // timing (in ms)
56
+ visibilityTime,
57
+ autoHide,
58
+
59
+ // content
60
+ text1: undefined,
61
+ text2: undefined,
62
+
63
+ onPress: undefined,
64
+ onShow: undefined,
65
+ onHide: undefined
66
+ });
67
+
68
+ class Toast extends Component {
69
+ static _ref = null;
70
+
71
+ static setRef(ref = {}) {
72
+ Toast._ref = ref;
73
+ }
74
+
75
+ static getRef() {
76
+ return Toast._ref;
77
+ }
78
+
79
+ static clearRef() {
80
+ Toast._ref = null;
81
+ }
82
+
83
+ static show(options = {}) {
84
+ Toast._ref.show(options);
85
+ }
86
+
87
+ static hide() {
88
+ Toast._ref.hide();
89
+ }
90
+
91
+ constructor(props) {
92
+ super(props);
93
+
94
+ this._setState = this._setState.bind(this);
95
+ this._animateMovement = this._animateMovement.bind(this);
96
+ this._animateRelease = this._animateRelease.bind(this);
97
+ this.startTimer = this.startTimer.bind(this);
98
+ this.animate = this.animate.bind(this);
99
+ this.show = this.show.bind(this);
100
+ this.hide = this.hide.bind(this);
101
+ this.onLayout = this.onLayout.bind(this);
102
+
103
+ this.state = {
104
+ ...getInitialState(props),
105
+
106
+ inProgress: false,
107
+ isVisible: false,
108
+ animation: new Animated.Value(0),
109
+ keyboardHeight: 0,
110
+ keyboardVisible: false,
111
+
112
+ customProps: {}
113
+ };
114
+
115
+ this.panResponder = PanResponder.create({
116
+ onMoveShouldSetPanResponder: (event, gesture) =>
117
+ shouldSetPanResponder(gesture),
118
+ onMoveShouldSetPanResponderCapture: (event, gesture) =>
119
+ shouldSetPanResponder(gesture),
120
+ onPanResponderMove: (event, gesture) => {
121
+ this._animateMovement(gesture);
122
+ },
123
+ onPanResponderRelease: (event, gesture) => {
124
+ this._animateRelease(gesture);
125
+ }
126
+ });
127
+ }
128
+
129
+ componentDidMount() {
130
+ const noop = {
131
+ remove: () => {}
132
+ };
133
+ this.keyboardDidShowListener = isIOS
134
+ ? Keyboard.addListener('keyboardDidShow', this.keyboardDidShow)
135
+ : noop;
136
+ this.keyboardDidHideListner = isIOS
137
+ ? Keyboard.addListener('keyboardDidHide', this.keyboardDidHide)
138
+ : noop;
139
+ }
140
+
141
+ componentWillUnmount() {
142
+ this.keyboardDidShowListener.remove();
143
+ this.keyboardDidHideListner.remove();
144
+ clearTimeout(this.timer);
145
+ }
146
+
147
+ keyboardDidShow = (e) => {
148
+ const { isVisible, position } = this.state;
149
+ this.setState({
150
+ keyboardHeight: e.endCoordinates.height,
151
+ keyboardVisible: true
152
+ });
153
+
154
+ if (isVisible && position === 'bottom') {
155
+ this.animate({ toValue: 2 });
156
+ }
157
+ };
158
+
159
+ keyboardDidHide = () => {
160
+ const { isVisible, position } = this.state;
161
+ this.setState({
162
+ keyboardVisible: false
163
+ });
164
+ if (isVisible && position === 'bottom') {
165
+ this.animate({ toValue: 1 });
166
+ }
167
+ };
168
+
169
+ _setState(reducer) {
170
+ return new Promise((resolve) => this.setState(reducer, () => resolve()));
171
+ }
172
+
173
+ _animateMovement(gesture) {
174
+ const { position, animation, keyboardVisible } = this.state;
175
+ const { dy } = gesture;
176
+ let value = 1 + dy / 100;
177
+ const start = keyboardVisible && position === 'bottom' ? 2 : 1;
178
+
179
+ if (position === 'bottom') {
180
+ value = start - dy / 100;
181
+ }
182
+
183
+ if (value <= start) {
184
+ animation.setValue(value);
185
+ }
186
+ }
187
+
188
+ _animateRelease(gesture) {
189
+ const { position, animation, keyboardVisible } = this.state;
190
+ const { dy, vy } = gesture;
191
+
192
+ const isBottom = position === 'bottom';
193
+ let value = 1 + dy / 100;
194
+
195
+ if (isBottom) {
196
+ value = 1 - dy / 100;
197
+ }
198
+
199
+ const treshold = 0.65;
200
+ if (value <= treshold || Math.abs(vy) >= treshold) {
201
+ this.hide({
202
+ speed: Math.abs(vy) * 3
203
+ });
204
+ } else {
205
+ Animated.spring(animation, {
206
+ toValue: keyboardVisible && isBottom ? 2 : 1,
207
+ velocity: vy,
208
+ useNativeDriver: true
209
+ }).start();
210
+ }
211
+ }
212
+
213
+ async show(options = {}) {
214
+ const { inProgress, isVisible } = this.state;
215
+ if (inProgress || isVisible) {
216
+ await this.hide();
217
+ }
218
+
219
+ await this._setState((prevState) => ({
220
+ ...prevState,
221
+ ...getInitialState(this.props), // Reset layout
222
+ /*
223
+ Preserve the previously computed height (via onLayout).
224
+ If the height of the component corresponding to this `show` call is different,
225
+ onLayout will be called again and `height` state will adjust.
226
+
227
+ This fixes an issue where a succession of calls to components with custom heights (custom Toast types)
228
+ fails to hide them completely due to always resetting to the default component height
229
+ */
230
+ height: prevState.height,
231
+ inProgress: true,
232
+ ...options,
233
+ ...(options?.props ? { customProps: options.props } : { customProps: {} })
234
+ }));
235
+ await this.animateShow();
236
+ await this._setState((prevState) => ({
237
+ ...prevState,
238
+ isVisible: true,
239
+ inProgress: false
240
+ }));
241
+ this.clearTimer();
242
+
243
+ const { autoHide, onShow } = this.state;
244
+
245
+ if (autoHide) {
246
+ this.startTimer();
247
+ }
248
+
249
+ if (onShow) {
250
+ onShow();
251
+ }
252
+ }
253
+
254
+ async hide({ speed } = {}) {
255
+ await this._setState((prevState) => ({
256
+ ...prevState,
257
+ inProgress: true
258
+ }));
259
+ await this.animateHide({
260
+ speed
261
+ });
262
+ this.clearTimer();
263
+ await this._setState((prevState) => ({
264
+ ...prevState,
265
+ isVisible: false,
266
+ inProgress: false
267
+ }));
268
+
269
+ const { onHide } = this.state;
270
+ if (onHide) {
271
+ onHide();
272
+ }
273
+ }
274
+
275
+ animateShow = () => {
276
+ const { keyboardVisible, position } = this.state;
277
+ const toValue = keyboardVisible && position === 'bottom' ? 2 : 1;
278
+ return this.animate({ toValue });
279
+ };
280
+
281
+ animateHide({ speed } = {}) {
282
+ return this.animate({ toValue: 0, speed });
283
+ }
284
+
285
+ animate({ toValue, speed = 0 }) {
286
+ const { animation } = this.state;
287
+ return new Promise((resolve) => {
288
+ const config = {
289
+ toValue,
290
+ useNativeDriver: true,
291
+ ...(speed > 0 ? { speed } : { friction: FRICTION })
292
+ };
293
+ Animated.spring(animation, config).start(() => resolve());
294
+ });
295
+ }
296
+
297
+ startTimer() {
298
+ const { visibilityTime } = this.state;
299
+ this.timer = setTimeout(() => this.hide(), visibilityTime);
300
+ }
301
+
302
+ clearTimer() {
303
+ clearTimeout(this.timer);
304
+ this.timer = null;
305
+ }
306
+
307
+ renderContent({ config }) {
308
+ const componentsConfig = {
309
+ ...defaultComponentsConfig,
310
+ ...config
311
+ };
312
+
313
+ const { type, customProps } = this.state;
314
+ const toastComponent = componentsConfig[type];
315
+
316
+ if (!toastComponent) {
317
+ // eslint-disable-next-line no-console
318
+ console.error(
319
+ `Type '${type}' does not exist. Make sure to add it to your 'config'. You can read the documentation here: https://github.com/calintamas/react-native-toast-message/blob/master/README.md`
320
+ );
321
+ return null;
322
+ }
323
+
324
+ return toastComponent({
325
+ ...includeKeys({
326
+ obj: this.state,
327
+ keys: [
328
+ 'position',
329
+ 'type',
330
+ 'inProgress',
331
+ 'isVisible',
332
+ 'text1',
333
+ 'text2',
334
+ 'hide',
335
+ 'show',
336
+ 'onPress'
337
+ ]
338
+ }),
339
+ props: { ...customProps },
340
+ hide: this.hide,
341
+ show: this.show
342
+ });
343
+ }
344
+
345
+ getBaseStyle(position = 'bottom', keyboardHeight) {
346
+ const { topOffset, bottomOffset, keyboardOffset, height, animation } =
347
+ this.state;
348
+ const offset = position === 'bottom' ? bottomOffset : topOffset;
349
+
350
+ // +5 px to completely hide the toast under StatusBar (on Android)
351
+ const range = [height + 5, -offset, -(keyboardOffset + keyboardHeight)];
352
+ const outputRange = position === 'bottom' ? range : complement(range);
353
+
354
+ const translateY = animation.interpolate({
355
+ inputRange: [0, 1, 2],
356
+ outputRange: [0, 1, 0]
357
+ });
358
+
359
+ return [
360
+ styles.base,
361
+ styles[position],
362
+ {
363
+ opacity: translateY
364
+ }
365
+ ];
366
+ }
367
+
368
+ onLayout(e) {
369
+ this.setState({ height: e.nativeEvent.layout.height });
370
+ }
371
+
372
+ render() {
373
+ const { style } = this.props;
374
+ const { position, keyboardHeight } = this.state;
375
+ const baseStyle = this.getBaseStyle(position, keyboardHeight);
376
+
377
+ return (
378
+ <Animated.View
379
+ testID='animatedView'
380
+ onLayout={this.onLayout}
381
+ style={[
382
+ baseStyle,
383
+ style,
384
+ { zIndex: 100, display: this.state.isVisible ? 'flex' : 'none', backgroundColor:'red' }
385
+ ]} //added zindex
386
+ {...this.panResponder.panHandlers}>
387
+ {this.renderContent(this.props)}
388
+ </Animated.View>
389
+ );
390
+ }
391
+ }
392
+
393
+ Toast.propTypes = {
394
+ config: PropTypes.objectOf(PropTypes.func),
395
+ style: stylePropType,
396
+ topOffset: PropTypes.number,
397
+ bottomOffset: PropTypes.number,
398
+ keyboardOffset: PropTypes.number,
399
+ visibilityTime: PropTypes.number,
400
+ autoHide: PropTypes.bool,
401
+ height: PropTypes.number,
402
+ position: PropTypes.oneOf(['top', 'bottom']),
403
+ type: PropTypes.string
404
+ };
405
+
406
+ Toast.defaultProps = {
407
+ config: {},
408
+ style: undefined,
409
+ topOffset: 30,
410
+ bottomOffset: 40,
411
+ keyboardOffset: 15,
412
+ visibilityTime: 4000,
413
+ autoHide: true,
414
+ height: 60,
415
+ position: 'top',
416
+ type: 'success'
417
+ };
418
+
419
+ export default Toast;