@plusscommunities/pluss-core-app 8.0.1 → 8.0.2-auth.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 (320) hide show
  1. package/dist/module/actions/FollowerActions.js +4 -4
  2. package/dist/module/actions/FollowerActions.js.map +1 -1
  3. package/dist/module/actions/MediaActions.js +1 -1
  4. package/dist/module/actions/MediaActions.js.map +1 -1
  5. package/dist/module/actions/ResidentActions.js +1 -1
  6. package/dist/module/actions/ResidentActions.js.map +1 -1
  7. package/dist/module/actions/UserActions.js +1 -1
  8. package/dist/module/actions/UserActions.js.map +1 -1
  9. package/dist/module/actions/UserSettingsActions.js +1 -1
  10. package/dist/module/actions/UserSettingsActions.js.map +1 -1
  11. package/dist/module/actions/index.js +5 -5
  12. package/dist/module/actions/index.js.map +1 -1
  13. package/dist/module/actions/types.js +16 -16
  14. package/dist/module/actions/types.js.map +1 -1
  15. package/dist/module/apis/analyticsActions.js +5 -5
  16. package/dist/module/apis/analyticsActions.js.map +1 -1
  17. package/dist/module/apis/contactActions.js +6 -6
  18. package/dist/module/apis/contactActions.js.map +1 -1
  19. package/dist/module/apis/eventActions.js +28 -28
  20. package/dist/module/apis/eventActions.js.map +1 -1
  21. package/dist/module/apis/fileActions.js +15 -15
  22. package/dist/module/apis/fileActions.js.map +1 -1
  23. package/dist/module/apis/followerActions.js +8 -8
  24. package/dist/module/apis/followerActions.js.map +1 -1
  25. package/dist/module/apis/index.js +12 -12
  26. package/dist/module/apis/index.js.map +1 -1
  27. package/dist/module/apis/notificationActions.js +17 -17
  28. package/dist/module/apis/notificationActions.js.map +1 -1
  29. package/dist/module/apis/profileActions.js +4 -4
  30. package/dist/module/apis/profileActions.js.map +1 -1
  31. package/dist/module/apis/reactionActions.js +15 -15
  32. package/dist/module/apis/reactionActions.js.map +1 -1
  33. package/dist/module/apis/settingActions.js +6 -6
  34. package/dist/module/apis/settingActions.js.map +1 -1
  35. package/dist/module/apis/stringActions.js +8 -8
  36. package/dist/module/apis/stringActions.js.map +1 -1
  37. package/dist/module/apis/typeActions.js +4 -4
  38. package/dist/module/apis/typeActions.js.map +1 -1
  39. package/dist/module/apis/userActions.js +8 -8
  40. package/dist/module/apis/userActions.js.map +1 -1
  41. package/dist/module/assets/icons/fontawesome/fa-brands-400.ttf +0 -0
  42. package/dist/module/assets/icons/fontawesome/fa-light-300.ttf +0 -0
  43. package/dist/module/assets/icons/fontawesome/fa-regular-400.ttf +0 -0
  44. package/dist/module/assets/icons/fontawesome/fa-solid-900.ttf +0 -0
  45. package/dist/module/assets/icons/fontawesome/fa-thin-100.ttf +0 -0
  46. package/dist/module/assets/icons/fontawesome/fa7-glyphmap.json +4205 -0
  47. package/dist/module/colours.js +26 -29
  48. package/dist/module/colours.js.map +1 -1
  49. package/dist/module/components/AddButton.js +8 -8
  50. package/dist/module/components/AddButton.js.map +1 -1
  51. package/dist/module/components/AddToCalendarButton.js +30 -29
  52. package/dist/module/components/AddToCalendarButton.js.map +1 -1
  53. package/dist/module/components/Attachment.js +10 -9
  54. package/dist/module/components/Attachment.js.map +1 -1
  55. package/dist/module/components/AudienceSelectorLauncher.js +11 -11
  56. package/dist/module/components/AudienceSelectorLauncher.js.map +1 -1
  57. package/dist/module/components/AudienceSelectorPage.js +45 -44
  58. package/dist/module/components/AudienceSelectorPage.js.map +1 -1
  59. package/dist/module/components/AutoOffsetImage.js +13 -13
  60. package/dist/module/components/AutoOffsetImage.js.map +1 -1
  61. package/dist/module/components/BackButton.js +10 -10
  62. package/dist/module/components/BackButton.js.map +1 -1
  63. package/dist/module/components/CalendarPopup.js +21 -21
  64. package/dist/module/components/CalendarPopup.js.map +1 -1
  65. package/dist/module/components/CategoryTabs.js +30 -29
  66. package/dist/module/components/CategoryTabs.js.map +1 -1
  67. package/dist/module/components/CommentReply.js +43 -37
  68. package/dist/module/components/CommentReply.js.map +1 -1
  69. package/dist/module/components/CommentSection.js +74 -74
  70. package/dist/module/components/CommentSection.js.map +1 -1
  71. package/dist/module/components/ConfirmPopup.js +21 -20
  72. package/dist/module/components/ConfirmPopup.js.map +1 -1
  73. package/dist/module/components/ConfirmationPopup.js +11 -11
  74. package/dist/module/components/ConfirmationPopup.js.map +1 -1
  75. package/dist/module/components/DocumentUploader.js +50 -50
  76. package/dist/module/components/DocumentUploader.js.map +1 -1
  77. package/dist/module/components/DropDownItem.js +14 -13
  78. package/dist/module/components/DropDownItem.js.map +1 -1
  79. package/dist/module/components/DropDownMenu.js +5 -5
  80. package/dist/module/components/DropDownMenu.js.map +1 -1
  81. package/dist/module/components/EmptyStateMain.js +10 -9
  82. package/dist/module/components/EmptyStateMain.js.map +1 -1
  83. package/dist/module/components/EmptyStateWidget.js +7 -6
  84. package/dist/module/components/EmptyStateWidget.js.map +1 -1
  85. package/dist/module/components/FontScaleButton.js +5 -4
  86. package/dist/module/components/FontScaleButton.js.map +1 -1
  87. package/dist/module/components/FontScalePopup.js +11 -10
  88. package/dist/module/components/FontScalePopup.js.map +1 -1
  89. package/dist/module/components/Forbidden.js +13 -13
  90. package/dist/module/components/Forbidden.js.map +1 -1
  91. package/dist/module/components/FormCard.js +4 -4
  92. package/dist/module/components/FormCard.js.map +1 -1
  93. package/dist/module/components/FormCardSection.js +20 -18
  94. package/dist/module/components/FormCardSection.js.map +1 -1
  95. package/dist/module/components/FormCardSectionOptionLauncher.js +13 -12
  96. package/dist/module/components/FormCardSectionOptionLauncher.js.map +1 -1
  97. package/dist/module/components/FormattedText.js +18 -16
  98. package/dist/module/components/FormattedText.js.map +1 -1
  99. package/dist/module/components/GenericInput.js +24 -21
  100. package/dist/module/components/GenericInput.js.map +1 -1
  101. package/dist/module/components/GenericInputSection.js +27 -26
  102. package/dist/module/components/GenericInputSection.js.map +1 -1
  103. package/dist/module/components/Header.js +70 -69
  104. package/dist/module/components/Header.js.map +1 -1
  105. package/dist/module/components/Icon.js +109 -0
  106. package/dist/module/components/Icon.js.map +1 -0
  107. package/dist/module/components/ImagePopup.js +211 -73
  108. package/dist/module/components/ImagePopup.js.map +1 -1
  109. package/dist/module/components/ImageUploadProgress.js +10 -9
  110. package/dist/module/components/ImageUploadProgress.js.map +1 -1
  111. package/dist/module/components/ImageUploader.js +122 -97
  112. package/dist/module/components/ImageUploader.js.map +1 -1
  113. package/dist/module/components/InlineButton.js +9 -8
  114. package/dist/module/components/InlineButton.js.map +1 -1
  115. package/dist/module/components/Input.js +28 -26
  116. package/dist/module/components/Input.js.map +1 -1
  117. package/dist/module/components/LoadingCircles.js +20 -20
  118. package/dist/module/components/LoadingCircles.js.map +1 -1
  119. package/dist/module/components/LoadingIndicator.js +11 -11
  120. package/dist/module/components/LoadingIndicator.js.map +1 -1
  121. package/dist/module/components/LoadingStateWidget.js +5 -5
  122. package/dist/module/components/LoadingStateWidget.js.map +1 -1
  123. package/dist/module/components/MediaPlayer.js +31 -31
  124. package/dist/module/components/MediaPlayer.js.map +1 -1
  125. package/dist/module/components/MiddlePopup.js +17 -11
  126. package/dist/module/components/MiddlePopup.js.map +1 -1
  127. package/dist/module/components/PDFPopup.js +152 -46
  128. package/dist/module/components/PDFPopup.js.map +1 -1
  129. package/dist/module/components/PlussChat.js +168 -149
  130. package/dist/module/components/PlussChat.js.map +1 -1
  131. package/dist/module/components/PlussChatMessage.js +42 -42
  132. package/dist/module/components/PlussChatMessage.js.map +1 -1
  133. package/dist/module/components/PlussChatTime.js +18 -17
  134. package/dist/module/components/PlussChatTime.js.map +1 -1
  135. package/dist/module/components/Popup.js +20 -19
  136. package/dist/module/components/Popup.js.map +1 -1
  137. package/dist/module/components/PopupMenu.js +15 -14
  138. package/dist/module/components/PopupMenu.js.map +1 -1
  139. package/dist/module/components/PositionedImage.js +20 -20
  140. package/dist/module/components/PositionedImage.js.map +1 -1
  141. package/dist/module/components/ProfilePic.js +10 -10
  142. package/dist/module/components/ProfilePic.js.map +1 -1
  143. package/dist/module/components/RadioButton.js +10 -9
  144. package/dist/module/components/RadioButton.js.map +1 -1
  145. package/dist/module/components/Reaction.js +18 -17
  146. package/dist/module/components/Reaction.js.map +1 -1
  147. package/dist/module/components/Reactions.js +7 -7
  148. package/dist/module/components/Reactions.js.map +1 -1
  149. package/dist/module/components/SharingTools.js +78 -43
  150. package/dist/module/components/SharingTools.js.map +1 -1
  151. package/dist/module/components/Spinner.js +5 -5
  152. package/dist/module/components/Spinner.js.map +1 -1
  153. package/dist/module/components/StickyFooter.js +6 -6
  154. package/dist/module/components/StickyFooter.js.map +1 -1
  155. package/dist/module/components/Text.js +57 -0
  156. package/dist/module/components/Text.js.map +1 -0
  157. package/dist/module/components/TickIcon.js +6 -6
  158. package/dist/module/components/TickIcon.js.map +1 -1
  159. package/dist/module/components/Toggle.js +10 -9
  160. package/dist/module/components/Toggle.js.map +1 -1
  161. package/dist/module/components/TouchableSearchBar.js +18 -17
  162. package/dist/module/components/TouchableSearchBar.js.map +1 -1
  163. package/dist/module/components/UserListPopup.js +20 -19
  164. package/dist/module/components/UserListPopup.js.map +1 -1
  165. package/dist/module/components/UserListing.js +41 -40
  166. package/dist/module/components/UserListing.js.map +1 -1
  167. package/dist/module/components/VideoPopup.js +20 -20
  168. package/dist/module/components/VideoPopup.js.map +1 -1
  169. package/dist/module/components/WarningPopup.js +21 -20
  170. package/dist/module/components/WarningPopup.js.map +1 -1
  171. package/dist/module/components/expo-image-picker-multiple/ImageBrowser.js +13 -13
  172. package/dist/module/components/expo-image-picker-multiple/ImageBrowser.js.map +1 -1
  173. package/dist/module/components/expo-image-picker-multiple/ImageTile.js +24 -23
  174. package/dist/module/components/expo-image-picker-multiple/ImageTile.js.map +1 -1
  175. package/dist/module/components/index.js +59 -58
  176. package/dist/module/components/index.js.map +1 -1
  177. package/dist/module/components/react-native-expo-image-cropper/ExpoImageManipulator.js +113 -76
  178. package/dist/module/components/react-native-expo-image-cropper/ExpoImageManipulator.js.map +1 -1
  179. package/dist/module/components/react-native-expo-image-cropper/ImageCropOverlay.js +64 -64
  180. package/dist/module/components/react-native-expo-image-cropper/ImageCropOverlay.js.map +1 -1
  181. package/dist/module/config.js +15 -10
  182. package/dist/module/config.js.map +1 -1
  183. package/dist/module/constants.js +3 -4
  184. package/dist/module/constants.js.map +1 -1
  185. package/dist/module/helper.js +83 -82
  186. package/dist/module/helper.js.map +1 -1
  187. package/dist/module/index.js +12 -12
  188. package/dist/module/index.js.map +1 -1
  189. package/dist/module/js/images/detectFaces.js +11 -10
  190. package/dist/module/js/images/detectFaces.js.map +1 -1
  191. package/dist/module/js/images/findLandmarkRange.js +8 -8
  192. package/dist/module/js/images/findLandmarkRange.js.map +1 -1
  193. package/dist/module/js/images/getScaledOffset.js.map +1 -1
  194. package/dist/module/js/site/getSiteLevelFromState.js +2 -2
  195. package/dist/module/js/site/getSiteLevelFromState.js.map +1 -1
  196. package/dist/module/js/site/isTVEnabled.js +2 -2
  197. package/dist/module/js/site/isTVEnabled.js.map +1 -1
  198. package/dist/module/session.js +6 -6
  199. package/dist/module/session.js.map +1 -1
  200. package/dist/module/styles.js +17 -17
  201. package/dist/module/styles.js.map +1 -1
  202. package/dist/module/withNavigationFocus.js +30 -0
  203. package/dist/module/withNavigationFocus.js.map +1 -0
  204. package/package.json +81 -68
  205. package/src/actions/FollowerActions.js +36 -32
  206. package/src/actions/MediaActions.js +25 -20
  207. package/src/actions/ResidentActions.js +26 -21
  208. package/src/actions/UserActions.js +22 -22
  209. package/src/actions/UserSettingsActions.js +11 -11
  210. package/src/actions/index.js +5 -5
  211. package/src/actions/types.js +16 -16
  212. package/src/apis/analyticsActions.js +17 -17
  213. package/src/apis/contactActions.js +20 -20
  214. package/src/apis/eventActions.js +153 -144
  215. package/src/apis/fileActions.js +96 -86
  216. package/src/apis/followerActions.js +29 -29
  217. package/src/apis/index.js +12 -12
  218. package/src/apis/notificationActions.js +44 -44
  219. package/src/apis/profileActions.js +8 -8
  220. package/src/apis/reactionActions.js +81 -73
  221. package/src/apis/settingActions.js +15 -15
  222. package/src/apis/stringActions.js +29 -25
  223. package/src/apis/typeActions.js +10 -10
  224. package/src/apis/userActions.js +93 -93
  225. package/src/assets/icons/fontawesome/fa-brands-400.ttf +0 -0
  226. package/src/assets/icons/fontawesome/fa-light-300.ttf +0 -0
  227. package/src/assets/icons/fontawesome/fa-regular-400.ttf +0 -0
  228. package/src/assets/icons/fontawesome/fa-solid-900.ttf +0 -0
  229. package/src/assets/icons/fontawesome/fa-thin-100.ttf +0 -0
  230. package/src/assets/icons/fontawesome/fa7-glyphmap.json +4205 -0
  231. package/src/colours.js +116 -96
  232. package/src/components/AddButton.js +32 -27
  233. package/src/components/AddToCalendarButton.js +236 -202
  234. package/src/components/Attachment.js +59 -36
  235. package/src/components/AudienceSelectorLauncher.js +52 -48
  236. package/src/components/AudienceSelectorPage.js +353 -311
  237. package/src/components/AutoOffsetImage.js +237 -196
  238. package/src/components/BackButton.js +57 -41
  239. package/src/components/CalendarPopup.js +127 -97
  240. package/src/components/CategoryTabs.js +208 -163
  241. package/src/components/CommentReply.js +370 -309
  242. package/src/components/CommentSection.js +974 -781
  243. package/src/components/ConfirmPopup.js +141 -110
  244. package/src/components/ConfirmationPopup.js +80 -69
  245. package/src/components/DocumentUploader.js +245 -215
  246. package/src/components/DropDownItem.js +70 -60
  247. package/src/components/DropDownMenu.js +31 -27
  248. package/src/components/EmptyStateMain.js +51 -44
  249. package/src/components/EmptyStateWidget.js +47 -38
  250. package/src/components/FontScaleButton.js +29 -25
  251. package/src/components/FontScalePopup.js +67 -56
  252. package/src/components/Forbidden.js +48 -46
  253. package/src/components/FormCard.js +21 -17
  254. package/src/components/FormCardSection.js +284 -233
  255. package/src/components/FormCardSectionOptionLauncher.js +72 -46
  256. package/src/components/FormattedText.js +128 -111
  257. package/src/components/GenericInput.js +168 -136
  258. package/src/components/GenericInputSection.js +209 -161
  259. package/src/components/Header.js +620 -474
  260. package/src/components/Icon.js +119 -0
  261. package/src/components/ImagePopup.js +425 -221
  262. package/src/components/ImageUploadProgress.js +49 -41
  263. package/src/components/ImageUploader.js +973 -797
  264. package/src/components/InlineButton.js +79 -69
  265. package/src/components/Input.js +190 -156
  266. package/src/components/LoadingCircles.js +233 -233
  267. package/src/components/LoadingIndicator.js +87 -76
  268. package/src/components/LoadingStateWidget.js +47 -37
  269. package/src/components/MediaPlayer.js +416 -387
  270. package/src/components/MiddlePopup.js +62 -33
  271. package/src/components/PDFPopup.js +307 -159
  272. package/src/components/PlussChat.js +1224 -1025
  273. package/src/components/PlussChatMessage.js +329 -298
  274. package/src/components/PlussChatTime.js +57 -53
  275. package/src/components/Popup.js +138 -116
  276. package/src/components/PopupMenu.js +140 -110
  277. package/src/components/PositionedImage.js +281 -237
  278. package/src/components/ProfilePic.js +122 -113
  279. package/src/components/RadioButton.js +76 -52
  280. package/src/components/Reaction.js +134 -96
  281. package/src/components/Reactions.js +65 -63
  282. package/src/components/SharingTools.js +185 -134
  283. package/src/components/Spinner.js +13 -13
  284. package/src/components/StickyFooter.js +36 -26
  285. package/src/components/Text.js +62 -0
  286. package/src/components/TickIcon.js +20 -20
  287. package/src/components/Toggle.js +74 -73
  288. package/src/components/TouchableSearchBar.js +68 -50
  289. package/src/components/UserListPopup.js +161 -124
  290. package/src/components/UserListing.js +273 -238
  291. package/src/components/VideoPopup.js +110 -96
  292. package/src/components/WarningPopup.js +92 -71
  293. package/src/components/expo-image-picker-multiple/ImageBrowser.js +288 -256
  294. package/src/components/expo-image-picker-multiple/ImageTile.js +108 -84
  295. package/src/components/index.js +59 -58
  296. package/src/components/react-native-expo-image-cropper/ExpoImageManipulator.js +447 -359
  297. package/src/components/react-native-expo-image-cropper/ImageCropOverlay.js +420 -324
  298. package/src/config.js +26 -21
  299. package/src/constants.js +8 -10
  300. package/src/helper.js +469 -438
  301. package/src/index.js +24 -12
  302. package/src/js/images/detectFaces.js +28 -21
  303. package/src/js/images/findLandmarkRange.js +97 -90
  304. package/src/js/images/getScaledOffset.js +80 -75
  305. package/src/js/site/getSiteLevelFromState.js +26 -26
  306. package/src/js/site/isTVEnabled.js +10 -10
  307. package/src/session.js +32 -32
  308. package/src/styles.js +61 -61
  309. package/src/withNavigationFocus.js +28 -0
  310. package/dist/module/components/TextStyle.js +0 -45
  311. package/dist/module/components/TextStyle.js.map +0 -1
  312. package/dist/module/fonts/index.js +0 -2
  313. package/dist/module/fonts/index.js.map +0 -1
  314. package/dist/module/fonts/pluss60-icons.js +0 -5
  315. package/dist/module/fonts/pluss60-icons.js.map +0 -1
  316. package/dist/module/fonts/pluss60-icons.json +0 -1097
  317. package/src/components/TextStyle.js +0 -48
  318. package/src/fonts/index.js +0 -1
  319. package/src/fonts/pluss60-icons.js +0 -7
  320. package/src/fonts/pluss60-icons.json +0 -1097
