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
@@ -4,7 +4,6 @@ import { EventRegister } from 'react-native-event-listeners';
4
4
  import {
5
5
  SafeAreaView,
6
6
  NativeModules,
7
- PermissionsAndroid,
8
7
  BackHandler,
9
8
  Linking,
10
9
  Alert,
@@ -13,26 +12,39 @@ import {
13
12
  } from 'react-native';
14
13
 
15
14
  import WebView from 'react-native-webview';
16
-
17
- import LocationEnabler from 'react-native-location-enabler';
18
-
19
15
  import DeviceInfo from 'react-native-device-info';
20
16
 
21
17
  import axios from 'axios';
22
18
 
23
19
  import constants from './constants';
20
+ import SecondaryWebView from './SecondaryWebView';
21
+ import { requestAndroidLocation } from './androidLocation';
24
22
 
25
23
  export const httpClient = axios.create({
26
24
  timeout: 60000,
27
25
  });
28
26
 
29
- const messageEmitter = new NativeEventEmitter(NativeModules.VisitFitnessModule);
27
+ // Domains that stay inside the WebView. Matches the host exactly or any of its
28
+ // subdomains. Everything else (wa.me, tel:, mailto: ...) is handed to the OS.
29
+ const INTERNAL_HOSTS = ['getvisitapp.net', 'getvisitapp.com', 'myhubble.money'];
30
+
31
+ // Note: does not use `new URL()` - React Native's URL polyfill throws
32
+ // "URL.hostname is not implemented".
33
+ const isInternalUrl = (url) => {
34
+ const link = typeof url === 'string' ? url.trim() : '';
35
+ const match = /^https?:\/\/([^/?#]+)/i.exec(link);
36
+ if (!match) {
37
+ // about:blank / data: / blob: are rendered by the WebView itself.
38
+ return /^(about|data|blob):/i.test(link);
39
+ }
40
+ // Strip any userinfo and port before comparing.
41
+ const host = match[1].split('@').pop().split(':')[0].toLowerCase();
42
+ return INTERNAL_HOSTS.some(
43
+ (domain) => host === domain || host.endsWith(`.${domain}`)
44
+ );
45
+ };
30
46
 
31
- const {
32
- PRIORITIES: { HIGH_ACCURACY },
33
- useLocationSettings,
34
- addListener,
35
- } = LocationEnabler;
47
+ const messageEmitter = new NativeEventEmitter(NativeModules.VisitFitnessModule);
36
48
 
37
49
  const VisitRnSdkView = ({
38
50
  cpsid,
@@ -45,13 +57,9 @@ const VisitRnSdkView = ({
45
57
  isLoggingEnabled,
46
58
  }) => {
47
59
  const [source, setSource] = useState('');
60
+ const [secondarySource, setSecondarySource] = useState('');
48
61
  const [appState, setAppState] = useState(AppState.currentState);
49
62
 
50
- const [
51
- showPermissionAlreadyDeniedDialog,
52
- setShowPermissionAlreadyDeniedDialog,
53
- ] = useState(false);
54
-
55
63
  useEffect(() => {
56
64
  if (isLoggingEnabled) {
57
65
  console.log('useEffect ran');
@@ -248,6 +256,9 @@ const VisitRnSdkView = ({
248
256
  return () => {
249
257
  subscription.remove();
250
258
  };
259
+ // handleAppStateChange is declared below and only closes over appState,
260
+ // which is already a dependency, so the listener never sees a stale value.
261
+ // eslint-disable-next-line react-hooks/exhaustive-deps
251
262
  }, [appState]); // Include appState in the dependency array to ensure it's up to date.
252
263
 
253
264
  const handleAppStateChange = (nextAppState) => {
@@ -266,96 +277,23 @@ const VisitRnSdkView = ({
266
277
  setAppState(nextAppState); // Update the state with the new app state
267
278
  };
268
279
 
269
- const [enabled, requestResolution] = useLocationSettings(
270
- {
271
- priority: HIGH_ACCURACY, // default BALANCED_POWER_ACCURACY
272
- alwaysShow: true, // default false
273
- needBle: true, // default false
274
- },
275
- false /* optional: default undefined */
276
- );
277
-
278
280
  const webviewRef = useRef(null);
281
+ const locationRequestInFlightRef = useRef(false);
279
282
 
280
- const showLocationPermissionAlert = () => {
281
- Alert.alert(
282
- 'Permission Required',
283
- 'Allow location permission from app settings',
284
- [
285
- {
286
- text: 'Cancel',
287
- onPress: () => {
288
- console.log('Cancel clicked');
289
- },
290
- },
291
- {
292
- text: 'Go to Settings',
293
- onPress: () => {
294
- Linking.openSettings();
295
- },
296
- },
297
- ]
298
- );
299
- };
283
+ const requestLocationPermission = async (locationResponseVersion) => {
284
+ if (locationRequestInFlightRef.current) {
285
+ return;
286
+ }
300
287
 
301
- const requestLocationPermission = async () => {
288
+ locationRequestInFlightRef.current = true;
302
289
  try {
303
- console.log('requestLocationPermission called');
304
-
305
- const isLocationPermissionPresent = await PermissionsAndroid.check(
306
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
307
- );
308
-
309
- console.log(
310
- 'isLocationPermissionPresent: ' +
311
- isLocationPermissionPresent +
312
- ' showPermissionAlreadyDeniedDialog: ' +
313
- showPermissionAlreadyDeniedDialog
314
- );
315
-
316
- if (!isLocationPermissionPresent && showPermissionAlreadyDeniedDialog) {
317
- console.log('showLocationPermissionAlert() called');
318
-
319
- showLocationPermissionAlert();
320
- } else {
321
- console.log('requesting location permission');
322
-
323
- const granted = await PermissionsAndroid.request(
324
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
325
- {
326
- title: 'Need Location Permission',
327
- message: 'Need access to location permission',
328
- buttonNeutral: 'Ask Me Later',
329
- buttonNegative: 'Cancel',
330
- buttonPositive: 'OK',
331
- }
332
- );
333
- if (granted === PermissionsAndroid.RESULTS.GRANTED) {
334
- if (isLoggingEnabled) {
335
- console.log('Location permission granted');
336
- }
337
- setShowPermissionAlreadyDeniedDialog(false);
338
-
339
- if (!enabled) {
340
- requestResolution();
341
- } else {
342
- var finalString = `window.checkTheGpsPermission(true)`;
343
- console.log('requestLocationPermission: ' + finalString);
344
-
345
- webviewRef.current?.injectJavaScript(finalString);
346
- }
347
- } else {
348
- setShowPermissionAlreadyDeniedDialog(true);
349
- console.log('Location permission denied');
350
-
351
- var finalString = `window.checkTheGpsPermission(false)`;
352
- console.log('requestLocationPermission: ' + finalString);
353
-
354
- webviewRef.current?.injectJavaScript(finalString);
355
- }
356
- }
357
- } catch (e) {
358
- console.error(e);
290
+ await requestAndroidLocation({
291
+ webviewRef,
292
+ locationResponseVersion,
293
+ isLoggingEnabled,
294
+ });
295
+ } finally {
296
+ locationRequestInFlightRef.current = false;
359
297
  }
360
298
  };
361
299
 
@@ -590,7 +528,7 @@ const VisitRnSdkView = ({
590
528
  break;
591
529
  case 'GET_LOCATION_PERMISSIONS':
592
530
  console.log('GET_LOCATION_PERMISSIONS');
593
- requestLocationPermission();
531
+ requestLocationPermission(parsedObject.locationResponseVersion);
594
532
  break;
595
533
  case 'OPEN_PDF':
596
534
  {
@@ -600,6 +538,27 @@ const VisitRnSdkView = ({
600
538
  Linking.openURL(pdfUrl);
601
539
  }
602
540
  break;
541
+ case 'OPEN_FACE_SCAN_FLOW':
542
+ EventRegister.emitEvent('visit-event', {
543
+ message: 'OPEN_FACE_SCAN_FLOW',
544
+ });
545
+ break;
546
+ case 'OPEN_SECONDARY_WEB_VIEW':
547
+ {
548
+ const secondaryLink =
549
+ typeof parsedObject.link === 'string'
550
+ ? parsedObject.link.trim()
551
+ : '';
552
+
553
+ if (
554
+ /^https?:\/\/[^\s/?#]+(?:[/?#][^\s]*)?$/i.test(secondaryLink)
555
+ ) {
556
+ setSecondarySource(
557
+ (currentSource) => currentSource || secondaryLink
558
+ );
559
+ }
560
+ }
561
+ break;
603
562
  case 'CLOSE_VIEW':
604
563
  break;
605
564
 
@@ -624,13 +583,6 @@ const VisitRnSdkView = ({
624
583
  }, [canGoBack]);
625
584
 
626
585
  useEffect(() => {
627
- // Subscribe to GPS/location setting changes
628
- const locationSub = addListener(({ locationEnabled }) => {
629
- if (locationEnabled) {
630
- checkLocationPermissionAndSendCallback();
631
- }
632
- });
633
-
634
586
  // Subscribe to Android hardware back press
635
587
  const backSub = BackHandler.addEventListener(
636
588
  'hardwareBackPress',
@@ -640,32 +592,9 @@ const VisitRnSdkView = ({
640
592
  // Cleanup subscriptions on unmount
641
593
  return () => {
642
594
  backSub?.remove();
643
- locationSub?.remove();
644
595
  };
645
596
  }, [handleBack]);
646
597
 
647
- const checkLocationPermissionAndSendCallback = async () => {
648
- const isLocationPermissionAvailable = await PermissionsAndroid.check(
649
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
650
- );
651
-
652
- if (isLoggingEnabled) {
653
- console.log(
654
- 'checkLocationPermissionAndSendCallback() isLocationPermissionAvailable: ' +
655
- isLocationPermissionAvailable +
656
- 'isGPSPermissionAvailabe: true'
657
- );
658
- }
659
-
660
- if (isLocationPermissionAvailable) {
661
- var finalString = `window.checkTheGpsPermission(true)`;
662
-
663
- console.log('listener: ' + finalString);
664
-
665
- webviewRef.current?.injectJavaScript(finalString);
666
- }
667
- };
668
-
669
598
  return (
670
599
  // eslint-disable-next-line react-native/no-inline-styles
671
600
  <SafeAreaView style={{ flex: 1 }}>
@@ -678,9 +607,25 @@ const VisitRnSdkView = ({
678
607
  platform: 'ANDROID',
679
608
  },
680
609
  }}
610
+ onShouldStartLoadWithRequest={(request) => {
611
+ // Sub-frames (iframes) are never handed to the OS.
612
+ if (request.isTopFrame === false) {
613
+ return true;
614
+ }
615
+ if (isInternalUrl(request.url)) {
616
+ return true;
617
+ }
618
+ Linking.openURL(request.url).catch((err) => {
619
+ if (isLoggingEnabled) {
620
+ console.warn('Linking.openURL error: ', err);
621
+ }
622
+ });
623
+ return false;
624
+ }}
681
625
  onMessage={handleMessage}
682
626
  injectedJavaScriptBeforeContentLoaded={runBeforeFirst}
683
627
  javaScriptEnabled={true}
628
+ mediaPlaybackRequiresUserAction={false}
684
629
  onLoadProgress={(event) => setCanGoBack(event.nativeEvent.canGoBack)}
685
630
  onError={(errorMessage) => {
686
631
  EventRegister.emitEvent('visit-event', {
@@ -693,6 +638,13 @@ const VisitRnSdkView = ({
693
638
  }}
694
639
  />
695
640
  ) : null}
641
+ {secondarySource ? (
642
+ <SecondaryWebView
643
+ link={secondarySource}
644
+ isLoggingEnabled={isLoggingEnabled}
645
+ onClose={() => setSecondarySource('')}
646
+ />
647
+ ) : null}
696
648
  </SafeAreaView>
697
649
  );
698
650
  };
package/src/index.ios.js CHANGED
@@ -20,6 +20,8 @@ import { WebView } from 'react-native-webview';
20
20
  import DeviceInfo from 'react-native-device-info';
21
21
  import { getWebViewLink, httpClient } from './Services';
22
22
  import constants from './constants';
23
+ import SecondaryWebView from './SecondaryWebView';
24
+ import { requestIosLocation } from './iosLocation';
23
25
 
24
26
  const LINKING_ERROR =
25
27
  `The package 'react-native-visit-rn-sdk' doesn't seem to be linked. Make sure: \n\n` +
@@ -54,6 +56,26 @@ const unescapeHTML = (str) =>
54
56
 
55
57
  const visitEvent = 'visit-event';
56
58
 
59
+ // Domains that stay inside the WebView. Matches the host exactly or any of its
60
+ // subdomains. Everything else (wa.me, tel:, mailto: ...) is handed to the OS.
61
+ const INTERNAL_HOSTS = ['getvisitapp.net', 'getvisitapp.com', 'myhubble.money'];
62
+
63
+ // Note: does not use `new URL()` - React Native's URL polyfill throws
64
+ // "URL.hostname is not implemented".
65
+ const isInternalUrl = (url) => {
66
+ const link = typeof url === 'string' ? url.trim() : '';
67
+ const match = /^https?:\/\/([^/?#]+)/i.exec(link);
68
+ if (!match) {
69
+ // about:blank / data: / blob: are rendered by the WebView itself.
70
+ return /^(about|data|blob):/i.test(link);
71
+ }
72
+ // Strip any userinfo and port before comparing.
73
+ const host = match[1].split('@').pop().split(':')[0].toLowerCase();
74
+ return INTERNAL_HOSTS.some(
75
+ (domain) => host === domain || host.endsWith(`.${domain}`)
76
+ );
77
+ };
78
+
57
79
  const VisitRnSdkView = ({
58
80
  cpsid,
59
81
  baseUrl,
@@ -66,6 +88,7 @@ const VisitRnSdkView = ({
66
88
  }) => {
67
89
  const [source, setSource] = useState('');
68
90
  const [loading, setLoading] = useState(true);
91
+ const [secondarySource, setSecondarySource] = useState('');
69
92
  useEffect(() => {
70
93
  if (magicLink?.trim()?.length) {
71
94
  setSource(magicLink);
@@ -183,10 +206,28 @@ const VisitRnSdkView = ({
183
206
  );
184
207
 
185
208
  const webviewRef = useRef(null);
209
+ const locationRequestInFlightRef = useRef(false);
186
210
  const [apiBaseUrl, setApiBaseUrl] = useState('');
187
211
  const [authToken, setAuthToken] = useState('');
188
212
  const [hasLoadedOnce, setHasLoadedOnce] = useState(false);
189
213
 
214
+ const requestLocationPermission = async (locationResponseVersion) => {
215
+ if (locationRequestInFlightRef.current) {
216
+ return;
217
+ }
218
+
219
+ locationRequestInFlightRef.current = true;
220
+ try {
221
+ await requestIosLocation({
222
+ webviewRef,
223
+ locationResponseVersion,
224
+ isLoggingEnabled,
225
+ });
226
+ } finally {
227
+ locationRequestInFlightRef.current = false;
228
+ }
229
+ };
230
+
190
231
  const callSyncApi = useCallback(
191
232
  (data) =>
192
233
  httpClient
@@ -244,6 +285,7 @@ const VisitRnSdkView = ({
244
285
  googleFitLastSync,
245
286
  gfHourlyLastSync,
246
287
  url,
288
+ locationResponseVersion,
247
289
  } = data;
248
290
  console.log('handleMessage data is', data);
249
291
  console.log(unescapeHTML(event.nativeEvent.data));
@@ -302,12 +344,27 @@ const VisitRnSdkView = ({
302
344
  case 'OPEN_PDF':
303
345
  Linking.openURL(url);
304
346
  break;
347
+ case 'OPEN_FACE_SCAN_FLOW':
348
+ EventRegister.emitEvent('visit-event', {
349
+ message: 'OPEN_FACE_SCAN_FLOW',
350
+ });
351
+ break;
352
+ case 'OPEN_SECONDARY_WEB_VIEW':
353
+ {
354
+ const secondaryLink =
355
+ typeof data.link === 'string' ? data.link.trim() : '';
356
+
357
+ if (/^https?:\/\/[^\s/?#]+(?:[/?#][^\s]*)?$/i.test(secondaryLink)) {
358
+ setSecondarySource(
359
+ (currentSource) => currentSource || secondaryLink
360
+ );
361
+ }
362
+ }
363
+ break;
305
364
  case 'CLOSE_VIEW':
306
365
  break;
307
366
  case 'GET_LOCATION_PERMISSIONS':
308
- webviewRef.current?.injectJavaScript(
309
- 'window.checkTheGpsPermission(true)'
310
- );
367
+ requestLocationPermission(locationResponseVersion);
311
368
  break;
312
369
 
313
370
  default:
@@ -327,7 +384,23 @@ const VisitRnSdkView = ({
327
384
  source={{ uri: source }}
328
385
  style={styles.webView}
329
386
  javascriptEnabled
387
+ webviewDebuggingEnabled={Boolean(isLoggingEnabled)}
330
388
  onMessage={handleMessage}
389
+ onShouldStartLoadWithRequest={(request) => {
390
+ // Sub-frames (iframes) are never handed to the OS.
391
+ if (request.isTopFrame === false) {
392
+ return true;
393
+ }
394
+ if (isInternalUrl(request.url)) {
395
+ return true;
396
+ }
397
+ Linking.openURL(request.url).catch((err) => {
398
+ if (isLoggingEnabled) {
399
+ console.warn('Linking.openURL error: ', err);
400
+ }
401
+ });
402
+ return false;
403
+ }}
331
404
  onError={(errorMessage) => {
332
405
  EventRegister.emitEvent(visitEvent, {
333
406
  message: 'web-view-error',
@@ -339,6 +412,13 @@ const VisitRnSdkView = ({
339
412
  }}
340
413
  />
341
414
  )}
415
+ {secondarySource ? (
416
+ <SecondaryWebView
417
+ link={secondarySource}
418
+ isLoggingEnabled={isLoggingEnabled}
419
+ onClose={() => setSecondarySource('')}
420
+ />
421
+ ) : null}
342
422
  </SafeAreaView>
343
423
  );
344
424
  };
@@ -0,0 +1,172 @@
1
+ import { Alert, Linking, NativeModules } from 'react-native';
2
+
3
+ export const NATIVE_LOCATION_RESPONSE_VERSION = 2;
4
+
5
+ export const NATIVE_LOCATION_OPTIONS = {
6
+ maximumAgeMs: 60000,
7
+ timeoutMs: 10000,
8
+ };
9
+
10
+ const LOCATION_PERMISSION_ERROR_CODES = new Set([
11
+ 'E_LOCATION_SERVICES_DISABLED',
12
+ 'E_LOCATION_PERMISSION_DENIED',
13
+ 'E_LOCATION_PERMISSION_DENIED_PREVIOUSLY',
14
+ 'E_LOCATION_PERMISSION_RESTRICTED',
15
+ 'E_LOCATION_USAGE_DESCRIPTION_MISSING',
16
+ ]);
17
+
18
+ const showLocationPermissionAlert = () => {
19
+ Alert.alert(
20
+ 'Permission Required',
21
+ 'Allow location permission from app settings',
22
+ [
23
+ {
24
+ text: 'Cancel',
25
+ },
26
+ {
27
+ text: 'Go to Settings',
28
+ onPress: () => {
29
+ Linking.openSettings();
30
+ },
31
+ },
32
+ ]
33
+ );
34
+ };
35
+
36
+ const normalizeLocation = (location) => {
37
+ if (!location || typeof location !== 'object') {
38
+ return null;
39
+ }
40
+
41
+ const { latitude, longitude, accuracy, timestamp, precision } = location;
42
+ if (
43
+ !Number.isFinite(latitude) ||
44
+ latitude < -90 ||
45
+ latitude > 90 ||
46
+ !Number.isFinite(longitude) ||
47
+ longitude < -180 ||
48
+ longitude > 180 ||
49
+ !Number.isFinite(accuracy) ||
50
+ accuracy < 0 ||
51
+ !Number.isFinite(timestamp) ||
52
+ timestamp <= 0 ||
53
+ (precision !== 'precise' && precision !== 'approximate')
54
+ ) {
55
+ return null;
56
+ }
57
+
58
+ return {
59
+ latitude,
60
+ longitude,
61
+ accuracy,
62
+ timestamp,
63
+ precision,
64
+ source: 'ios-core-location',
65
+ };
66
+ };
67
+
68
+ export const createIosGpsPermissionCallbackScript = (
69
+ isAvailable,
70
+ location = null
71
+ ) => {
72
+ // The generated script invokes one of these callback forms:
73
+ // window.checkTheGpsPermission(true);
74
+ // window.checkTheGpsPermission(true, {
75
+ // latitude: 28.5683506,
76
+ // longitude: 77.3163723,
77
+ // accuracy: 100,
78
+ // timestamp: 1788954715833,
79
+ // precision: 'precise',
80
+ // source: 'ios-core-location',
81
+ // });
82
+ // window.checkTheGpsPermission(false);
83
+ const callbackArguments = isAvailable
84
+ ? location
85
+ ? `true, ${JSON.stringify(location)}`
86
+ : 'true'
87
+ : 'false';
88
+
89
+ return `(function() {
90
+ if (typeof window.checkTheGpsPermission === 'function') {
91
+ console.log(
92
+ '[VisitLocation] invoking checkTheGpsPermission',
93
+ 'isAvailable:', ${Boolean(isAvailable)},
94
+ 'hasLocation:', ${Boolean(location)},
95
+ 'callbackArguments:', ${callbackArguments},
96
+ );
97
+ window.checkTheGpsPermission(${callbackArguments});
98
+ } else {
99
+ console.warn('[VisitLocation] checkTheGpsPermission is not defined');
100
+ }
101
+ return true;
102
+ })();
103
+ true;`;
104
+ };
105
+
106
+ export const requestIosLocation = async ({
107
+ webviewRef,
108
+ locationResponseVersion,
109
+ isLoggingEnabled,
110
+ }) => {
111
+ let hasResponded = false;
112
+ const startedAt = Date.now();
113
+ const logTiming = (stage) => {
114
+ if (isLoggingEnabled) {
115
+ console.log(`[VisitLocation] iOS ${stage}: ${Date.now() - startedAt}ms`);
116
+ }
117
+ };
118
+ const respond = (isAvailable, location = null) => {
119
+ if (hasResponded) {
120
+ return;
121
+ }
122
+ hasResponded = true;
123
+ webviewRef.current?.injectJavaScript(
124
+ createIosGpsPermissionCallbackScript(isAvailable, location)
125
+ );
126
+ };
127
+
128
+ const supportsNativeLocation =
129
+ Number(locationResponseVersion) >= NATIVE_LOCATION_RESPONSE_VERSION;
130
+ if (!supportsNativeLocation) {
131
+ respond(true);
132
+ return;
133
+ }
134
+
135
+ const locationModule = NativeModules.VisitLocationModule;
136
+ if (!locationModule?.getCurrentLocation) {
137
+ logTiming('native module unavailable; using WebView fallback');
138
+ respond(true);
139
+ return;
140
+ }
141
+
142
+ try {
143
+ const nativeLocation = await locationModule.getCurrentLocation(
144
+ NATIVE_LOCATION_OPTIONS
145
+ );
146
+ const location = normalizeLocation(nativeLocation);
147
+ logTiming('native location resolved');
148
+
149
+ if (!location && isLoggingEnabled) {
150
+ console.warn(
151
+ '[VisitLocation] iOS native location was invalid; using WebView fallback'
152
+ );
153
+ }
154
+ respond(true, location);
155
+ } catch (error) {
156
+ const errorCode = error?.code;
157
+ if (isLoggingEnabled) {
158
+ console.warn('[VisitLocation] iOS native location failed', errorCode);
159
+ }
160
+
161
+ if (errorCode === 'E_LOCATION_PERMISSION_DENIED_PREVIOUSLY') {
162
+ showLocationPermissionAlert();
163
+ }
164
+
165
+ if (LOCATION_PERMISSION_ERROR_CODES.has(errorCode)) {
166
+ respond(false);
167
+ return;
168
+ }
169
+
170
+ respond(true);
171
+ }
172
+ };
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
- package="com.visitrnsdk" >
4
-
5
- <uses-sdk android:minSdkVersion="21" />
6
-
7
- </manifest>
@@ -1,18 +0,0 @@
1
- {
2
- "version": 3,
3
- "artifactType": {
4
- "type": "AAPT_FRIENDLY_MERGED_MANIFESTS",
5
- "kind": "Directory"
6
- },
7
- "applicationId": "com.visitrnsdk",
8
- "variantName": "debug",
9
- "elements": [
10
- {
11
- "type": "SINGLE",
12
- "filters": [],
13
- "attributes": [],
14
- "outputFile": "AndroidManifest.xml"
15
- }
16
- ],
17
- "elementType": "File"
18
- }
@@ -1,5 +0,0 @@
1
- aarFormatVersion=1.0
2
- aarMetadataVersion=1.0
3
- minCompileSdk=1
4
- minCompileSdkExtension=0
5
- minAndroidGradlePluginVersion=1.0.0