react-native-visit-rn-sdk 2.0.13 → 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 +81 -109
  17. package/lib/commonjs/index.android.js.map +1 -1
  18. package/lib/commonjs/index.ios.js +70 -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 +82 -110
  29. package/lib/module/index.android.js.map +1 -1
  30. package/lib/module/index.ios.js +70 -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 +79 -133
  40. package/src/index.ios.js +78 -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,
@@ -12,28 +11,40 @@ import {
12
11
  NativeEventEmitter,
13
12
  } from 'react-native';
14
13
 
15
-
16
14
  import WebView from 'react-native-webview';
17
-
18
- import LocationEnabler from 'react-native-location-enabler';
19
-
20
15
  import DeviceInfo from 'react-native-device-info';
21
16
 
22
17
  import axios from 'axios';
23
18
 
24
19
  import constants from './constants';
20
+ import SecondaryWebView from './SecondaryWebView';
21
+ import { requestAndroidLocation } from './androidLocation';
25
22
 
26
23
  export const httpClient = axios.create({
27
24
  timeout: 60000,
28
25
  });
29
26
 
30
- 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
+ };
31
46
 
32
- const {
33
- PRIORITIES: { HIGH_ACCURACY },
34
- useLocationSettings,
35
- addListener,
36
- } = LocationEnabler;
47
+ const messageEmitter = new NativeEventEmitter(NativeModules.VisitFitnessModule);
37
48
 