@@ -1,40 +1,69 @@
1
- import React, { PureComponent } from 'react';
2
- import { View, Modal, TouchableWithoutFeedback, KeyboardAvoidingView, Platform } from 'react-native';
1
+ import React, { PureComponent } from "react";
2
+ import {
3
+ View,
4
+ Modal,
5
+ TouchableWithoutFeedback,
6
+ KeyboardAvoidingView,
7
+ Platform,
8
+ } from "react-native";
9
+ import { withSafeAreaInsets } from "react-native-safe-area-context";
3
10
 
4
11
  class MiddlePopup extends PureComponent {
5
- render() {
6
- return (
7
- <Modal visible={this.props.visible} transparent animationType="fade" onRequestClose={this.props.onClose}>
8
- <KeyboardAvoidingView behavior={this.props.keyboardAvoid && Platform.OS === 'ios' && 'padding'} style={styles.popup}>
9
- <TouchableWithoutFeedback onPress={this.props.onClose}>
10
- <View style={styles.popupOverlay} />
11
- </TouchableWithoutFeedback>
12
- <View style={[styles.popupContent, this.props.style]}>{this.props.children}</View>
13
- </KeyboardAvoidingView>
14
- </Modal>
15
- );
16
- }
12
+ render() {
13
+ const bottom =
14
+ Platform.OS === "android" ? (this.props.insets?.bottom ?? 0) : 0;
15
+
16
+ return (
17
+ <Modal
18
+ visible={this.props.visible}
19
+ transparent
20
+ animationType="fade"
21
+ onRequestClose={this.props.onClose}
22
+ >
23
+ <KeyboardAvoidingView
24
+ behavior={
25
+ this.props.keyboardAvoid && Platform.OS === "ios" && "padding"
26
+ }
27
+ style={styles.popup}
28
+ >
29
+ <TouchableWithoutFeedback onPress={this.props.onClose}>
30
+ <View style={styles.popupOverlay} />
31
+ </TouchableWithoutFeedback>
32
+ <View
33
+ style={[
34
+ styles.popupContent,
35
+ this.props.style,
36
+ bottom > 0 && { paddingBottom: bottom },
37
+ ]}
38
+ >
39
+ {this.props.children}
40
+ </View>
41
+ </KeyboardAvoidingView>
42
+ </Modal>
43
+ );
44
+ }
17
45
  }
