@olea-bps/base 1.0.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 (268) hide show
  1. package/components/AppBar/index.js +84 -0
  2. package/components/AppBar/styles.js +27 -0
  3. package/components/BookDetail/index.js +268 -0
  4. package/components/BookDetail/styles.js +124 -0
  5. package/components/ComponentJobsFilter/index.js +188 -0
  6. package/components/ComponentJobsFilter/styles.js +12 -0
  7. package/components/ConnectivityWarning/index.js +65 -0
  8. package/components/ConnectivityWarning/styles.js +19 -0
  9. package/components/ContactDetail/index.js +232 -0
  10. package/components/ContactDetail/styles.js +32 -0
  11. package/components/CourseDetail/index.js +357 -0
  12. package/components/CourseDetail/styles.js +59 -0
  13. package/components/CourseDetailDialog/index.js +169 -0
  14. package/components/CourseDetailDialog/styles.js +116 -0
  15. package/components/CourseInfo/index.js +219 -0
  16. package/components/CourseInfo/styles.js +40 -0
  17. package/components/DevelopmentDialog/index.js +214 -0
  18. package/components/DevelopmentDialog/styles.js +10 -0
  19. package/components/EventCodeInput/index.js +149 -0
  20. package/components/EventCodeInput/styles.js +108 -0
  21. package/components/FlexMenuEntry/index.js +84 -0
  22. package/components/FlexMenuEntry/styles.js +27 -0
  23. package/components/MainMenuEntry/index.js +88 -0
  24. package/components/MainMenuEntry/styles.js +28 -0
  25. package/components/MealItem/index.js +87 -0
  26. package/components/MealItem/styles.js +84 -0
  27. package/components/MensaMenu/index.js +305 -0
  28. package/components/MensaMenu/styles.js +94 -0
  29. package/components/MensaSlider/index.js +188 -0
  30. package/components/MensaSlider/styles.js +53 -0
  31. package/components/Modal/index.js +106 -0
  32. package/components/Modal/styles.js +8 -0
  33. package/components/NewsDetail/index.js +377 -0
  34. package/components/NewsDetail/styles.js +77 -0
  35. package/components/NewsList/index.js +120 -0
  36. package/components/NewsList/styles.js +19 -0
  37. package/components/NewsListItem/index.js +89 -0
  38. package/components/NewsListItem/styles.js +32 -0
  39. package/components/OtherCourses/index.js +152 -0
  40. package/components/OtherCourses/styles.js +10 -0
  41. package/components/PtsDeparture/index.js +140 -0
  42. package/components/PtsDeparture/styles.js +7 -0
  43. package/components/PtsStation/index.js +186 -0
  44. package/components/PtsStation/styles.js +47 -0
  45. package/components/QuickLinks/index.js +127 -0
  46. package/components/QuickLinks/styles.js +45 -0
  47. package/components/RoomDetail/index.js +281 -0
  48. package/components/RoomDetail/styles.js +56 -0
  49. package/components/ScaledImage/index.js +92 -0
  50. package/components/SearchResults/index.js +362 -0
  51. package/components/SearchResults/styles.js +59 -0
  52. package/components/SettingSection/index.js +54 -0
  53. package/components/SettingSection/styles.js +15 -0
  54. package/components/SettingsDialog/index.js +52 -0
  55. package/components/SettingsDialog/styles.js +12 -0
  56. package/components/SettingsDialogRadio/index.js +66 -0
  57. package/components/SettingsDialogRadio/styles.js +7 -0
  58. package/components/SettingsDialogSelect/index.js +73 -0
  59. package/components/SettingsDialogSelect/styles.js +7 -0
  60. package/components/TimetableCodeInput/index.js +205 -0
  61. package/components/TimetableCodeInput/styles.js +28 -0
  62. package/components/TimetableDay/index.js +252 -0
  63. package/components/TimetableDay/styles.js +103 -0
  64. package/components/TimetableEvent/index.js +163 -0
  65. package/components/TimetableEvent/styles.js +108 -0
  66. package/components/TimetableList/index.js +180 -0
  67. package/components/TimetableList/styles.js +106 -0
  68. package/components/TimetableMonth/index.js +156 -0
  69. package/components/TimetableMonth/styles.js +29 -0
  70. package/components/TimetableWeek/index.js +230 -0
  71. package/components/TimetableWeek/styles.js +58 -0
  72. package/components/TopNews/index.js +282 -0
  73. package/components/TopNews/styles.js +125 -0
  74. package/components/TopNewsHtwk/index.js +279 -0
  75. package/components/TopNewsHtwk/styles.js +142 -0
  76. package/components/WebView/index.js +108 -0
  77. package/components/WebView/styles.js +11 -0
  78. package/context/context-callmanager/TucCallManager.js +74 -0
  79. package/context/context-callmanager/index.js +128 -0
  80. package/context/context-canteen/AsistServerApiProvider.js +126 -0
  81. package/context/context-canteen/CollektorVersion2ApiProvider.js +100 -0
  82. package/context/context-canteen/index.js +692 -0
  83. package/context/context-connectivity/index.js +85 -0
  84. package/context/context-event/AsistServerClient.js +82 -0
  85. package/context/context-event/index.js +205 -0
  86. package/context/context-flex-menu/AsistServerApiProvider.js +0 -0
  87. package/context/context-flex-menu/CollectorVersion2ApiProvider.js +32 -0
  88. package/context/context-flex-menu/index.js +160 -0
  89. package/context/context-info-dialog/CollektorVersion2ApiProvider.js +53 -0
  90. package/context/context-info-dialog/ProviderErrors.js +22 -0
  91. package/context/context-info-dialog/index.js +190 -0
  92. package/context/context-mails/MailService.js +147 -0
  93. package/context/context-mails/TucUnseenApiProvider.js +65 -0
  94. package/context/context-mails/index.js +131 -0
  95. package/context/context-news/CollektorVersion2ApiProvider.js +68 -0
  96. package/context/context-news/index.js +155 -0
  97. package/context/context-public-transport-ticket/CollektorVersion2ApiProvider.js +45 -0
  98. package/context/context-public-transport-ticket/ProviderErrors.js +11 -0
  99. package/context/context-public-transport-ticket/index.js +175 -0
  100. package/context/context-timetable/CollectorVersion2ApiProvider.js +102 -0
  101. package/context/context-timetable/ProviderErrors.js +22 -0
  102. package/context/context-timetable/TimetableService.js +357 -0
  103. package/context/context-timetable/index.js +215 -0
  104. package/context/context-user/index.js +586 -0
  105. package/index.js +178 -0
  106. package/libraries/base-api-provider/hooks.js +24 -0
  107. package/libraries/base-api-provider/http-api-provider.js +168 -0
  108. package/libraries/base-api-provider/index.js +20 -0
  109. package/libraries/core/api/canteens.js +88 -0
  110. package/libraries/core/api/corona.js +45 -0
  111. package/libraries/core/api/courses.js +54 -0
  112. package/libraries/core/api/device.js +98 -0
  113. package/libraries/core/api/feed.js +144 -0
  114. package/libraries/core/api/feedback.js +123 -0
  115. package/libraries/core/api/jobs.js +48 -0
  116. package/libraries/core/api/library.js +67 -0
  117. package/libraries/core/api/lostfound.js +77 -0
  118. package/libraries/core/api/occupancy.js +44 -0
  119. package/libraries/core/api/officehours.js +25 -0
  120. package/libraries/core/api/poi.js +25 -0
  121. package/libraries/core/api/pts.js +68 -0
  122. package/libraries/core/api/rooms.js +31 -0
  123. package/libraries/core/api/survey.js +121 -0
  124. package/libraries/core/api/telephone.js +32 -0
  125. package/libraries/core/api/tucrooms.js +31 -0
  126. package/libraries/core/constants/actions.js +75 -0
  127. package/libraries/core/constants/api.js +146 -0
  128. package/libraries/core/constants/enums.js +5 -0
  129. package/libraries/core/helper/date.js +9 -0
  130. package/libraries/core/helper/format.helper.js +2 -0
  131. package/libraries/core/index.js +60 -0
  132. package/libraries/core/redux/actions/notifications.js +6 -0
  133. package/libraries/core/redux/actions/setting.js +75 -0
  134. package/libraries/core/redux/actions/state.js +74 -0
  135. package/libraries/core/redux/asyncDispatch.js +27 -0
  136. package/libraries/core/redux/reducers/api.js +190 -0
  137. package/libraries/core/redux/reducers/index.js +32 -0
  138. package/libraries/core/redux/reducers/notifications.js +16 -0
  139. package/libraries/core/redux/reducers/setting.js +99 -0
  140. package/libraries/core/redux/reducers/state.js +122 -0
  141. package/libraries/core/redux/selectors.js +123 -0
  142. package/libraries/core/redux/store.js +40 -0
  143. package/libraries/core/services/data.js +96 -0
  144. package/libraries/core/services/root-navigation.js +36 -0
  145. package/libraries/core/services/search.js +175 -0
  146. package/libraries/core-plugins/enums/replaceTypes.js +53 -0
  147. package/libraries/core-plugins/index.js +21 -0
  148. package/libraries/core-plugins/redux/actions/plugin.js +13 -0
  149. package/libraries/core-plugins/redux/reducers/plugin.js +210 -0
  150. package/libraries/icons-openasist/index.js +143 -0
  151. package/libraries/notifications/index.js +268 -0
  152. package/libraries/notifications/services/subscriber.service.js +123 -0
  153. package/libraries/react-native-webview-autoheight/README.md +47 -0
  154. package/libraries/react-native-webview-autoheight/index.js +140 -0
  155. package/libraries/react-native-webview-autoheight/package.json +37 -0
  156. package/libraries/react-native-webview-autoheight/utils.js +268 -0
  157. package/libraries/redux-offline/.eslintignore +1 -0
  158. package/libraries/redux-offline/.github/ISSUE_TEMPLATE/redux-offline-core-issues-template.md +25 -0
  159. package/libraries/redux-offline/.prettierrc +6 -0
  160. package/libraries/redux-offline/LICENSE +21 -0
  161. package/libraries/redux-offline/README.md +133 -0
  162. package/libraries/redux-offline/flow-typed/npm/redux-logger_vx.x.x.js +109 -0
  163. package/libraries/redux-offline/flow-typed/npm/redux_v4.x.x.js +100 -0
  164. package/libraries/redux-offline/lib/actions.js +46 -0
  165. package/libraries/redux-offline/lib/config.js +15 -0
  166. package/libraries/redux-offline/lib/constants.js +17 -0
  167. package/libraries/redux-offline/lib/defaults/defaultCommit.js +11 -0
  168. package/libraries/redux-offline/lib/defaults/defaultRollback.js +11 -0
  169. package/libraries/redux-offline/lib/defaults/detectNetwork.js +33 -0
  170. package/libraries/redux-offline/lib/defaults/detectNetwork.native.js +211 -0
  171. package/libraries/redux-offline/lib/defaults/discard.js +18 -0
  172. package/libraries/redux-offline/lib/defaults/effect.js +87 -0
  173. package/libraries/redux-offline/lib/defaults/index.js +32 -0
  174. package/libraries/redux-offline/lib/defaults/offlineStateLens.js +24 -0
  175. package/libraries/redux-offline/lib/defaults/persist.js +9 -0
  176. package/libraries/redux-offline/lib/defaults/persist.native.js +17 -0
  177. package/libraries/redux-offline/lib/defaults/persistAutoRehydrate.js +8 -0
  178. package/libraries/redux-offline/lib/defaults/queue.js +27 -0
  179. package/libraries/redux-offline/lib/defaults/retry.js +29 -0
  180. package/libraries/redux-offline/lib/index.js +115 -0
  181. package/libraries/redux-offline/lib/middleware.js +56 -0
  182. package/libraries/redux-offline/lib/offlineActionTracker.js +43 -0
  183. package/libraries/redux-offline/lib/send.js +112 -0
  184. package/libraries/redux-offline/lib/types.js +3 -0
  185. package/libraries/redux-offline/lib/updater.js +111 -0
  186. package/libraries/redux-offline/package.json +69 -0
  187. package/libraries/redux-offline/src/__tests__/defaults/discard.js +22 -0
  188. package/libraries/redux-offline/src/__tests__/defaults/effect.js +118 -0
  189. package/libraries/redux-offline/src/__tests__/index.js +116 -0
  190. package/libraries/redux-offline/src/__tests__/middleware.js +185 -0
  191. package/libraries/redux-offline/src/__tests__/offlineActionTracker.js +54 -0
  192. package/libraries/redux-offline/src/__tests__/send.js +208 -0
  193. package/libraries/redux-offline/src/actions.js +36 -0
  194. package/libraries/redux-offline/src/config.js +9 -0
  195. package/libraries/redux-offline/src/constants.js +18 -0
  196. package/libraries/redux-offline/src/defaults/defaultCommit.js +7 -0
  197. package/libraries/redux-offline/src/defaults/defaultRollback.js +7 -0
  198. package/libraries/redux-offline/src/defaults/detectNetwork.js +16 -0
  199. package/libraries/redux-offline/src/defaults/detectNetwork.native.js +148 -0
  200. package/libraries/redux-offline/src/defaults/discard.js +19 -0
  201. package/libraries/redux-offline/src/defaults/effect.js +86 -0
  202. package/libraries/redux-offline/src/defaults/index.js +25 -0
  203. package/libraries/redux-offline/src/defaults/offlineStateLens.js +11 -0
  204. package/libraries/redux-offline/src/defaults/persist.js +4 -0
  205. package/libraries/redux-offline/src/defaults/persist.native.js +9 -0
  206. package/libraries/redux-offline/src/defaults/persistAutoRehydrate.js +4 -0
  207. package/libraries/redux-offline/src/defaults/queue.js +20 -0
  208. package/libraries/redux-offline/src/defaults/retry.js +18 -0
  209. package/libraries/redux-offline/src/index.js +138 -0
  210. package/libraries/redux-offline/src/middleware.js +52 -0
  211. package/libraries/redux-offline/src/offlineActionTracker.js +40 -0
  212. package/libraries/redux-offline/src/send.js +111 -0
  213. package/libraries/redux-offline/src/types.js +127 -0
  214. package/libraries/redux-offline/src/updater.js +141 -0
  215. package/libraries/redux-offline/typings.d.ts +150 -0
  216. package/libraries/redux-offline/yarn.lock +6460 -0
  217. package/libraries/stored-state/index.js +155 -0
  218. package/package.json +68 -0
  219. package/views/Callmanager/index.js +148 -0
  220. package/views/Callmanager/styles.js +62 -0
  221. package/views/Canteens/index.js +383 -0
  222. package/views/Canteens/styles.js +89 -0
  223. package/views/Dashboard/index.js +176 -0
  224. package/views/Dashboard/styles.js +16 -0
  225. package/views/DashboardHtwk/index.js +197 -0
  226. package/views/DashboardHtwk/styles.js +24 -0
  227. package/views/Event/index.js +373 -0
  228. package/views/Event/styles.js +63 -0
  229. package/views/FeedList/index.js +165 -0
  230. package/views/FeedList/styles.js +15 -0
  231. package/views/FeedNews/index.js +243 -0
  232. package/views/FeedNews/styles.js +32 -0
  233. package/views/Flexmenu/index.js +185 -0
  234. package/views/Flexmenu/styles.js +62 -0
  235. package/views/FlexmenuWebview/index.js +167 -0
  236. package/views/FlexmenuWebview/styles.js +16 -0
  237. package/views/Howhy/index.js +151 -0
  238. package/views/Howhy/styles.js +11 -0
  239. package/views/Jobs/index.js +217 -0
  240. package/views/Jobs/styles.js +41 -0
  241. package/views/MainMenu/index.js +283 -0
  242. package/views/MainMenu/styles.js +36 -0
  243. package/views/NewsTabbar/index.js +164 -0
  244. package/views/NewsTabbar/styles.js +27 -0
  245. package/views/Opal/index.js +136 -0
  246. package/views/Opal/styles.js +11 -0
  247. package/views/PublicTransportTicket/index.js +173 -0
  248. package/views/PublicTransportTicket/styles.js +17 -0
  249. package/views/Search/index.js +186 -0
  250. package/views/Search/styles.js +67 -0
  251. package/views/SettingsAccessibility/index.js +148 -0
  252. package/views/SettingsAccessibility/styles.js +13 -0
  253. package/views/SettingsAppInfo/index.js +86 -0
  254. package/views/SettingsAppInfo/styles.js +18 -0
  255. package/views/SettingsCanteens/index.js +249 -0
  256. package/views/SettingsCanteens/styles.js +33 -0
  257. package/views/SettingsGeneral/index.js +173 -0
  258. package/views/SettingsGeneral/styles.js +28 -0
  259. package/views/SettingsNotifications/index.js +204 -0
  260. package/views/SettingsNotifications/styles.js +38 -0
  261. package/views/SettingsUser/index.js +170 -0
  262. package/views/SettingsUser/styles.js +17 -0
  263. package/views/TimetableCalendar/index.js +387 -0
  264. package/views/TimetableCalendar/styles.js +121 -0
  265. package/views/TimetableList/index.js +402 -0
  266. package/views/TimetableList/styles.js +55 -0
  267. package/views/Webviews/index.js +158 -0
  268. package/views/Webviews/styles.js +11 -0
