react-native-visit-rn-sdk 2.0.12 → 2.0.14

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 (154) hide show
  1. package/README.md +144 -0
  2. package/android/build.gradle +2 -0
  3. package/android/gradle.properties +1 -0
  4. package/android/src/main/AndroidManifest.xml +10 -0
  5. package/android/src/main/AndroidManifestNew.xml +10 -0
  6. package/android/src/main/java/com/visitrnsdk/VisitLocationModule.kt +349 -0
  7. package/android/src/main/java/com/visitrnsdk/VisitRnSdkPackage.kt +1 -1
  8. package/ios/VisitLocationModule.h +6 -0
  9. package/ios/VisitLocationModule.m +374 -0
  10. package/lib/commonjs/SecondaryWebView.android.js +145 -0
  11. package/lib/commonjs/SecondaryWebView.android.js.map +1 -0
  12. package/lib/commonjs/SecondaryWebView.ios.js +210 -0
  13. package/lib/commonjs/SecondaryWebView.ios.js.map +1 -0
  14. package/lib/commonjs/androidLocation.js +180 -0
  15. package/lib/commonjs/androidLocation.js.map +1 -0
  16. package/lib/commonjs/index.android.js +86 -109
  17. package/lib/commonjs/index.android.js.map +1 -1
  18. package/lib/commonjs/index.ios.js +75 -4
  19. package/lib/commonjs/index.ios.js.map +1 -1
  20. package/lib/commonjs/iosLocation.js +137 -0
  21. package/lib/commonjs/iosLocation.js.map +1 -0
  22. package/lib/module/SecondaryWebView.android.js +135 -0
  23. package/lib/module/SecondaryWebView.android.js.map +1 -0
  24. package/lib/module/SecondaryWebView.ios.js +201 -0
  25. package/lib/module/SecondaryWebView.ios.js.map +1 -0
  26. package/lib/module/androidLocation.js +170 -0
  27. package/lib/module/androidLocation.js.map +1 -0
  28. package/lib/module/index.android.js +87 -110
  29. package/lib/module/index.android.js.map +1 -1
  30. package/lib/module/index.ios.js +75 -4
  31. package/lib/module/index.ios.js.map +1 -1
  32. package/lib/module/iosLocation.js +127 -0
  33. package/lib/module/iosLocation.js.map +1 -0
  34. package/package.json +7 -3
  35. package/react-native-visit-rn-sdk.podspec +1 -0
  36. package/src/SecondaryWebView.android.js +149 -0
  37. package/src/SecondaryWebView.ios.js +230 -0
  38. package/src/androidLocation.js +228 -0
  39. package/src/index.android.js +84 -132
  40. package/src/index.ios.js +83 -3
  41. package/src/iosLocation.js +172 -0
  42. package/android/bin/build/generated/source/buildConfig/debug/com/visitrnsdk/BuildConfig.class +0 -0
  43. package/android/bin/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +0 -7
  44. package/android/bin/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json +0 -18
  45. package/android/bin/build/intermediates/aar_main_jar/debug/classes.jar +0 -0
  46. package/android/bin/build/intermediates/aar_metadata/debug/aar-metadata.properties +0 -5
  47. package/android/bin/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +0 -1
  48. package/android/bin/build/intermediates/annotations_typedef_file/debug/typedefs.txt +0 -0
  49. package/android/bin/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
  50. package/android/bin/build/intermediates/compile_r_class_jar/debug/R.jar +0 -0
  51. package/android/bin/build/intermediates/compile_symbol_list/debug/R.txt +0 -1954
  52. package/android/bin/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +0 -1
  53. package/android/bin/build/intermediates/incremental/debug/packageDebugResources/merger.xml +0 -2
  54. package/android/bin/build/intermediates/incremental/debug-mergeJavaRes/merge-state +0 -0
  55. package/android/bin/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +0 -2
  56. package/android/bin/build/intermediates/incremental/mergeDebugShaders/merger.xml +0 -2
  57. package/android/bin/build/intermediates/incremental/packageDebugAssets/merger.xml +0 -2
  58. package/android/bin/build/intermediates/library_java_res/debug/res.jar +0 -0
  59. package/android/bin/build/intermediates/local_only_symbol_list/debug/R-def.txt +0 -2
  60. package/android/bin/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt +0 -8
  61. package/android/bin/build/intermediates/merged_java_res/debug/feature-react-native-visit-rn-sdk.jar +0 -0
  62. package/android/bin/build/intermediates/merged_manifest/debug/AndroidManifest.xml +0 -7
  63. package/android/bin/build/intermediates/navigation_json/debug/navigation.json +0 -1
  64. package/android/bin/build/intermediates/packaged_manifests/debug/output-metadata.json +0 -18
  65. package/android/bin/build/intermediates/runtime_library_classes_jar/debug/classes.jar +0 -0
  66. package/android/bin/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt +0 -1447
  67. package/android/bin/build/intermediates/variant_model/debug/variant_model.json +0 -0
  68. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
  69. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
  70. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
  71. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
  72. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
  73. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
  74. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i.len +0 -0
  75. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
  76. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
  77. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
  78. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
  79. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
  80. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
  81. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i.len +0 -0
  82. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
  83. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
  84. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
  85. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
  86. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
  87. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
  88. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i.len +0 -0
  89. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
  90. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
  91. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
  92. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
  93. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
  94. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
  95. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i.len +0 -0
  96. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
  97. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
  98. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
  99. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
  100. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
  101. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
  102. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i.len +0 -0
  103. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
  104. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
  105. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
  106. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
  107. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
  108. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
  109. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i.len +0 -0
  110. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
  111. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
  112. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
  113. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
  114. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
  115. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
  116. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i.len +0 -0
  117. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
  118. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
  119. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
  120. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
  121. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
  122. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
  123. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i.len +0 -0
  124. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +0 -2
  125. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
  126. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
  127. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
  128. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
  129. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
  130. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
  131. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i.len +0 -0
  132. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
  133. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
  134. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
  135. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
  136. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
  137. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
  138. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i.len +0 -0
  139. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
  140. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
  141. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
  142. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
  143. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
  144. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
  145. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i.len +0 -0
  146. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
  147. package/android/bin/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
  148. package/android/bin/build/outputs/aar/react-native-visit-rn-sdk-debug.aar +0 -0
  149. package/android/bin/build/outputs/logs/manifest-merger-debug-report.txt +0 -25
  150. package/android/bin/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  151. package/android/bin/build/tmp/kotlin-classes/debug/META-INF/react-native-visit-rn-sdk_debug.kotlin_module +0 -0
  152. package/android/bin/local.properties +0 -8
  153. package/lib/typescript/index.test.d.ts +0 -1
  154. package/lib/typescript/index.test.d.ts.map +0 -1