18
46
 
19
47
  const styles = {
20
- popup: {
21
- flex: 1,
22
- justifyContent: 'center',
23
- alignItems: 'center',
24
- },
25
- popupOverlay: {
26
- position: 'absolute',
27
- backgroundColor: 'rgba(19, 19, 26, .25)',
28
- top: 0,
29
- left: 0,
30
- right: 0,
31
- bottom: 0,
32
- },
33
- popupContent: {
34
- borderRadius: 12,
35
- backgroundColor: '#fff',
36
- alignItems: 'center',
37
- },
48
+ popup: {
49
+ flex: 1,
50
+ justifyContent: "center",
51
+ alignItems: "center",
52
+ },
53
+ popupOverlay: {
54
+ position: "absolute",
55
+ backgroundColor: "rgba(19, 19, 26, .25)",
56
+ top: 0,
57
+ left: 0,
58
+ right: 0,
59
+ bottom: 0,
60
+ },
61
+ popupContent: {
62
+ borderRadius: 12,
63
+ backgroundColor: "#fff",
64
+ alignItems: "center",
65
+ },
38
66
  };
39
67
 
40
- export { MiddlePopup };
68
+ const MiddlePopupWithInsets = withSafeAreaInsets(MiddlePopup);
69
+ export { MiddlePopupWithInsets as MiddlePopup };
@@ -1,176 +1,324 @@
1
- import React, { Component } from 'react';
2
- import { View, Text, TouchableOpacity, Modal, Dimensions } from 'react-native';
3
- import { Icon } from '@rneui/themed';
4
- import { WebView } from 'react-native-webview';
5
- import * as FileSystem from 'expo-file-system';
6
- import * as Sharing from 'expo-sharing';
7
- import { Pl60Icon } from '../fonts';
8
- import { Spinner } from './Spinner';
9
- import { StatusBarHeight, getFileName } from '../helper';
1
+ import { Icon } from "@rneui/themed";
2
+ import { File, Paths } from "expo-file-system";
3
+ import * as Sharing from "expo-sharing";
4
+ import { Component } from "react";
5
+ import { Alert, Dimensions, Modal, TouchableOpacity, View } from "react-native";
6
+ import { WebView } from "react-native-webview";
7
+ import { TEXT_DARK, TEXT_LIGHT } from "../colours";
8
+ import { getFileName, StatusBarHeight } from "../helper";
9
+ import { FontAwesome } from "./Icon";
10
+ import { Spinner } from "./Spinner";
11
+ import { Text } from "./Text";
10
12
 