@@ -0,0 +1,140 @@
1
+ import React, {useState, useEffect, forwardRef} from 'react';
2
+
3
+ import {StyleSheet, Platform} from 'react-native';
4
+
5
+ import PropTypes from 'prop-types';
6
+
7
+ import {WebView} from 'react-native-webview';
8
+
9
+ import {
10
+ topic,
11
+ reduceData,
12
+ getWidth,
13
+ isSizeChanged,
14
+ shouldUpdate,
15
+ } from './utils';
16
+
17
+ const AutoHeightWebView = React.memo(
18
+ forwardRef((props, ref) => {
19
+ const defaultProps = {
20
+ showsVerticalScrollIndicator: false,
21
+ showsHorizontalScrollIndicator: false,
22
+ originWhitelist: ['*'],
23
+ };
24
+
25
+ Platform.OS === 'android' &&
26
+ Object.assign(defaultProps, {
27
+ scalesPageToFit: false,
28
+ });
29
+
30
+ Platform.OS === 'ios' &&
31
+ Object.assign(defaultProps, {
32
+ viewportContent: 'width=device-width',
33
+ });
34
+
35
+ const fullProps = Object.assign(defaultProps, props);
36
+
37
+ const {
38
+ style,
39
+ onMessage,
40
+ onSizeUpdated,
41
+ scrollEnabledWithZoomedin,
42
+ scrollEnabled,
43
+ } = fullProps;
44
+
45
+ const [size, setSize] = useState({
46
+ height: style && style.height ? style.height : 0,
47
+ width: getWidth(style),
48
+ });
49
+
50
+ const [scrollable, setScrollable] = useState(false);
51
+ const handleMessage = (event) => {
52
+ if (event.nativeEvent) {
53
+ try {
54
+ const data = JSON.parse(event.nativeEvent.data);
55
+ if (data.topic !== topic) {
56
+ onMessage && onMessage(event);
57
+ return;
58
+ }
59
+ const {height, width, zoomedin} = data;
60
+ !scrollEnabled &&
61
+ scrollEnabledWithZoomedin &&
62
+ setScrollable(!!zoomedin);
63
+ const {height: previousHeight, width: previousWidth} = size;
64
+ isSizeChanged({height, previousHeight, width, previousWidth}) &&
65
+ setSize({
66
+ height,
67
+ width,
68
+ });
69
+ } catch (error) {
70
+ onMessage && onMessage(event);
71
+ }
72
+ } else {
73
+ onMessage && onMessage(event);
74
+ }
75
+ };
76
+
77
+ const currentScrollEnabled =
78
+ scrollEnabled === false && scrollEnabledWithZoomedin
79
+ ? scrollable
80
+ : scrollEnabled;
81
+
82
+ const {currentSource, script} = reduceData(fullProps);
83
+
84
+ const {width, height} = size;
85
+ useEffect(() => {
86
+ onSizeUpdated &&
87
+ onSizeUpdated({
88
+ height,
89
+ width,
90
+ });
91
+ }, [width, height, onSizeUpdated]);
92
+
93
+ return React.createElement(WebView, {
94
+ ...fullProps,
95
+ ref,
96
+ onMessage: handleMessage,
97
+ style: [
98
+ styles.webView,
99
+ {
100
+ width,
101
+ height,
102
+ },
103
+ style,
104
+ ],
105
+ injectedJavaScript: script,
106
+ source: currentSource,
107
+ scrollEnabled: currentScrollEnabled,
108
+ });
109
+ }),
110
+ (prevProps, nextProps) => !shouldUpdate({prevProps, nextProps}),
111
+ );
112
+
113
+ AutoHeightWebView.propTypes = {
114
+ onSizeUpdated: PropTypes.func,
115
+ files: PropTypes.arrayOf(
116
+ PropTypes.shape({
117
+ href: PropTypes.string,
118
+ type: PropTypes.string,
119
+ rel: PropTypes.string,
120
+ }),
121
+ ),
122
+ style: PropTypes.object,
123
+ customScript: PropTypes.string,
124
+ customStyle: PropTypes.string,
125
+ viewportContent: PropTypes.string,
126
+ scrollEnabledWithZoomedin: PropTypes.bool,
127
+ // webview props
128
+ originWhitelist: PropTypes.arrayOf(PropTypes.string),
129
+ onMessage: PropTypes.func,
130
+ scalesPageToFit: PropTypes.bool,
131
+ source: PropTypes.object,
132
+ };
133
+
134
+ const styles = StyleSheet.create({
135
+ webView: {
136
+ backgroundColor: 'transparent',
137
+ },
138
+ });
139
+
140
+ export default AutoHeightWebView;
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@olea-bps/react-native-webview-autoheight",
3
+ "version": "1.0.2",
4
+ "description": "React Native WebView with AutoHeight",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/tuc-urz/olea.git",
12
+ "directory": "packages/libraries/react-native-webview-autoheight"
13
+ },
14
+ "keywords": [
15
+ "react",
16
+ "native",
17
+ "webview",
18
+ "auto",
19
+ "height"
20
+ ],
21
+ "author": "Elton Jain",
22
+ "license": "ISC",
23
+ "files": [
24
+ "index.js",
25
+ "utils.js",
26
+ "package.json",
27
+ "LICENSE",
28
+ "README.md"
29
+ ],
30
+ "dependencies": {
31
+ "react-native-webview": "13.16.0"
32
+ },
33
+ "peerDependencies": {
34
+ "react": "^19.0.0",
35
+ "react-native": "^0.81.0"
36
+ }
37
+ }
@@ -0,0 +1,268 @@
1
+ 'use strict';
2
+
3
+ import {Dimensions} from 'react-native';
4
+
5
+ export const topic = "rnaw"
6
+ export const topicString = `"${topic}"`
7
+
8
+ const domMutationObserveScript = `
9
+ var MutationObserver =
10
+ window.MutationObserver || window.WebKitMutationObserver;
11
+ var observer = new MutationObserver(updateSize);
12
+ observer.observe(document, {
13
+ subtree: true,
14
+ attributes: true
15
+ });
16
+ `;
17
+
18
+ const updateSizeWithMessage = (element, scalesPageToFit) =>
19
+ `
20
+ var usingScale = ${scalesPageToFit} ? screen.width / window.innerWidth : 1;
21
+ var scaling = false;
22
+ var zoomedin = false;
23
+ var lastHeight = 0;
24
+ var heightTheSameTimes = 0;
25
+ var maxHeightTheSameTimes = 5;
26
+ var forceRefreshDelay = 1000;
27
+ var forceRefreshTimeout;
28
+ var checkPostMessageTimeout;
29
+
30
+ function updateSize() {
31
+ if (zoomedin || scaling || document.fullscreenElement) {
32
+ return;
33
+ }
34
+ if (
35
+ !window.hasOwnProperty('ReactNativeWebView') ||
36
+ !window.ReactNativeWebView.hasOwnProperty('postMessage')
37
+ ) {
38
+ checkPostMessageTimeout = setTimeout(updateSize, 200);
39
+ return;
40
+ }
41
+
42
+ clearTimeout(checkPostMessageTimeout);
43
+ var result = ${element}.getBoundingClientRect()
44
+ height = result.height + result.top;
45
+ if(!height) {
46
+ height = ${element}.offsetHeight || document.documentElement.offsetHeight
47
+ }
48
+ width = result.width;
49
+ if(!width) {
50
+ width = ${element}.offsetWidth || document.documentElement.offsetWidth
51
+ }
52
+
53
+
54
+ window.ReactNativeWebView.postMessage(JSON.stringify({ width: Math.min(width, screen.width), height: height * usingScale, topic: ${topicString} }));
55
+
56
+ // Make additional height checks (required to fix issues wit twitter embeds)
57
+ clearTimeout(forceRefreshTimeout);
58
+
59
+ if (lastHeight !== height) {
60
+ heightTheSameTimes = 1;
61
+ } else {
62
+ heightTheSameTimes++;
63
+ }
64
+
65
+ lastHeight = height;
66
+
67
+ if (heightTheSameTimes <= maxHeightTheSameTimes) {
68
+ forceRefreshTimeout = setTimeout(
69
+ updateSize,
70
+ heightTheSameTimes * forceRefreshDelay
71
+ );
72
+ }
73
+ }
74
+ `;
75
+
76
+ const setViewportContent = (content) => {
77
+ if (!content) {
78
+ return '';
79
+ }
80
+ return `
81
+ var meta = document.createElement("meta");
82
+ meta.setAttribute("name", "viewport");
83
+ meta.setAttribute("content", "${content}");
84
+ document.getElementsByTagName("head")[0].appendChild(meta);
85
+ `;
86
+ };
87
+
88
+ const detectZoomChanged = `
89
+ var latestTapStamp = 0;
90
+ var lastScale = 1.0;
91
+ var doubleTapDelay = 400;
92
+ function detectZoomChanged() {
93
+ var tempZoomedin = (screen.width / window.innerWidth) > usingScale;
94
+ tempZoomedin !== zoomedin && window.ReactNativeWebView.postMessage(JSON.stringify({ zoomedin: tempZoomedin, topic: ${topicString} }));
95
+ zoomedin = tempZoomedin;
96
+ }
97
+ window.addEventListener('ontouchstart', event => {
98
+ if (event.touches.length === 2) {
99
+ scaling = true;
100
+ }
101
+ })
102
+ window.addEventListener('touchend', event => {
103
+ if(scaling) {
104
+ scaleing = false;
105
+ }
106
+
107
+ var tempScale = event.scale;
108
+ tempScale !== lastScale && detectZoomChanged();
109
+ lastScale = tempScale;
110
+ var timeSince = new Date().getTime() - latestTapStamp;
111
+
112
+ // double tap
113
+ if(timeSince < 600 && timeSince > 0) {
114
+ zoomedinTimeOut = setTimeout(() => {
115
+ clearTimeout(zoomedinTimeOut);
116
+ detectZoomChanged();
117
+ }, doubleTapDelay);
118
+ }
119
+
120
+ latestTapStamp = new Date().getTime();
121
+ });
122
+ `;
123
+
124
+ const getBaseScript = ({
125
+ viewportContent,
126
+ scalesPageToFit,
127
+ scrollEnabledWithZoomedin,
128
+ }) =>
129
+ `
130
+ ;
131
+ var wrapper = document.getElementById("rnahw-wrapper");
132
+ if (!wrapper) {
133
+ wrapper = document.createElement('div');
134
+ wrapper.id = 'rnahw-wrapper';
135
+ while (document.body.firstChild instanceof Node) {
136
+ wrapper.appendChild(document.body.firstChild);
137
+ }
138
+ document.body.appendChild(wrapper);
139
+ }
140
+ ${updateSizeWithMessage('wrapper', scalesPageToFit)}
141
+ window.addEventListener('load', updateSize);
142
+ window.addEventListener('resize', updateSize);
143
+ ${domMutationObserveScript}
144
+ ${setViewportContent(viewportContent)}
145
+ ${scrollEnabledWithZoomedin ? detectZoomChanged : ''}
146
+ updateSize();
147
+ `;
148
+
149
+ const appendFilesToHead = ({files, script}) =>
150
+ files.reduceRight((combinedScript, file) => {
151
+ const {rel, type, href} = file;
152
+ return `
153
+ var link = document.createElement('link');
154
+ link.rel = '${rel}';
155
+ link.type = '${type}';
156
+ link.href = '${href}';
157
+ document.head.appendChild(link);
158
+ ${combinedScript}
159
+ `;
160
+ }, script);
161
+
162
+ const bodyStyle = `
163
+ body {
164
+ margin: 0;
165
+ padding: 0;
166
+ }
167
+ `;
168
+
169
+ const appendStylesToHead = ({style, script}) => {
170
+ const currentStyles = style ? bodyStyle + style : bodyStyle;
171
+ // Escape any single quotes or newlines in the CSS with .replace()
172
+ const escaped = currentStyles.replace(/\'/g, "\\'").replace(/\n/g, '\\n');
173
+ return `
174
+ var styleElement = document.createElement('style');
175
+ styleElement.innerHTML = '${escaped}';
176
+ document.head.appendChild(styleElement);
177
+ ${script}
178
+ `;
179
+ };
180
+
181
+ const getInjectedSource = ({html, script}) => `
182
+ ${html}
183
+ <script>
184
+ // prevents code colissions with global scope
185
+ (function() {
186
+ ${script}
187
+ })();
188
+ </script>
189
+ `;
190
+
191
+ const getScript = ({
192
+ files,
193
+ customStyle,
194
+ customScript,
195
+ style,
196
+ viewportContent,
197
+ scalesPageToFit,
198
+ scrollEnabledWithZoomedin,
199
+ }) => {
200
+ let script = getBaseScript({
201
+ viewportContent,
202
+ scalesPageToFit,
203
+ scrollEnabledWithZoomedin,
204
+ });
205
+ script =
206
+ files && files.length > 0 ? appendFilesToHead({files, script}) : script;
207
+ script = appendStylesToHead({style: customStyle, script});
208
+ customScript && (script = customScript + script);
209
+ return script;
210
+ };
211
+
212
+ export const getWidth = (style) => {
213
+ return style && style.width ? style.width : Dimensions.get('window').width;
214
+ };
215
+
216
+ export const isSizeChanged = ({
217
+ height,
218
+ previousHeight,
219
+ width,
220
+ previousWidth,
221
+ }) => {
222
+ if (!height || !width) {
223
+ return;
224
+ }
225
+ return height !== previousHeight || width !== previousWidth;
226
+ };
227
+
228
+ export const reduceData = (props) => {
229
+ const {source} = props;
230
+ const script = getScript(props);
231
+ const {html, baseUrl} = source;
232
+ if (html) {
233
+ return {
234
+ currentSource: {baseUrl, html: getInjectedSource({html, script})},
235
+ };
236
+ } else {
237
+ return {
238
+ currentSource: source,
239
+ script,
240
+ };
241
+ }
242
+ };
243
+
244
+ export const shouldUpdate = ({prevProps, nextProps}) => {
245
+ if (!(prevProps && nextProps)) {
246
+ return true;
247
+ }
248
+ for (const prop in nextProps) {
249
+ if (nextProps[prop] !== prevProps[prop]) {
250
+ if (
251
+ typeof nextProps[prop] === 'object' &&
252
+ typeof prevProps[prop] === 'object'
253
+ ) {
254
+ if (
255
+ shouldUpdate({
256
+ prevProps: prevProps[prop],
257
+ nextProps: nextProps[prop],
258
+ })
259
+ ) {
260
+ return true;
261
+ }
262
+ } else {
263
+ return true;
264
+ }
265
+ }
266
+ }
267
+ return false;
268
+ };
@@ -0,0 +1 @@
1
+ src/__tests__/*.js
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: Redux-Offline core issues template
3
+ about: Please use this template if reporting a bug
4
+
5
+ ---
6
+
7
+ ### Are you using `offline()` or `createOffline()` API?
8
+ _If you're using `createOffline()` API, be sure to use `compose()` in the right order._
9
+
10
+ ### Store config
11
+ Please paste your config below.
12
+ ```js
13
+ (Please paste your store config)
14
+ ```
15
+
16
+ ### Offline config
17
+
18
+ Are you using a custom configuration? If you are please paste your config below.
19
+ ```js
20
+ (Please paste your offline config)
21
+ ```
22
+ If you need code indentation, you can use [Prettier](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEAzArlMMCW0AEAEnADYkQDqEATiQCYAUwA5tXHLlM-gLz4A6IABalyggDT5W7eHV74A5IKq06ghZIDOOEghjzUAQxKa4k6AFkI6UwHkAbnGriAvgEp8wflG-58OVAYAQmkOHC43YDYYdGoofCh0MhcAbm9fPz8Aeiz8ABVbABFbJHxC6AV9Gzh8akMoOggAW394tganDN19RJa+C0MYIQA6VHIafAYBoeG6huaGDwAqfABGAFEAagB2N2GYCABlGGpw5kXZuAAHEkMwOAYs-n5h57pNrJxmSUFBN3T4rUOLF4gAeOg4ez4MC3TSaAByhiacB4CmIZEoNHoCnwuBguh4wAABgBNaz4QxsfD2HDaA7UBLoJoAIyc+AAJMBGS0XESXPhLNY7I5qITBdUHE4XAA+AGZfCgzQnaDMaVc0KcZjDTQkHD3Bj4AAMklW+D2BwAqlcrk4AMKGUyLfCbKRsMJcbW6-Wrc0QAAyEAA7naHQ8PC5QVkldQVbLAX4WG7NcMEHRNBQcEMGBI-vgAPwCECF-ClRVXer4JUATwJwGAkHI1FKSn40irChcMokhcjmnLUGl+BcGT8oLgTTj-Bg6qTcDkw58MEj47j8q5DG0ulg-3jmQLgleIBHmVKgiCggXx8jEPs0rSPigLhA4hAECuuGgmmQoEpMcDAAVKQQL8UEMewIBwOhnxAZk6jAABrDhDnLMAzmQE50DMEBwlMagYH-OpmCaQxkCMEwsIAK00AAPAAhODEJgQ4kTgP1wjgUjjFMF9y2oXDkBgwxmRraBoKuU5YAzOghmQAAOY0QHEiBTAoOorgE8S4FwxxoLYABHdAcDYAjDCIkikDI7iQFMJocHQ6hMJfbQuF0ABFdAIHgezHJAGAhKkmSkAAJhfE5DB0M5bWaYiBKgaAOJfao8iEkDLLgTsgA).
23
+
24
+ ### Are you reporting a bug?
25
+ If you've detected a bug and are able to reproduce it please share a code example using our [code-sandbox](https://codesandbox.io/s/8xml9l1r0j).
@@ -0,0 +1,6 @@
1
+ {
2
+ "singleQuote": true,
3
+ "arrowParens": "avoid",
4
+ "trailingComma": "none"
5
+ }
6
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Jani Eväkallio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,133 @@
1
+ <p>
2
+ <img alt="redux-offline" src="docs/logo.png" width="300"></img>
3
+ </p>
4
+ <p>
5
+ <a title='License' href="https://raw.githubusercontent.com/redux-offline/redux-offline/master/LICENSE" height="18">
6
+ <img src='https://img.shields.io/badge/license-MIT-blue.svg' />
7
+ </a>
8
+ <a href="https://badge.fury.io/js/%40redux-offline%2Fredux-offline">
9
+ <img src="https://badge.fury.io/js/%40redux-offline%2Fredux-offline.svg" alt="npm version" height="18">
10
+ </a>
11
+ <a href="https://travis-ci.org/redux-offline/redux-offline">
12
+ <img src="https://travis-ci.org/redux-offline/redux-offline.svg?branch=master" alt="travis" height="18">
13
+ </a>
14
+ </p>
15
+
16
+ Persistent Redux store for _Reasonaboutable_:tm: Offline-First applications, with first-class support for optimistic UI. Use with React, React Native, or as standalone state container for any web app.
17
+
18
+ > Redux Offline is now being maintained by a community driven team. The new versions of the library will now be available under the npm organization `@redux-offline`. Big thank you to [@jevakallio](https://github.com/jevakallio) for creating this amazing library in the first place.
19
+
20
+ ## Quick start
21
+
22
+ ##### 1. Install with npm (or [Yarn](https://yarnpkg.com))
23
+
24
+ ##### For React Native 0.60+
25
+ ```shell
26
+ npm install --save @redux-offline/redux-offline@native
27
+ ```
28
+
29
+ #### For React Native Expo SDK 36
30
+ ```shell
31
+ npm install --save @redux-offline/redux-offline@expo
32
+ ```
33
+
34
+ #### For React Native <= 0.59
35
+ ```shell
36
+ npm install --save @redux-offline/redux-offline
37
+ ```
38
+
39
+ ##### 2. Add the `offline` [store enhancer](http://redux.js.org/docs/Glossary.html#store-enhancer) with `compose`
40
+ ```js
41
+
42
+ import { applyMiddleware, createStore, compose } from 'redux';
43
+ import { offline } from '@redux-offline/redux-offline';
44
+ import offlineConfig from '@redux-offline/redux-offline/lib/defaults';
45
+
46
+ // ...
47
+
48
+ const store = createStore(
49
+ reducer,
50
+ preloadedState,
51
+ compose(
52
+ applyMiddleware(middleware),
53
+ offline(offlineConfig)
54
+ )
55
+ );
56
+ ```
57
+
58
+ ##### 3. Decorate actions with offline metadata
59
+
60
+ ```js
61
+ const followUser = userId => ({
62
+ type: 'FOLLOW_USER_REQUEST',
63
+ payload: { userId },
64
+ meta: {
65
+ offline: {
66
+ // the network action to execute:
67
+ effect: { url: '/api/follow', method: 'POST', json: { userId } },
68
+ // action to dispatch when effect succeeds:
69
+ commit: { type: 'FOLLOW_USER_COMMIT', meta: { userId } },
70
+ // action to dispatch if network action fails permanently:
71
+ rollback: { type: 'FOLLOW_USER_ROLLBACK', meta: { userId } }
72
+ }
73
+ }
74
+ });
75
+ ```
76
+
77
+ If the effect payload is something other than JSON you can pass the body and headers:
78
+
79
+ ```js
80
+ const registerUser = (name, email) => ({
81
+ type: 'REGISTER_USER',
82
+ payload: { name, email },
83
+ meta: {
84
+ offline: {
85
+ // the network action to execute:
86
+ effect: { url: '/api/register', method: 'POST', body: `name=${name}&email=${email}`, headers: { 'content-type': 'application/x-www-form-urlencoded' } },
87
+ // action to dispatch when effect succeeds:
88
+ commit: { type: 'REGISTER_USER_COMMIT', meta: { name, email } },
89
+ // action to dispatch if network action fails permanently:
90
+ rollback: { type: 'REGISTER_USER_ROLLBACK', meta: { name, email } }
91
+ }
92
+ }
93
+ });
94
+ ```
95
+
96
+ ##### 4. (React Native Android) Ask permission to read network status
97
+
98
+ If writing a native app for Android, you'll need to make sure to request the permission to access network state in your `AndroidManifest.xml`:
99
+
100
+ ```xml
101
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
102
+ ```
103
+ * * *
104
+
105
+ See [Documentation](docs/README.md) for configuration options, the full API, and common recipes.
106
+
107
+ ## Contributing
108
+
109
+ Improvements and additions welcome. For large changes, please submit a discussion issue before jumping to coding; we'd hate you to waste the effort.
110
+
111
+ If you are reporting a bug, please include code that reproduces the error. Here is a starting application on [CodeSandbox](https://codesandbox.io/s/8xml9l1r0j).
112
+
113
+ In lieu of a formal style guide, follow the included eslint rules, and use Prettier to format your code.
114
+
115
+ ## Miscellanea
116
+
117
+ ### Usage with Redux Persist v5
118
+
119
+ In case you want to use a custom [redux-persist](https://github.com/rt2zz/redux-persist) version, there is an
120
+ [example](https://gist.github.com/jarvisluong/f14872b9c7ed00bc2afc89c4622e3b55) configuration.
121
+
122
+ ### Prior art
123
+
124
+ Redux Offline is a distillation of patterns discovered while building apps using previously existing libraries:
125
+
126
+ * Forbes Lindesay's [redux-optimist](https://github.com/ForbesLindesay/redux-optimist)
127
+ * Zack Story's [redux-persist](https://github.com/rt2zz/redux-persist/tree/v4)
128
+
129
+ Without their work, Redux Offline wouldn't exist. If you like the ideas behind Redux Offline, but want to build your own stack from lower-level components, these are good places to start.
130
+
131
+ ### License
132
+
133
+ MIT