react-native-visit-rn-sdk 2.0.13 → 2.0.15

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 (159) 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/Services.js +24 -1
  15. package/lib/commonjs/Services.js.map +1 -1
  16. package/lib/commonjs/androidLocation.js +180 -0
  17. package/lib/commonjs/androidLocation.js.map +1 -0
  18. package/lib/commonjs/index.android.js +89 -120
  19. package/lib/commonjs/index.android.js.map +1 -1
  20. package/lib/commonjs/index.ios.js +77 -14
  21. package/lib/commonjs/index.ios.js.map +1 -1
  22. package/lib/commonjs/iosLocation.js +137 -0
  23. package/lib/commonjs/iosLocation.js.map +1 -0
  24. package/lib/module/SecondaryWebView.android.js +135 -0
  25. package/lib/module/SecondaryWebView.android.js.map +1 -0
  26. package/lib/module/SecondaryWebView.ios.js +201 -0
  27. package/lib/module/SecondaryWebView.ios.js.map +1 -0
  28. package/lib/module/Services.js +22 -0
  29. package/lib/module/Services.js.map +1 -1
  30. package/lib/module/androidLocation.js +170 -0
  31. package/lib/module/androidLocation.js.map +1 -0
  32. package/lib/module/index.android.js +90 -121
  33. package/lib/module/index.android.js.map +1 -1
  34. package/lib/module/index.ios.js +78 -15
  35. package/lib/module/index.ios.js.map +1 -1
  36. package/lib/module/iosLocation.js +127 -0
  37. package/lib/module/iosLocation.js.map +1 -0
  38. package/package.json +7 -3
  39. package/react-native-visit-rn-sdk.podspec +1 -0
  40. package/src/SecondaryWebView.android.js +149 -0
  41. package/src/SecondaryWebView.ios.js +230 -0
  42. package/src/Services.js +29 -0
  43. package/src/androidLocation.js +228 -0
  44. package/src/index.android.js +87 -152
  45. package/src/index.ios.js +86 -22
  46. package/src/iosLocation.js +172 -0
  47. package/android/bin/build/generated/source/buildConfig/debug/com/visitrnsdk/BuildConfig.class +0 -0
  48. package/android/bin/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +0 -7
  49. package/android/bin/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json +0 -18
  50. package/android/bin/build/intermediates/aar_main_jar/debug/classes.jar +0 -0
  51. package/android/bin/build/intermediates/aar_metadata/debug/aar-metadata.properties +0 -5
  52. package/android/bin/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +0 -1
  53. package/android/bin/build/intermediates/annotations_typedef_file/debug/typedefs.txt +0 -0
  54. package/android/bin/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
  55. package/android/bin/build/intermediates/compile_r_class_jar/debug/R.jar +0 -0
  56. package/android/bin/build/intermediates/compile_symbol_list/debug/R.txt +0 -1954
  57. package/android/bin/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +0 -1
  58. package/android/bin/build/intermediates/incremental/debug/packageDebugResources/merger.xml +0 -2
  59. package/android/bin/build/intermediates/incremental/debug-mergeJavaRes/merge-state +0 -0
  60. package/android/bin/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +0 -2
  61. package/android/bin/build/intermediates/incremental/mergeDebugShaders/merger.xml +0 -2
  62. package/android/bin/build/intermediates/incremental/packageDebugAssets/merger.xml +0 -2
  63. package/android/bin/build/intermediates/library_java_res/debug/res.jar +0 -0
  64. package/android/bin/build/intermediates/local_only_symbol_list/debug/R-def.txt +0 -2
  65. package/android/bin/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt +0 -8
  66. package/android/bin/build/intermediates/merged_java_res/debug/feature-react-native-visit-rn-sdk.jar +0 -0
  67. package/android/bin/build/intermediates/merged_manifest/debug/AndroidManifest.xml +0 -7
  68. package/android/bin/build/intermediates/navigation_json/debug/navigation.json +0 -1
  69. package/android/bin/build/intermediates/packaged_manifests/debug/output-metadata.json +0 -18
  70. package/android/bin/build/intermediates/runtime_library_classes_jar/debug/classes.jar +0 -0
  71. package/android/bin/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt +0 -1447
  72. package/android/bin/build/intermediates/variant_model/debug/variant_model.json +0 -0
  73. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
  74. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
  75. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
  76. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
  77. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
  78. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
  79. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i.len +0 -0
  80. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
  81. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
  82. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
  83. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
  84. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
  85. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
  86. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i.len +0 -0
  87. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
  88. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
  89. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
  90. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
  91. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
  92. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
  93. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i.len +0 -0
  94. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
  95. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
  96. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
  97. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
  98. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
  99. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
  100. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i.len +0 -0
  101. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
  102. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
  103. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
  104. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
  105. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
  106. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
  107. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i.len +0 -0
  108. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
  109. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
  110. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
  111. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
  112. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
  113. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
  114. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i.len +0 -0
  115. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
  116. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
  117. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
  118. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
  119. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
  120. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
  121. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i.len +0 -0
  122. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
  123. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
  124. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
  125. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
  126. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
  127. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
  128. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i.len +0 -0
  129. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +0 -2
  130. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
  131. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
  132. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
  133. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
  134. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
  135. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
  136. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i.len +0 -0
  137. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
  138. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
  139. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
  140. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
  141. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
  142. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
  143. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i.len +0 -0
  144. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
  145. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
  146. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
  147. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
  148. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
  149. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
  150. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i.len +0 -0
  151. package/android/bin/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
  152. package/android/bin/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
  153. package/android/bin/build/outputs/aar/react-native-visit-rn-sdk-debug.aar +0 -0
  154. package/android/bin/build/outputs/logs/manifest-merger-debug-report.txt +0 -25
  155. package/android/bin/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  156. package/android/bin/build/tmp/kotlin-classes/debug/META-INF/react-native-visit-rn-sdk_debug.kotlin_module +0 -0
  157. package/android/bin/local.properties +0 -8
  158. package/lib/typescript/index.test.d.ts +0 -1
  159. 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,41 @@ 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';