11
- const SCREEN_HEIGHT = Dimensions.get('window').height;
13
+ const SCREEN_HEIGHT = Dimensions.get("window").height;
12
14
 
13
15
  class PDFPopup extends Component {
14
- state = {
15
- loaded: false,
16
- };
16
+ state = {
17
+ loaded: false,
18
+ error: false,
19
+ };
17
20
 
18
- onLoadStarted() {
19
- this.setState({
20
- loaded: false,
21
- });
22
- }
21
+ componentDidUpdate(prevProps) {
22
+ const sourceChanged = prevProps.source !== this.props.source;
23
+ const becameVisible = !prevProps.visible && this.props.visible;
24
+ if (sourceChanged || becameVisible) {
25
+ // Popup is reused across attachments — clear stale state so the
26
+ // spinner reappears and any prior error from a different PDF resets.
27
+ clearTimeout(this._loadTimeout);
28
+ this._loadTimeout = null;
29
+ this.setState({ loaded: false, error: false });
30
+ }
31
+ }
23
32
 
24
- onLoadEnded() {
25
- this.setState({
26
- loaded: true,
27
- });
28
- }
33
+ componentWillUnmount() {
34
+ clearTimeout(this._loadTimeout);
35
+ this._loadTimeout = null;
36
+ }
29
37
 
30
- onChangeIndex(index) {
31
- this.props.onChangeIndex(index);
32
- }
38
+ onLoadStarted() {
39
+ this.setState({
40
+ loaded: false,
41
+ error: false,
42
+ });
43
+ clearTimeout(this._loadTimeout);
44
+ this._loadTimeout = setTimeout(() => {
45
+ this.setState({ error: true });
46
+ }, 15000);
47
+ }
33
48
 
34
- getUrl() {
35
- const linkPrefix = 'http://drive.google.com/viewerng/viewer?embedded=true&url=';
36
- return `${linkPrefix}${this.props.source}`;
37
- }
49
+ onLoadEnded() {
50
+ clearTimeout(this._loadTimeout);
51
+ this._loadTimeout = null;
52
+ this.setState({
53
+ loaded: true,
54
+ });
55
+ }
38
56
 
39
- download = async () => {
40
- const downloadedFile = await FileSystem.downloadAsync(this.props.source, FileSystem.documentDirectory + getFileName(this.props.source));
41
- const shareResult = await Sharing.shareAsync(downloadedFile.uri, { UTI: 'public.item' });
42
- };
57
+ onChangeIndex(index) {
58
+ this.props.onChangeIndex(index);
59
+ }
43
60
 
44
- closePopup() {
45
- this.props.onClose();
46
- }
61
+ getUrl() {
62
+ if (!this.props.source) {
63
+ return "";
64
+ }
65
+ const linkPrefix =
66
+ "https://drive.google.com/viewerng/viewer?embedded=true&url=";
67
+ return `${linkPrefix}${encodeURIComponent(this.props.source)}`;
68
+ }
47
69
 
48
- renderFooter() {
49
- if (this.props.pdfCount && this.props.pdfCount === 1) {
50
- return null;
51
- }
52
- return (
53
- <View style={styles.footerContent}>
54
- <TouchableOpacity onPress={this.onChangeIndex.bind(this, -1)} activeOpacity={0.6}>
55
- <Icon type="font-awesome" name="angle-left" iconStyle={[styles.chevron]} />
56
- </TouchableOpacity>
57
- <Text style={styles.footerText}>
58
- {this.props.selectedIndex + 1} / {this.props.pdfCount}
59
- </Text>
60
- <TouchableOpacity onPress={this.onChangeIndex.bind(this, 1)} activeOpacity={0.6}>
61
- <Icon type="font-awesome" name="angle-right" iconStyle={[styles.chevron]} />
62
- </TouchableOpacity>
63
- </View>
64
- );
65
- }
70
+ download = async () => {
71
+ try {
72
+ const file = await File.downloadFileAsync(
73
+ this.props.source,
74
+ new File(Paths.document, getFileName(this.props.source)),
75
+ { idempotent: true },
76
+ );
77
+ await Sharing.shareAsync(file.uri, {
78
+ UTI: "public.item",
79
+ });
80
+ } catch (error) {
81
+ console.log("PDFPopup download error:", error);
82
+ Alert.alert(
83
+ "Download Failed",
84
+ "Unable to download PDF. Please try again.",
85
+ [{ text: "OK" }],
86
+ );
87
+ }
88
+ };
66
89
 
67
- render() {
68
- if (!this.props.source) {
69
- return null;
70
- }
71
- return (
72
- <Modal visible={this.props.visible} transparent animationType="slide" onRequestClose={this.closePopup.bind(this)}>
73
- <View
74
- style={{
75
- flex: 1,
76
- backgroundColor: '#000',
77
- paddingTop: StatusBarHeight(0),
78
- }}
79
- >
80
- <View style={styles.headerContent}>
81
- <TouchableOpacity onPress={this.closePopup.bind(this)} activeOpacity={0.6}>
82
- <Pl60Icon name="close" style={[styles.menuIcon]} />
83
- </TouchableOpacity>
84
- <View style={styles.titleContainer}>
85
- <Text style={styles.title}>{this.props.title}</Text>
86
- </View>
87
- <TouchableOpacity onPress={this.download} activeOpacity={0.6}>
88
- <Icon type="font-awesome" name="cloud-download" iconStyle={[styles.menuIcon]} />
89
- </TouchableOpacity>
90
- </View>
91
- <View style={{ flex: 1, backgroundColor: '#fff' }}>
92
- {this.state.loaded ? null : <Spinner style={{ height: SCREEN_HEIGHT - StatusBarHeight(145), flex: 0 }} />}
93
- <WebView
94
- ref="PDFWebView"
95
- source={{
96
- uri: this.getUrl(),
97
- }}
98
- renderError={e => {
99
- console.log('errored');
100
- console.log(e);
101
- }}
102
- style={[
103
- {
104
- flex: 1,
105
- backgroundColor: '#fff',
106
- },
107
- ]}
108
- onLoadStart={this.onLoadStarted.bind(this)}
109
- onLoadEnd={this.onLoadEnded.bind(this)}
110
- />
111
- </View>
112
- {this.renderFooter()}
113
- </View>
114
- </Modal>
115
- );
116
- }
90
+ closePopup() {
91
+ this.props.onClose();
92
+ }
93
+
94
+ renderFooter() {
95
+ if (this.props.pdfCount && this.props.pdfCount === 1) {
96
+ return null;
97
+ }
98
+ return (
99
+ <View style={styles.footerContent}>
100
+ <TouchableOpacity
101
+ onPress={this.onChangeIndex.bind(this, -1)}
102
+ activeOpacity={0.6}
103
+ >
104
+ <Icon
105
+ type="font-awesome"
106
+ name="angle-left"
107
+ iconStyle={[styles.chevron]}
108
+ />
109
+ </TouchableOpacity>
110
+ <Text style={styles.footerText}>
111
+ {this.props.selectedIndex + 1} / {this.props.pdfCount}
112
+ </Text>
113
+ <TouchableOpacity
114
+ onPress={this.onChangeIndex.bind(this, 1)}
115
+ activeOpacity={0.6}
116
+ >
117
+ <Icon
118
+ type="font-awesome"
119
+ name="angle-right"
120
+ iconStyle={[styles.chevron]}
121
+ />
122
+ </TouchableOpacity>
123
+ </View>
124
+ );
125
+ }
126
+
127
+ render() {
128
+ if (!this.props.source) {
129
+ return null;
130
+ }
131
+ return (
132
+ <Modal
133
+ visible={this.props.visible}
134
+ transparent
135
+ animationType="slide"
136
+ onRequestClose={this.closePopup.bind(this)}
137
+ >
138
+ <View
139
+ style={{
140
+ flex: 1,
141
+ backgroundColor: "#000",
142
+ paddingTop: StatusBarHeight(0),
143
+ }}
144
+ >
145
+ <View style={styles.headerContent}>
146
+ <TouchableOpacity
147
+ onPress={this.closePopup.bind(this)}
148
+ activeOpacity={0.6}
149
+ >
150
+ <FontAwesome name="x" style={[styles.menuIcon]} />
151
+ </TouchableOpacity>
152
+ <View style={styles.titleContainer}>
153
+ <Text style={styles.title}>{this.props.title}</Text>
154
+ </View>
155
+ <TouchableOpacity onPress={this.download} activeOpacity={0.6}>
156
+ <Icon
157
+ type="font-awesome"
158
+ name="cloud-download"
159
+ iconStyle={[styles.menuIcon]}
160
+ />
161
+ </TouchableOpacity>
162
+ </View>
163
+ <View style={{ flex: 1, backgroundColor: "#fff" }}>
164
+ {this.state.error ? (
165
+ <View style={styles.errorContainer}>
166
+ <Text style={styles.errorTitle}>Unable to load this PDF.</Text>
167
+ <Text style={styles.errorSubtitle}>
168
+ Try downloading it instead.
169
+ </Text>
170
+ <TouchableOpacity
171
+ onPress={this.download}
172
+ activeOpacity={0.6}
173
+ style={styles.errorDownloadButton}
174
+ >
175
+ <Icon
176
+ type="font-awesome"
177
+ name="cloud-download"
178
+ iconStyle={styles.errorDownloadIcon}
179
+ />
180
+ <Text style={styles.errorDownloadText}>Download PDF</Text>
181
+ </TouchableOpacity>
182
+ </View>
183
+ ) : (
184
+ <>
185
+ {this.state.loaded ? null : (
186
+ <Spinner
187
+ style={{
188
+ height: SCREEN_HEIGHT - StatusBarHeight(145),
189
+ flex: 0,
190
+ }}
191
+ />
192
+ )}
193
+ <WebView
194
+ source={{
195
+ uri: this.getUrl(),
196
+ }}
197
+ javaScriptEnabled
198
+ domStorageEnabled
199
+ originWhitelist={["*"]}
200
+ renderError={() => {
201
+ // Surface error UI in the parent View rather than the
202
+ // default WebView error chrome. Defer setState to avoid
203
+ // triggering a state update during another render.
204
+ if (!this.state.error) {
205
+ setTimeout(() => this.setState({ error: true }), 0);
206
+ }
207
+ return null;
208
+ }}
209
+ style={[
210
+ {
211
+ flex: 1,
212
+ backgroundColor: "#fff",
213
+ },
214
+ ]}
215
+ onLoadStart={this.onLoadStarted.bind(this)}
216
+ onLoadEnd={this.onLoadEnded.bind(this)}
217
+ />
218
+ </>
219
+ )}
220
+ </View>
221
+ {this.renderFooter()}
222
+ </View>
223
+ </Modal>
224
+ );
225
+ }
117
226
  }