@@ -0,0 +1,230 @@
1
+ import React, { useCallback, useMemo, useRef, useState } from 'react';
2
+ import {
3
+ Linking,
4
+ Modal,
5
+ PanResponder,
6
+ SafeAreaView,
7
+ StyleSheet,
8
+ View,
9
+ } from 'react-native';
10
+ import { EventRegister } from 'react-native-event-listeners';
11
+ import { WebView } from 'react-native-webview';
12
+ import { requestIosLocation } from './iosLocation';
13
+
14
+ const escapeChars = {
15
+ lt: '<',
16
+ gt: '>',
17
+ quot: '"',
18
+ apos: "'",
19
+ amp: '&',
20
+ };
21
+
22
+ const unescapeHTML = (str) =>
23
+ // modified from underscore.string and string.js
24
+ // eslint-disable-next-line no-useless-escape
25
+ str.replace(/\&([^;]+);/g, (entity, entityCode) => {
26
+ let match;
27
+
28
+ if (entityCode in escapeChars) {
29
+ return escapeChars[entityCode];
30
+ } else if ((match = entityCode.match(/^#x([\da-fA-F]+)$/))) {
31
+ return String.fromCharCode(parseInt(match[1], 16));
32
+ } else if ((match = entityCode.match(/^#(\d+)$/))) {
33
+ return String.fromCharCode(match[1]);
34
+ } else {
35
+ return entity;
36
+ }
37
+ });
38
+
39
+ const getHttpUrl = (url) => {
40
+ const link = typeof url === 'string' ? url.trim() : '';
41
+ return /^https?:\/\/[^\s/?#]+(?:[/?#][^\s]*)?$/i.test(link) ? link : '';
42
+ };
43
+
44
+ const isWebViewLocalUrl = (url) =>
45
+ /^(about|data|blob):/i.test(typeof url === 'string' ? url.trim() : '');
46
+
47
+ const BACK_SWIPE_EDGE_WIDTH = 24;
48
+ const BACK_SWIPE_DISTANCE = 60;
49
+ const BACK_SWIPE_FAST_DISTANCE = 24;
50
+ const BACK_SWIPE_VELOCITY = 0.5;
51
+
52
+ const isCompletedBackSwipe = ({ dx = 0, dy = 0, vx = 0 }) => {
53
+ const isRightwardHorizontalSwipe = dx > 0 && dx > Math.abs(dy);
54
+ const passedDistance = dx >= BACK_SWIPE_DISTANCE;
55
+ const passedFastFlick =
56
+ dx >= BACK_SWIPE_FAST_DISTANCE && vx >= BACK_SWIPE_VELOCITY;
57
+
58
+ return isRightwardHorizontalSwipe && (passedDistance || passedFastFlick);
59
+ };
60
+
61
+ const runBeforeFirst = `
62
+ window.isNativeApp = true;
63
+ window.platform = "IOS";
64
+ if (typeof window.setSdkPlatform === 'function') {
65
+ window.setSdkPlatform('IOS');
66
+ }
67
+ true; // note: this is required, or you'll sometimes get silent failures
68
+ `;
69
+
70
+ const SecondaryWebView = ({ link, isLoggingEnabled, onClose }) => {
71
+ const webviewRef = useRef(null);
72
+ const locationRequestInFlightRef = useRef(false);
73
+ const [canGoBack, setCanGoBack] = useState(false);
74
+
75
+ const requestLocationPermission = async (locationResponseVersion) => {
76
+ if (locationRequestInFlightRef.current) {
77
+ return;
78
+ }
79
+
80
+ locationRequestInFlightRef.current = true;
81
+ try {
82
+ await requestIosLocation({
83
+ webviewRef,
84
+ locationResponseVersion,
85
+ isLoggingEnabled,
86
+ });
87
+ } finally {
88
+ locationRequestInFlightRef.current = false;
89
+ }
90
+ };
91
+
92
+ const handleMessage = (event) => {
93
+ if (event.nativeEvent.data != null) {
94
+ try {
95
+ if (isLoggingEnabled) {
96
+ console.log('Secondary WebView event received');
97
+ }
98
+
99
+ const parsedObject = JSON.parse(unescapeHTML(event.nativeEvent.data));
100
+
101
+ switch (parsedObject.method) {
102
+ case 'GET_LOCATION_PERMISSIONS':
103
+ requestLocationPermission(parsedObject.locationResponseVersion);
104
+ break;
105
+ case 'OPEN_PDF':
106
+ Linking.openURL(parsedObject.url);
107
+ break;
108
+ case 'OPEN_FACE_SCAN_FLOW':
109
+ EventRegister.emitEvent('visit-event', {
110
+ message: 'OPEN_FACE_SCAN_FLOW',
111
+ });
112
+ break;
113
+ case 'CLOSE_VIEW':
114
+ onClose();
115
+ break;
116
+ case 'OPEN_SECONDARY_WEB_VIEW':
117
+ break;
118
+ default:
119
+ break;
120
+ }
121
+ } catch (exception) {
122
+ console.log('Exception occured:' + exception.message);
123
+ }
124
+ }
125
+ };
126
+
127
+ const handleBack = useCallback(() => {
128
+ if (canGoBack && webviewRef.current) {
129
+ webviewRef.current.goBack();
130
+ return;
131
+ }
132
+
133
+ onClose();
134
+ }, [canGoBack, onClose]);
135
+
136
+ const backSwipeResponder = useMemo(
137
+ () =>
138
+ PanResponder.create({
139
+ onStartShouldSetPanResponder: () => true,
140
+ onMoveShouldSetPanResponder: () => true,
141
+ onPanResponderRelease: (_event, gestureState) => {
142
+ if (isCompletedBackSwipe(gestureState)) {
143
+ handleBack();
144
+ }
145
+ },
146
+ onPanResponderTerminate: () => undefined,
147
+ onPanResponderTerminationRequest: () => false,
148
+ }),
149
+ [handleBack]
150
+ );
151
+
152
+ const source = getHttpUrl(link);
153
+ if (!source) {
154
+ return null;
155
+ }
156
+
157
+ return (
158
+ <Modal
159
+ animationType="slide"
160
+ onRequestClose={handleBack}
161
+ presentationStyle="fullScreen"
162
+ visible={true}
163
+ >
164
+ <SafeAreaView style={styles.container}>
165
+ <WebView
166
+ ref={webviewRef}
167
+ source={{ uri: source }}
168
+ style={styles.webView}
169
+ webviewDebuggingEnabled={Boolean(isLoggingEnabled)}
170
+ onShouldStartLoadWithRequest={(request) => {
171
+ if (request.isTopFrame === false) {
172
+ return true;
173
+ }
174
+ if (getHttpUrl(request.url) || isWebViewLocalUrl(request.url)) {
175
+ return true;
176
+ }
177
+ Linking.openURL(request.url).catch((error) => {
178
+ if (isLoggingEnabled) {
179
+ console.warn('Linking.openURL error: ', error);
180
+ }
181
+ });
182
+ return false;
183
+ }}
184
+ onMessage={handleMessage}
185
+ injectedJavaScriptBeforeContentLoaded={runBeforeFirst}
186
+ javaScriptEnabled={true}
187
+ mediaPlaybackRequiresUserAction={false}
188
+ allowsBackForwardNavigationGestures={false}
189
+ onNavigationStateChange={(navigationState) =>
190
+ setCanGoBack(Boolean(navigationState.canGoBack))
191
+ }
192
+ onError={(errorMessage) => {
193
+ EventRegister.emitEvent('visit-event', {
194
+ message: 'web-view-error',
195
+ errorMessage: errorMessage,
196
+ });
197
+ if (isLoggingEnabled) {
198
+ console.warn('Webview error: ', errorMessage);
199
+ }
200
+ }}
201
+ />
202
+ <View
203
+ testID="secondary-webview-back-swipe-edge"
204
+ style={styles.backSwipeEdge}
205
+ {...backSwipeResponder.panHandlers}
206
+ />
207
+ </SafeAreaView>
208
+ </Modal>
209
+ );
210
+ };
211
+
212
+ const styles = StyleSheet.create({
213
+ container: {
214
+ flex: 1,
215
+ backgroundColor: 'white',
216
+ },
217
+ webView: {
218
+ flex: 1,
219
+ },
220
+ backSwipeEdge: {
221
+ position: 'absolute',
222
+ bottom: 0,
223
+ left: 0,
224
+ top: 0,
225
+ width: BACK_SWIPE_EDGE_WIDTH,
226
+ zIndex: 1,
227
+ },
228
+ });
229
+
230
+ export default SecondaryWebView;
@@ -0,0 +1,228 @@
1
+ import {
2
+ Alert,
3
+ Linking,
4
+ NativeModules,
5
+ PermissionsAndroid,
6
+ } from 'react-native';
7
+
8
+ export const NATIVE_LOCATION_RESPONSE_VERSION = 2;
9
+
10
+ export const NATIVE_LOCATION_OPTIONS = {
11
+ maximumAgeMs: 60000,
12
+ timeoutMs: 10000,
13
+ };
14
+
15
+ const isGranted = (result) => result === PermissionsAndroid.RESULTS.GRANTED;
16
+
17
+ const isPermanentlyDenied = (result) =>
18
+ result === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN;
19
+
20
+ const showLocationPermissionAlert = () => {
21
+ Alert.alert(
22
+ 'Permission Required',
23
+ 'Allow location permission from app settings',
24
+ [
25
+ {
26
+ text: 'Cancel',
27
+ },
28
+ {
29
+ text: 'Go to Settings',
30
+ onPress: () => {
31
+ Linking.openSettings();
32
+ },
33
+ },
34
+ ]
35
+ );
36
+ };
37
+
38
+ const getForegroundLocationPermission = async () => {
39
+ const finePermission = PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION;
40
+ const coarsePermission =
41
+ PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION;
42
+
43
+ const [hasFinePermission, hasCoarsePermission] = await Promise.all([
44
+ PermissionsAndroid.check(finePermission),
45
+ PermissionsAndroid.check(coarsePermission),
46
+ ]);
47
+
48
+ if (hasFinePermission || hasCoarsePermission) {
49
+ return {
50
+ granted: true,
51
+ precision: hasFinePermission ? 'precise' : 'approximate',
52
+ permanentlyDenied: false,
53
+ };
54
+ }
55
+
56
+ const results = await PermissionsAndroid.requestMultiple([
57
+ finePermission,
58
+ coarsePermission,
59
+ ]);
60
+ const fineResult = results[finePermission];
61
+ const coarseResult = results[coarsePermission];
62
+ const fineGranted = isGranted(fineResult);
63
+ const coarseGranted = isGranted(coarseResult);
64
+
65
+ return {
66
+ granted: fineGranted || coarseGranted,
67
+ precision: fineGranted ? 'precise' : 'approximate',
68
+ permanentlyDenied:
69
+ !fineGranted &&
70
+ !coarseGranted &&
71
+ (isPermanentlyDenied(fineResult) || isPermanentlyDenied(coarseResult)),
72
+ };
73
+ };
74
+
75
+ const normalizeLocation = (location) => {
76
+ if (!location || typeof location !== 'object') {
77
+ return null;
78
+ }
79
+
80
+ const { latitude, longitude, accuracy, timestamp, precision } = location;
81
+ if (
82
+ !Number.isFinite(latitude) ||
83
+ latitude < -90 ||
84
+ latitude > 90 ||
85
+ !Number.isFinite(longitude) ||
86
+ longitude < -180 ||
87
+ longitude > 180 ||
88
+ !Number.isFinite(accuracy) ||
89
+ accuracy < 0 ||
90
+ !Number.isFinite(timestamp) ||
91
+ (precision !== 'precise' && precision !== 'approximate')
92
+ ) {
93
+ return null;
94
+ }
95
+
96
+ return {
97
+ latitude,
98
+ longitude,
99
+ accuracy,
100
+ timestamp,
101
+ precision,
102
+ source: 'android-fused',
103
+ };
104
+ };
105
+
106
+ export const createGpsPermissionCallbackScript = (
107
+ isAvailable,
108
+ location = null
109
+ ) => {
110
+ // The generated script invokes one of these callback forms:
111
+ // window.checkTheGpsPermission(true);
112
+ // window.checkTheGpsPermission(true, {
113
+ // latitude: 28.5683506,
114
+ // longitude: 77.3163723,
115
+ // accuracy: 100,
116
+ // timestamp: 1788954715833,
117
+ // precision: 'precise',
118
+ // source: 'android-fused',
119
+ // });
120
+ // window.checkTheGpsPermission(false);
121
+ const callbackArguments = isAvailable
122
+ ? location
123
+ ? `true, ${JSON.stringify(location)}`
124
+ : 'true'
125
+ : 'false';
126
+
127
+ return `(function() {
128
+ if (typeof window.checkTheGpsPermission === 'function') {
129
+ console.log(
130
+ '[VisitLocation] invoking checkTheGpsPermission',
131
+ 'isAvailable:', ${Boolean(isAvailable)},
132
+ 'hasLocation:', ${Boolean(location)},
133
+ 'callbackArguments:', ${callbackArguments},
134
+ );
135
+ window.checkTheGpsPermission(${callbackArguments});
136
+ } else {
137
+ console.warn('[VisitLocation] checkTheGpsPermission is not defined');
138
+ }
139
+ return true;
140
+ })();
141
+ true;`;
142
+ };
143
+
144
+ export const requestAndroidLocation = async ({
145
+ webviewRef,
146
+ locationResponseVersion,
147
+ isLoggingEnabled,
148
+ }) => {
149
+ let hasResponded = false;
150
+ const startedAt = Date.now();
151
+ const logTiming = (stage) => {
152
+ if (isLoggingEnabled) {
153
+ console.log(`[VisitLocation] ${stage}: ${Date.now() - startedAt}ms`);
154
+ }
155
+ };
156
+ const respond = (isAvailable, location = null) => {
157
+ if (hasResponded) {
158
+ return;
159
+ }
160
+ hasResponded = true;
161
+ webviewRef.current?.injectJavaScript(
162
+ createGpsPermissionCallbackScript(isAvailable, location)
163
+ );
164
+ };
165
+
166
+ try {
167
+ const permission = await getForegroundLocationPermission();
168
+ logTiming('permission resolved');
169
+
170
+ if (!permission.granted) {
171
+ if (permission.permanentlyDenied) {
172
+ showLocationPermissionAlert();
173
+ }
174
+ respond(false);
175
+ return;
176
+ }
177
+
178
+ const locationModule = NativeModules.VisitLocationModule;
179
+ if (!locationModule?.requestLocationSettings) {
180
+ logTiming('native module unavailable; using WebView fallback');
181
+ respond(true);
182
+ return;
183
+ }
184
+
185
+ let locationSettingsEnabled;
186
+ try {
187
+ locationSettingsEnabled = await locationModule.requestLocationSettings();
188
+ } catch (error) {
189
+ if (isLoggingEnabled) {
190
+ console.warn('[VisitLocation] location settings check failed', error);
191
+ }
192
+ respond(true);
193
+ return;
194
+ }
195
+ logTiming('location settings resolved');
196
+
197
+ if (!locationSettingsEnabled) {
198
+ respond(false);
199
+ return;
200
+ }
201
+
202
+ const supportsNativeLocation =
203
+ Number(locationResponseVersion) >= NATIVE_LOCATION_RESPONSE_VERSION;
204
+ if (!supportsNativeLocation || !locationModule.getCurrentLocation) {
205
+ respond(true);
206
+ return;
207
+ }
208
+
209
+ try {
210
+ const nativeLocation = await locationModule.getCurrentLocation(
211
+ NATIVE_LOCATION_OPTIONS
212
+ );
213
+ const location = normalizeLocation(nativeLocation);
214
+ logTiming('native location resolved');
215
+ respond(true, location);
216
+ } catch (error) {
217
+ if (isLoggingEnabled) {
218
+ console.warn('[VisitLocation] native location failed', error);
219
+ }
220
+ respond(true);
221
+ }
222
+ } catch (error) {
223
+ if (isLoggingEnabled) {
224
+ console.warn('[VisitLocation] permission request failed', error);
225
+ }
226
+ respond(false);
227
+ }
228
+ };