22
+ import { createGeneratedSsoUrl } from './Services';
25
23
 
26
24
  export const httpClient = axios.create({
27
25
  timeout: 60000,
28
26
  });
29
27
 
30
- const messageEmitter = new NativeEventEmitter(NativeModules.VisitFitnessModule);
28
+ // Domains that stay inside the WebView. Matches the host exactly or any of its
29
+ // subdomains. Everything else (wa.me, tel:, mailto: ...) is handed to the OS.
30
+ const INTERNAL_HOSTS = ['getvisitapp.net', 'getvisitapp.com', 'myhubble.money'];
31
+
32
+ // Note: does not use `new URL()` - React Native's URL polyfill throws
33
+ // "URL.hostname is not implemented".
34
+ const isInternalUrl = (url) => {
35
+ const link = typeof url === 'string' ? url.trim() : '';
36
+ const match = /^https?:\/\/([^/?#]+)/i.exec(link);
37
+ if (!match) {
38
+ // about:blank / data: / blob: are rendered by the WebView itself.
39
+ return /^(about|data|blob):/i.test(link);
40
+ }
41
+ // Strip any userinfo and port before comparing.
42
+ const host = match[1].split('@').pop().split(':')[0].toLowerCase();
43
+ return INTERNAL_HOSTS.some(
44
+ (domain) => host === domain || host.endsWith(`.${domain}`)
45
+ );
46
+ };
31
47
 
32
- const {
33
- PRIORITIES: { HIGH_ACCURACY },
34
- useLocationSettings,
35
- addListener,
36
- } = LocationEnabler;
48
+ const messageEmitter = new NativeEventEmitter(NativeModules.VisitFitnessModule);
37
49
 
38
50
  const VisitRnSdkView = ({
39
51
  cpsid,
@@ -46,13 +58,9 @@ const VisitRnSdkView = ({
46
58
  isLoggingEnabled,
47
59
  }) => {
48
60
  const [source, setSource] = useState('');
61
+ const [secondarySource, setSecondarySource] = useState('');
49
62
  const [appState, setAppState] = useState(AppState.currentState);
50
63
 
51
- const [
52
- showPermissionAlreadyDeniedDialog,
53
- setShowPermissionAlreadyDeniedDialog,
54
- ] = useState(false);
55
-
56
64
  useEffect(() => {
57
65
  if (isLoggingEnabled) {
58
66
  console.log('useEffect ran');
@@ -122,26 +130,14 @@ const VisitRnSdkView = ({
122
130
  finalBaseUrl = constants.STAGE_BASE_URL;
123
131
  }
124
132
 
125
- let finalUrl = `${finalBaseUrl}=${magicCode}`;
126
-
127
133
  if (data.message === 'success') {
128
- if ((moduleName?.trim()?.length || 0) > 0) {
129
- finalUrl += `&tab=${moduleName}`;
130
- }
131
-
132
- if (
133
- typeof responseReferenceId === 'string' &&
134
- responseReferenceId.trim().length > 0
135
- ) {
136
- finalUrl += `&responseReferenceId=${responseReferenceId}`;
137
- }
138
-
139
- if (
140
- typeof otherValues === 'string' &&
141
- otherValues.trim().length > 0
142
- ) {
143
- finalUrl += `&otherValues=${otherValues}`;
144
- }
134
+ const finalUrl = createGeneratedSsoUrl({
135
+ baseUrl: finalBaseUrl,
136
+ magicCode,
137
+ moduleName,
138
+ responseReferenceId,
139
+ otherValues,
140
+ });
145
141
 
146
142
  if (isLoggingEnabled) {
147
143
  console.log('magicLink: ' + finalUrl);
@@ -249,6 +245,9 @@ const VisitRnSdkView = ({
249
245
  return () => {
250
246
  subscription.remove();
251
247
  };
248
+ // handleAppStateChange is declared below and only closes over appState,
249
+ // which is already a dependency, so the listener never sees a stale value.
250
+ // eslint-disable-next-line react-hooks/exhaustive-deps
252
251
  }, [appState]); // Include appState in the dependency array to ensure it's up to date.
253
252
 
254
253
  const handleAppStateChange = (nextAppState) => {
@@ -267,96 +266,23 @@ const VisitRnSdkView = ({
267
266
  setAppState(nextAppState); // Update the state with the new app state
268
267
  };
269
268
 
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
269
  const webviewRef = useRef(null);
270
+ const locationRequestInFlightRef = useRef(false);
280
271
 
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
- };
272
+ const requestLocationPermission = async (locationResponseVersion) => {
273
+ if (locationRequestInFlightRef.current) {
274
+ return;
275
+ }
301
276
 
302
- const requestLocationPermission = async () => {
277
+ locationRequestInFlightRef.current = true;
303
278
  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);
279
+ await requestAndroidLocation({
280
+ webviewRef,
281
+ locationResponseVersion,
282
+ isLoggingEnabled,
283
+ });
284
+ } finally {
285
+ locationRequestInFlightRef.current = false;
360
286
  }
361
287
  };
362
288
 
@@ -591,7 +517,7 @@ const VisitRnSdkView = ({
591
517
  break;
592
518
  case 'GET_LOCATION_PERMISSIONS':
593
519
  console.log('GET_LOCATION_PERMISSIONS');
594
- requestLocationPermission();
520
+ requestLocationPermission(parsedObject.locationResponseVersion);
595
521
  break;
596
522
  case 'OPEN_PDF':
597
523
  {
@@ -606,6 +532,22 @@ const VisitRnSdkView = ({
606
532
  message: 'OPEN_FACE_SCAN_FLOW',
607
533
  });
608
534
  break;
535
+ case 'OPEN_SECONDARY_WEB_VIEW':
536
+ {
537
+ const secondaryLink =
538
+ typeof parsedObject.link === 'string'
539
+ ? parsedObject.link.trim()
540
+ : '';
541
+
542
+ if (
543
+ /^https?:\/\/[^\s/?#]+(?:[/?#][^\s]*)?$/i.test(secondaryLink)
544
+ ) {
545
+ setSecondarySource(
546
+ (currentSource) => currentSource || secondaryLink
547
+ );
548
+ }
549
+ }
550
+ break;
609
551
  case 'CLOSE_VIEW':
610
552
  break;
611
553
 
@@ -630,13 +572,6 @@ const VisitRnSdkView = ({
630
572
  }, [canGoBack]);
631
573
 
632
574
  useEffect(() => {
633
- // Subscribe to GPS/location setting changes
634
- const locationSub = addListener(({ locationEnabled }) => {
635
- if (locationEnabled) {
636
- checkLocationPermissionAndSendCallback();
637
- }
638
- });
639
-
640
575
  // Subscribe to Android hardware back press
641
576
  const backSub = BackHandler.addEventListener(
642
577
  'hardwareBackPress',
@@ -646,32 +581,9 @@ const VisitRnSdkView = ({
646
581
  // Cleanup subscriptions on unmount
647
582
  return () => {
648
583
  backSub?.remove();
649
- locationSub?.remove();
650
584
  };
651
585
  }, [handleBack]);
652
586
 
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
587
  return (
676
588
  // eslint-disable-next-line react-native/no-inline-styles
677
589
  <SafeAreaView style={{ flex: 1 }}>
@@ -684,9 +596,25 @@ const VisitRnSdkView = ({
684
596
  platform: 'ANDROID',
685
597
  },
686
598
  }}
599
+ onShouldStartLoadWithRequest={(request) => {
600
+ // Sub-frames (iframes) are never handed to the OS.
601
+ if (request.isTopFrame === false) {
602
+ return true;
603
+ }
604
+ if (isInternalUrl(request.url)) {
605
+ return true;
606
+ }
607
+ Linking.openURL(request.url).catch((err) => {
608
+ if (isLoggingEnabled) {
609
+ console.warn('Linking.openURL error: ', err);
610
+ }
611
+ });
612
+ return false;
613
+ }}
687
614
  onMessage={handleMessage}
688
615
  injectedJavaScriptBeforeContentLoaded={runBeforeFirst}
689
616
  javaScriptEnabled={true}
617
+ mediaPlaybackRequiresUserAction={false}
690
618
  onLoadProgress={(event) => setCanGoBack(event.nativeEvent.canGoBack)}
691
619
  onError={(errorMessage) => {
692
620
  EventRegister.emitEvent('visit-event', {
@@ -699,6 +627,13 @@ const VisitRnSdkView = ({
699
627
  }}
700
628
  />
701
629
  ) : null}
630
+ {secondarySource ? (
631
+ <SecondaryWebView
632
+ link={secondarySource}
633
+ isLoggingEnabled={isLoggingEnabled}
634
+ onClose={() => setSecondarySource('')}
635
+ />
636
+ ) : null}
702
637
  </SafeAreaView>
703
638
  );
704
639
  };
package/src/index.ios.js CHANGED
@@ -18,8 +18,10 @@ import {
18
18
  import { EventRegister } from 'react-native-event-listeners';
19
19
  import { WebView } from 'react-native-webview';
20
20
  import DeviceInfo from 'react-native-device-info';
21
- import { getWebViewLink, httpClient } from './Services';
21
+ import { createGeneratedSsoUrl, 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);
@@ -117,24 +140,13 @@ const VisitRnSdkView = ({
117
140
  }
118
141
  }
119
142
  if (finalBaseUrl && magicCode) {
120
- let finalUrl = `${finalBaseUrl}=${magicCode}`;
121
- if (moduleName?.trim()) {
122
- finalUrl += `&tab=${moduleName}`;
123
- }
124
-
125
- if (
126
- typeof responseReferenceId === 'string' &&
127
- responseReferenceId.trim().length > 0
128
- ) {
129
- finalUrl += `&responseReferenceId=${responseReferenceId}`;
130
- }
131
-
132
- if (
133
- typeof otherValues === 'string' &&
134
- otherValues.trim().length > 0
135
- ) {
136
- finalUrl += `&otherValues=${otherValues}`;
137
- }
143
+ const finalUrl = createGeneratedSsoUrl({
144
+ baseUrl: finalBaseUrl,
145
+ magicCode,
146
+ moduleName,
147
+ responseReferenceId,
148
+ otherValues,
149
+ });
138
150
 
139
151
  setSource(finalUrl);
140
152
  }
@@ -183,10 +195,28 @@ const VisitRnSdkView = ({
183
195
  );
184
196
 
185
197
  const webviewRef = useRef(null);
198
+ const locationRequestInFlightRef = useRef(false);
186
199
  const [apiBaseUrl, setApiBaseUrl] = useState('');
187
200
  const [authToken, setAuthToken] = useState('');
188
201
  const [hasLoadedOnce, setHasLoadedOnce] = useState(false);
189
202
 
203
+ const requestLocationPermission = async (locationResponseVersion) => {
204
+ if (locationRequestInFlightRef.current) {
205
+ return;
206
+ }
207
+
208
+ locationRequestInFlightRef.current = true;
209
+ try {
210
+ await requestIosLocation({
211
+ webviewRef,
212
+ locationResponseVersion,
213
+ isLoggingEnabled,
214
+ });
215
+ } finally {
216
+ locationRequestInFlightRef.current = false;
217
+ }
218
+ };
219
+
190
220
  const callSyncApi = useCallback(
191
221
  (data) =>
192
222
  httpClient
@@ -244,6 +274,7 @@ const VisitRnSdkView = ({
244
274
  googleFitLastSync,
245
275
  gfHourlyLastSync,
246
276
  url,
277
+ locationResponseVersion,
247
278
  } = data;
248
279
  console.log('handleMessage data is', data);
249
280
  console.log(unescapeHTML(event.nativeEvent.data));
@@ -307,12 +338,22 @@ const VisitRnSdkView = ({
307
338
  message: 'OPEN_FACE_SCAN_FLOW',
308
339
  });
309
340
  break;
341
+ case 'OPEN_SECONDARY_WEB_VIEW':
342
+ {
343
+ const secondaryLink =
344
+ typeof data.link === 'string' ? data.link.trim() : '';
345
+
346
+ if (/^https?:\/\/[^\s/?#]+(?:[/?#][^\s]*)?$/i.test(secondaryLink)) {
347
+ setSecondarySource(
348
+ (currentSource) => currentSource || secondaryLink
349
+ );
350
+ }
351
+ }
352
+ break;
310
353
  case 'CLOSE_VIEW':
311
354
  break;
312
355
  case 'GET_LOCATION_PERMISSIONS':
313
- webviewRef.current?.injectJavaScript(
314
- 'window.checkTheGpsPermission(true)'
315
- );
356
+ requestLocationPermission(locationResponseVersion);
316
357
  break;
317
358
 
318
359
  default:
@@ -332,7 +373,23 @@ const VisitRnSdkView = ({
332
373
  source={{ uri: source }}
333
374
  style={styles.webView}
334
375
  javascriptEnabled
376
+ webviewDebuggingEnabled={Boolean(isLoggingEnabled)}
335
377
  onMessage={handleMessage}
378
+ onShouldStartLoadWithRequest={(request) => {
379
+ // Sub-frames (iframes) are never handed to the OS.
380
+ if (request.isTopFrame === false) {
381
+ return true;
382
+ }
383
+ if (isInternalUrl(request.url)) {
384
+ return true;
385
+ }
386
+ Linking.openURL(request.url).catch((err) => {
387
+ if (isLoggingEnabled) {
388
+ console.warn('Linking.openURL error: ', err);
389
+ }
390
+ });
391
+ return false;
392
+ }}
336
393
  onError={(errorMessage) => {
337
394
  EventRegister.emitEvent(visitEvent, {
338
395
  message: 'web-view-error',
@@ -344,6 +401,13 @@ const VisitRnSdkView = ({
344
401
  }}
345
402
  />
346
403
  )}
404
+ {secondarySource ? (
405
+ <SecondaryWebView
406
+ link={secondarySource}
407
+ isLoggingEnabled={isLoggingEnabled}
408
+ onClose={() => setSecondarySource('')}
409
+ />
410
+ ) : null}
347
411
  </SafeAreaView>
348
412
  );
349
413
  };
@@ -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>