118
227
 
119
228
  const styles = {
120
- container: {
121
- flex: 1,
122
- position: 'relative',
123
- backgroundColor: '#000',
124
- },
125
- innerContainer: {
126
- flex: 1,
127
- paddingLeft: 15,
128
- paddingRight: 15,
129
- },
130
- menuIcon: {
131
- fontSize: 25,
132
- padding: 15,
133
- width: 55,
134
- textAlign: 'center',
135
- color: '#fff',
136
- zIndex: 3,
137
- },
138
- headerContent: {
139
- flexDirection: 'row',
140
- alignItems: 'center',
141
- height: 70,
142
- },
143
- titleContainer: {
144
- flex: 1,
145
- },
146
- title: {
147
- color: '#fff',
148
- fontFamily: 'sf-semibold',
149
- fontSize: 16,
150
- textAlign: 'center',
151
- },
152
- footerContent: {
153
- flexDirection: 'row',
154
- alignItems: 'center',
155
- justifyContent: 'center',
156
- height: 70,
157
- //alignSelf: 'flex-end'
158
- },
159
- chevron: {
160
- fontSize: 25,
161
- padding: 15,
162
- width: 55,
163
- textAlign: 'center',
164
- color: '#fff',
165
- zIndex: 3,
166
- },
167
- footerText: {
168
- fontFamily: 'sf-regular',
169
- fontSize: 14,
170
- color: '#fff',
171
- width: 150,
172
- textAlign: 'center',
173
- },
229
+ container: {
230
+ flex: 1,
231
+ position: "relative",
232
+ backgroundColor: "#000",
233
+ },
234
+ innerContainer: {
235
+ flex: 1,
236
+ paddingLeft: 15,
237
+ paddingRight: 15,
238
+ },
239
+ menuIcon: {
240
+ fontSize: 25,
241
+ padding: 15,
242
+ width: 55,
243
+ textAlign: "center",
244
+ color: "#fff",
245
+ zIndex: 3,
246
+ },
247
+ headerContent: {
248
+ flexDirection: "row",
249
+ alignItems: "center",
250
+ height: 70,
251
+ },
252
+ titleContainer: {
253
+ flex: 1,
254
+ },
255
+ title: {
256
+ color: "#fff",
257
+ fontFamily: "sf-semibold",
258
+ fontSize: 16,
259
+ textAlign: "center",
260
+ },
261
+ footerContent: {
262
+ flexDirection: "row",
263
+ alignItems: "center",
264
+ justifyContent: "center",
265
+ height: 70,
266
+ //alignSelf: 'flex-end'
267
+ },
268
+ chevron: {
269
+ fontSize: 25,
270
+ padding: 15,
271
+ width: 55,
272
+ textAlign: "center",
273
+ color: "#fff",
274
+ zIndex: 3,
275
+ },
276
+ footerText: {
277
+ fontFamily: "sf-regular",
278
+ fontSize: 14,
279
+ color: "#fff",
280
+ width: 150,
281
+ textAlign: "center",
282
+ },
283
+ errorContainer: {
284
+ flex: 1,
285
+ alignItems: "center",
286
+ justifyContent: "center",
287
+ paddingHorizontal: 32,
288
+ paddingVertical: 24,
289
+ backgroundColor: "#fff",
290
+ },
291
+ errorTitle: {
292
+ fontFamily: "sf-semibold",
293
+ fontSize: 18,
294
+ color: TEXT_DARK,
295
+ textAlign: "center",
296
+ },
297
+ errorSubtitle: {
298
+ fontFamily: "sf-regular",
299
+ fontSize: 14,
300
+ color: TEXT_LIGHT,
301
+ textAlign: "center",
302
+ marginTop: 8,
303
+ },
304
+ errorDownloadButton: {
305
+ flexDirection: "row",
306
+ alignItems: "center",
307
+ justifyContent: "center",
308
+ marginTop: 24,
309
+ paddingHorizontal: 20,
310
+ paddingVertical: 12,
311
+ },
312
+ errorDownloadIcon: {
313
+ fontSize: 20,
314
+ color: TEXT_DARK,
315
+ marginRight: 8,
316
+ },
317
+ errorDownloadText: {
318
+ fontFamily: "sf-semibold",
319
+ fontSize: 16,
320
+ color: TEXT_DARK,
321
+ },
174
322
  };
175
323
 
176
324
  export { PDFPopup };