38
49
  const VisitRnSdkView = ({
39
50
  cpsid,
@@ -46,13 +57,9 @@ const VisitRnSdkView = ({
46
57
  isLoggingEnabled,
47
58
  }) => {
48
59
  const [source, setSource] = useState('');
60
+ const [secondarySource, setSecondarySource] = useState('');
49
61
  const [appState, setAppState] = useState(AppState.currentState);
50
62
 
51
- const [
52
- showPermissionAlreadyDeniedDialog,
53
- setShowPermissionAlreadyDeniedDialog,
54
- ] = useState(false);
55
-
56
63
  useEffect(() => {
57
64
  if (isLoggingEnabled) {
58
65
  console.log('useEffect ran');
@@ -249,6 +256,9 @@ const VisitRnSdkView = ({
249
256
  return () => {
250
257
  subscription.remove();
251
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
252
262
  }, [appState]); // Include appState in the dependency array to ensure it's up to date.
253
263
 
254
264
  const handleAppStateChange = (nextAppState) => {
@@ -267,96 +277,23 @@ const VisitRnSdkView = ({
267
277
  setAppState(nextAppState); // Update the state with the new app state
268
278
  };
269
279
 
270
- const [enabled, requestResolution] = useLocationSettings(
271
- {
272
- priority: HIGH_ACCURACY, // default BALANCED_POWER_ACCURACY
273
- alwaysShow: true, // default false
274
- needBle: true, // default false
275
- },
276
- false /* optional: default undefined */
277
- );
278
-
279
280
  const webviewRef = useRef(null);
281
+ const locationRequestInFlightRef = useRef(false);
280
282
 
281
- const showLocationPermissionAlert = () => {
282
- Alert.alert(
283
- 'Permission Required',
284
- 'Allow location permission from app settings',
285
- [
286
- {
287
- text: 'Cancel',
288
- onPress: () => {
289
- console.log('Cancel clicked');
290
- },
291
- },
292
- {
293
- text: 'Go to Settings',
294
- onPress: () => {
295
- Linking.openSettings();
296
- },
297
- },
298
- ]
299
- );
300
- };
283
+ const requestLocationPermission = async (locationResponseVersion) => {
284
+ if (locationRequestInFlightRef.current) {
285
+ return;
286
+ }
301
287
 
302
- const requestLocationPermission = async () => {
288
+ locationRequestInFlightRef.current = true;
303
289
  try {
304
- console.log('requestLocationPermission called');
305
-
306
- const isLocationPermissionPresent = await PermissionsAndroid.check(
307
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
308
- );
309
-
310
- console.log(
311
- 'isLocationPermissionPresent: ' +
312
- isLocationPermissionPresent +
313
- ' showPermissionAlreadyDeniedDialog: ' +
314
- showPermissionAlreadyDeniedDialog
315
- );
316
-
317
- if (!isLocationPermissionPresent && showPermissionAlreadyDeniedDialog) {
318
- console.log('showLocationPermissionAlert() called');
319
-
320
- showLocationPermissionAlert();
321
- } else {
322
- console.log('requesting location permission');
323
-
324
- const granted = await PermissionsAndroid.request(
325
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
326
- {
327
- title: 'Need Location Permission',
328
- message: 'Need access to location permission',
329
- buttonNeutral: 'Ask Me Later',
330
- buttonNegative: 'Cancel',
331
- buttonPositive: 'OK',
332
- }
333
- );
334
- if (granted === PermissionsAndroid.RESULTS.GRANTED) {
335
- if (isLoggingEnabled) {
336
- console.log('Location permission granted');
337
- }
338
- setShowPermissionAlreadyDeniedDialog(false);
339
-
340
- if (!enabled) {
341
- requestResolution();
342
- } else {
343
- var finalString = `window.checkTheGpsPermission(true)`;
344
- console.log('requestLocationPermission: ' + finalString);
345
-
346
- webviewRef.current?.injectJavaScript(finalString);
347
- }
348
- } else {
349
- setShowPermissionAlreadyDeniedDialog(true);
350
- console.log('Location permission denied');
351
-
352
- var finalString = `window.checkTheGpsPermission(false)`;
353
- console.log('requestLocationPermission: ' + finalString);
354
-
355
- webviewRef.current?.injectJavaScript(finalString);
356
- }
357
- }
358
- } catch (e) {
359
- console.error(e);
290
+ await requestAndroidLocation({
291
+ webviewRef,
292
+ locationResponseVersion,
293
+ isLoggingEnabled,
294
+ });
295
+ } finally {
296
+ locationRequestInFlightRef.current = false;
360
297
  }
361
298
  };
362
299
 
@@ -591,7 +528,7 @@ const VisitRnSdkView = ({
591
528
  break;
592
529
  case 'GET_LOCATION_PERMISSIONS':
593
530
  console.log('GET_LOCATION_PERMISSIONS');
594
- requestLocationPermission();
531
+ requestLocationPermission(parsedObject.locationResponseVersion);
595
532
  break;
596
533
  case 'OPEN_PDF':
597
534
  {
@@ -606,6 +543,22 @@ const VisitRnSdkView = ({
606
543
  message: 'OPEN_FACE_SCAN_FLOW',
607
544
  });
608
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;
609
562
  case 'CLOSE_VIEW':
610
563
  break;
611
564
 
@@ -630,13 +583,6 @@ const VisitRnSdkView = ({
630
583
  }, [canGoBack]);
631
584
 
632
585
  useEffect(() => {
633
- // Subscribe to GPS/location setting changes
634
- const locationSub = addListener(({ locationEnabled }) => {
635
- if (locationEnabled) {
636
- checkLocationPermissionAndSendCallback();
637
- }
638
- });
639
-
640
586
  // Subscribe to Android hardware back press
641
587
  const backSub = BackHandler.addEventListener(
642
588
  'hardwareBackPress',
@@ -646,32 +592,9 @@ const VisitRnSdkView = ({
646
592
  // Cleanup subscriptions on unmount
647
593
  return () => {
648
594
  backSub?.remove();
649
- locationSub?.remove();
650
595
  };
651
596
  }, [handleBack]);
652
597
 
653
- const checkLocationPermissionAndSendCallback = async () => {
654
- const isLocationPermissionAvailable = await PermissionsAndroid.check(
655
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
656
- );
657
-
658
- if (isLoggingEnabled) {
659
- console.log(
660
- 'checkLocationPermissionAndSendCallback() isLocationPermissionAvailable: ' +
661
- isLocationPermissionAvailable +
662
- 'isGPSPermissionAvailabe: true'
663
- );
664
- }
665
-
666
- if (isLocationPermissionAvailable) {
667
- var finalString = `window.checkTheGpsPermission(true)`;
668
-
669
- console.log('listener: ' + finalString);
670
-
671
- webviewRef.current?.injectJavaScript(finalString);
672
- }
673
- };
674
-
675
598
  return (
676
599
  // eslint-disable-next-line react-native/no-inline-styles
677
600
  <SafeAreaView style={{ flex: 1 }}>
@@ -684,9 +607,25 @@ const VisitRnSdkView = ({
684
607
  platform: 'ANDROID',
685
608
  },
686
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
+ }}
687
625
  onMessage={handleMessage}
688
626
  injectedJavaScriptBeforeContentLoaded={runBeforeFirst}
689
627
  javaScriptEnabled={true}
628
+ mediaPlaybackRequiresUserAction={false}
690
629
  onLoadProgress={(event) => setCanGoBack(event.nativeEvent.canGoBack)}
691
630
  onError={(errorMessage) => {
692
631
  EventRegister.emitEvent('visit-event', {
@@ -699,6 +638,13 @@ const VisitRnSdkView = ({
699
638
  }}
700
639
  />
701
640
  ) : null}
641
+ {secondarySource ? (
642
+ <SecondaryWebView
643
+ link={secondarySource}
644
+ isLoggingEnabled={isLoggingEnabled}
645
+ onClose={() => setSecondarySource('')}
646
+ />
647
+ ) : null}
702
648
  </SafeAreaView>
703
649
  );
704
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));
@@ -307,12 +349,22 @@ const VisitRnSdkView = ({
307
349
  message: 'OPEN_FACE_SCAN_FLOW',
308
350
  });
309
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;
310
364
  case 'CLOSE_VIEW':
311
365
  break;
312
366
  case 'GET_LOCATION_PERMISSIONS':
313
- webviewRef.current?.injectJavaScript(
314
- 'window.checkTheGpsPermission(true)'
315
- );
367
+ requestLocationPermission(locationResponseVersion);
316
368
  break;
317
369
 
318
370
  default:
@@ -332,7 +384,23 @@ const VisitRnSdkView = ({
332
384
  source={{ uri: source }}
333
385
  style={styles.webView}
334
386
  javascriptEnabled
387
+ webviewDebuggingEnabled={Boolean(isLoggingEnabled)}
335
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
+ }}
336
404
  onError={(errorMessage) => {
337
405
  EventRegister.emitEvent(visitEvent, {
338
406
  message: 'web-view-error',
@@ -344,6 +412,13 @@ const VisitRnSdkView = ({
344
412
  }}
345
413
  />
346
414
  )}
415
+ {secondarySource ? (
416
+ <SecondaryWebView
417
+ link={secondarySource}
418
+ isLoggingEnabled={isLoggingEnabled}
419
+ onClose={() => setSecondarySource('')}
420
+ />
421
+ ) : null}
347
422
  </SafeAreaView>
348
423
  );
349
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