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
package/README.md CHANGED
@@ -18,6 +18,150 @@ import VisitRnSdkView from "react-native-visit-rn-sdk";
18
18
  <VisitRnSdkView magicLink="magic-link" />
19
19
  ```
20
20
 
21
+ Set `isLoggingEnabled={true}` to enable SDK diagnostic logs. On iOS, the same
22
+ flag makes both the primary and secondary WebViews inspectable through Safari's
23
+ Develop menu. Leave the flag `false` or omit it to keep WebView inspection
24
+ disabled.
25
+
26
+ ## Secondary WebView
27
+
28
+ The Android and iOS SDKs can open one full-screen secondary WebView modal while
29
+ keeping the primary WebView mounted in the back stack. Send this message from
30
+ the primary WebView:
31
+
32
+ ```json
33
+ {
34
+ "method": "OPEN_SECONDARY_WEB_VIEW",
35
+ "link": "https://example.com"
36
+ }
37
+ ```
38
+
39
+ `link` must be an absolute HTTP or HTTPS URL. HTTP(S) links and redirects stay
40
+ inside the secondary WebView; other schemes such as `tel:` and `mailto:` are
41
+ passed to the operating system. No native Back header is added on either
42
+ platform. Android's system Back action navigates through the secondary
43
+ WebView's page history before closing it and returning to the preserved primary
44
+ WebView. On iOS, a rightward swipe beginning at the left screen edge performs
45
+ the same history-first Back behavior and closes the secondary WebView when it
46
+ is already at its root.
47
+
48
+ The secondary WebView handles these callbacks:
49
+
50
+ - `OPEN_SECONDARY_WEB_VIEW` (ignored while the single secondary WebView is open)
51
+ - `GET_LOCATION_PERMISSIONS`
52
+ - `OPEN_PDF`
53
+ - `OPEN_FACE_SCAN_FLOW`
54
+ - `CLOSE_VIEW` (immediately closes the secondary WebView)
55
+
56
+ All other web callbacks from the secondary WebView are ignored.
57
+
58
+ ## Android native location handoff
59
+
60
+ Android PWA builds that support native fused location should version the
61
+ location request:
62
+
63
+ ```js
64
+ window.checkTheGpsPermission = (available, location) => {
65
+ if (!available) {
66
+ // Stop loading and show the permission/GPS error state.
67
+ return;
68
+ }
69
+
70
+ if (
71
+ location &&
72
+ Number.isFinite(location.latitude) &&
73
+ Number.isFinite(location.longitude)
74
+ ) {
75
+ // Decode the native coordinates directly. Do not call navigator.geolocation.
76
+ fetchAddress(location.latitude, location.longitude);
77
+ return;
78
+ }
79
+
80
+ // Older Android and iOS SDKs use the existing browser fallback.
81
+ navigator.geolocation.getCurrentPosition(successCallback, failureCallback, {
82
+ timeout: 15000,
83
+ });
84
+ };
85
+
86
+ window.ReactNativeWebView.postMessage(
87
+ JSON.stringify({
88
+ method: 'GET_LOCATION_PERMISSIONS',
89
+ locationResponseVersion: 2,
90
+ })
91
+ );
92
+ ```
93
+
94
+ Define `window.checkTheGpsPermission` before posting the request. A successful
95
+ Android v2 response has this shape:
96
+
97
+ ```js
98
+ window.checkTheGpsPermission(true, {
99
+ latitude: 12.9716,
100
+ longitude: 77.5946,
101
+ accuracy: 8,
102
+ timestamp: 1788940000000,
103
+ precision: 'precise', // or 'approximate'
104
+ source: 'android-fused',
105
+ });
106
+ ```
107
+
108
+ When permission or the device location setting is unavailable, the SDK sends
109
+ `window.checkTheGpsPermission(false)`. When native acquisition fails or times
110
+ out, it sends `window.checkTheGpsPermission(true)` so v2 web builds can fall
111
+ back to `navigator.geolocation`. Requests without `locationResponseVersion: 2`
112
+ keep the legacy one-argument behavior and do not start a fused location request.
113
+
114
+ The Android library declares foreground fine and coarse location permissions.
115
+ It accepts approximate-only grants and uses a fused fix up to 60 seconds old,
116
+ otherwise waiting up to 10 seconds for a high-accuracy fix. The default Google
117
+ Play Services Location dependency is `21.3.0`; host apps can align it with their
118
+ dependency set through the root Gradle extra property:
119
+
120
+ ```gradle
121
+ ext {
122
+ playServicesLocationVersion = "21.3.0"
123
+ }
124
+ ```
125
+
126
+ ## iOS native location handoff
127
+
128
+ iOS uses the same versioned PWA request and callback contract shown above. A
129
+ successful iOS v2 response has this shape:
130
+
131
+ ```js
132
+ window.checkTheGpsPermission(true, {
133
+ latitude: 12.9716,
134
+ longitude: 77.5946,
135
+ accuracy: 8,
136
+ timestamp: 1788940000000,
137
+ precision: 'precise', // or 'approximate'
138
+ source: 'ios-core-location',
139
+ });
140
+ ```
141
+
142
+ The SDK requests foreground When In Use authorization and obtains a one-shot
143
+ location through Core Location. It accepts a cached fix up to 60 seconds old;
144
+ otherwise it waits up to 10 seconds for a location. A valid native payload lets
145
+ the PWA skip `navigator.geolocation`, avoiding the additional WebKit website
146
+ permission prompt.
147
+
148
+ Every consuming iOS app must provide a meaningful location purpose string in
149
+ its application `Info.plist`; an SDK pod cannot supply this text on behalf of
150
+ the host app:
151
+
152
+ ```xml
153
+ <key>NSLocationWhenInUseUsageDescription</key>
154
+ <string>Visit uses your location to find healthcare services available near you.</string>
155
+ ```
156
+
157
+ When authorization is denied/restricted, Location Services are disabled, or
158
+ the purpose string is missing, the SDK sends
159
+ `window.checkTheGpsPermission(false)`. A native acquisition failure or timeout
160
+ sends the bare `window.checkTheGpsPermission(true)` callback so the PWA can use
161
+ its WebView fallback. Requests without `locationResponseVersion: 2` retain the
162
+ legacy bare-`true` behavior and do not start Core Location. No background or
163
+ Always location authorization is requested.
164
+
21
165
  ## Contributing
22
166
 
23
167
  See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
@@ -94,6 +94,7 @@ repositories {
94
94
  }
95
95
 
96
96
  def kotlin_version = getExtOrDefault("kotlinVersion")
97
+ def play_services_location_version = getExtOrDefault("playServicesLocationVersion")
97
98
 
98
99
  dependencies {
99
100
  // For < 0.71, this will be from the local maven repo
@@ -101,6 +102,7 @@ dependencies {
101
102
  //noinspection GradleDynamicVersion
102
103
  implementation "com.facebook.react:react-native:+"
103
104
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
105
+ implementation "com.google.android.gms:play-services-location:$play_services_location_version"
104
106
  }
105
107
 
106
108
  if (isNewArchitectureEnabled()) {
@@ -3,3 +3,4 @@ VisitRnSdk_minSdkVersion=21
3
3
  VisitRnSdk_targetSdkVersion=31
4
4
  VisitRnSdk_compileSdkVersion=31
5
5
  VisitRnSdk_ndkversion=21.4.7075529
6
+ VisitRnSdk_playServicesLocationVersion=21.3.0
@@ -1,3 +1,13 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
2
  package="com.visitrnsdk">
3
+ <uses-permission android:name="android.permission.CAMERA" />
4
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
5
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
6
+
7
+ <uses-feature
8
+ android:name="android.hardware.camera"
9
+ android:required="false" />
10
+ <uses-feature
11
+ android:name="android.hardware.camera.front"
12
+ android:required="false" />
3
13
  </manifest>
@@ -1,2 +1,12 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.CAMERA" />
3
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
4
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
5
+
6
+ <uses-feature
7
+ android:name="android.hardware.camera"
8
+ android:required="false" />
9
+ <uses-feature
10
+ android:name="android.hardware.camera.front"
11
+ android:required="false" />
2
12
  </manifest>
@@ -0,0 +1,349 @@
1
+ package com.visitrnsdk
2
+
3
+ import android.Manifest
4
+ import android.app.Activity
5
+ import android.content.Intent
6
+ import android.content.IntentSender
7
+ import android.content.pm.PackageManager
8
+ import android.location.Location
9
+ import android.os.Handler
10
+ import android.os.Looper
11
+ import com.facebook.react.bridge.Arguments
12
+ import com.facebook.react.bridge.BaseActivityEventListener
13
+ import com.facebook.react.bridge.Promise
14
+ import com.facebook.react.bridge.ReactApplicationContext
15
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
16
+ import com.facebook.react.bridge.ReactMethod
17
+ import com.facebook.react.bridge.ReadableMap
18
+ import com.facebook.react.bridge.UiThreadUtil
19
+ import com.google.android.gms.common.api.ResolvableApiException
20
+ import com.google.android.gms.location.CurrentLocationRequest
21
+ import com.google.android.gms.location.Granularity
22
+ import com.google.android.gms.location.LocationRequest
23
+ import com.google.android.gms.location.LocationServices
24
+ import com.google.android.gms.location.Priority
25
+ import com.google.android.gms.location.LocationSettingsRequest
26
+ import com.google.android.gms.tasks.CancellationTokenSource
27
+
28
+ class VisitLocationModule(
29
+ reactContext: ReactApplicationContext
30
+ ) : ReactContextBaseJavaModule(reactContext) {
31
+
32
+ private val mainHandler = Handler(Looper.getMainLooper())
33
+ private val settingsLock = Any()
34
+ private val locationLock = Any()
35
+ private val pendingSettingsPromises = mutableListOf<Promise>()
36
+ private val pendingLocationPromises = mutableListOf<Promise>()
37
+
38
+ private var settingsResolutionInProgress = false
39
+ private var locationRequestInProgress = false
40
+ private var locationCancellationTokenSource: CancellationTokenSource? = null
41
+ private var locationTimeoutRunnable: Runnable? = null
42
+
43
+ private val activityEventListener = object : BaseActivityEventListener() {
44
+ override fun onActivityResult(
45
+ activity: Activity,
46
+ requestCode: Int,
47
+ resultCode: Int,
48
+ data: Intent?
49
+ ) {
50
+ if (requestCode != REQUEST_LOCATION_SETTINGS) {
51
+ return
52
+ }
53
+
54
+ finishSettingsResolution(resultCode == Activity.RESULT_OK)
55
+ }
56
+ }
57
+
58
+ init {
59
+ reactApplicationContext.addActivityEventListener(activityEventListener)
60
+ }
61
+
62
+ override fun getName(): String = NAME
63
+
64
+ @ReactMethod
65
+ fun requestLocationSettings(promise: Promise) {
66
+ synchronized(settingsLock) {
67
+ if (settingsResolutionInProgress) {
68
+ pendingSettingsPromises.add(promise)
69
+ return
70
+ }
71
+ }
72
+
73
+ val activity = currentActivity
74
+ if (activity == null) {
75
+ promise.reject(ERROR_NO_ACTIVITY, "No foreground Activity is available")
76
+ return
77
+ }
78
+
79
+ val locationRequest = LocationRequest.Builder(
80
+ Priority.PRIORITY_HIGH_ACCURACY,
81
+ LOCATION_SETTINGS_INTERVAL_MS
82
+ ).build()
83
+ val settingsRequest = LocationSettingsRequest.Builder()
84
+ .addLocationRequest(locationRequest)
85
+ .setAlwaysShow(true)
86
+ .build()
87
+
88
+ LocationServices.getSettingsClient(activity)
89
+ .checkLocationSettings(settingsRequest)
90
+ .addOnSuccessListener {
91
+ promise.resolve(true)
92
+ }
93
+ .addOnFailureListener { error ->
94
+ if (error !is ResolvableApiException) {
95
+ promise.resolve(false)
96
+ return@addOnFailureListener
97
+ }
98
+
99
+ var shouldStartResolution = false
100
+ synchronized(settingsLock) {
101
+ pendingSettingsPromises.add(promise)
102
+ if (!settingsResolutionInProgress) {
103
+ settingsResolutionInProgress = true
104
+ shouldStartResolution = true
105
+ }
106
+ }
107
+
108
+ if (shouldStartResolution) {
109
+ UiThreadUtil.runOnUiThread {
110
+ try {
111
+ error.startResolutionForResult(activity, REQUEST_LOCATION_SETTINGS)
112
+ } catch (_: IntentSender.SendIntentException) {
113
+ finishSettingsResolution(false)
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+
120
+ @ReactMethod
121
+ fun getCurrentLocation(options: ReadableMap, promise: Promise) {
122
+ val hasFinePermission = hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)
123
+ val hasCoarsePermission = hasPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
124
+
125
+ if (!hasFinePermission && !hasCoarsePermission) {
126
+ promise.reject(
127
+ ERROR_PERMISSION_DENIED,
128
+ "Foreground location permission has not been granted"
129
+ )
130
+ return
131
+ }
132
+
133
+ synchronized(locationLock) {
134
+ pendingLocationPromises.add(promise)
135
+ if (locationRequestInProgress) {
136
+ return
137
+ }
138
+ locationRequestInProgress = true
139
+ }
140
+
141
+ val maximumAgeMillis = readLongOption(
142
+ options,
143
+ "maximumAgeMs",
144
+ DEFAULT_MAXIMUM_AGE_MS,
145
+ 0L,
146
+ MAXIMUM_ALLOWED_AGE_MS
147
+ )
148
+ val timeoutMillis = readLongOption(
149
+ options,
150
+ "timeoutMs",
151
+ DEFAULT_TIMEOUT_MS,
152
+ MINIMUM_TIMEOUT_MS,
153
+ MAXIMUM_TIMEOUT_MS
154
+ )
155
+ val precision = if (hasFinePermission) PRECISION_PRECISE else PRECISION_APPROXIMATE
156
+
157
+ val currentLocationRequest = CurrentLocationRequest.Builder()
158
+ .setPriority(Priority.PRIORITY_HIGH_ACCURACY)
159
+ .setGranularity(Granularity.GRANULARITY_PERMISSION_LEVEL)
160
+ .setMaxUpdateAgeMillis(maximumAgeMillis)
161
+ .setDurationMillis(timeoutMillis)
162
+ .build()
163
+
164
+ val cancellationTokenSource = CancellationTokenSource()
165
+ locationCancellationTokenSource = cancellationTokenSource
166
+
167
+ val timeoutRunnable = Runnable {
168
+ cancellationTokenSource.cancel()
169
+ finishLocationFailure(
170
+ ERROR_LOCATION_TIMEOUT,
171
+ "Timed out while waiting for the current location"
172
+ )
173
+ }
174
+ locationTimeoutRunnable = timeoutRunnable
175
+ mainHandler.postDelayed(timeoutRunnable, timeoutMillis)
176
+
177
+ try {
178
+ LocationServices.getFusedLocationProviderClient(reactApplicationContext)
179
+ .getCurrentLocation(currentLocationRequest, cancellationTokenSource.token)
180
+ .addOnSuccessListener { location ->
181
+ if (location == null) {
182
+ finishLocationFailure(
183
+ ERROR_LOCATION_UNAVAILABLE,
184
+ "Fused Location Provider returned no location"
185
+ )
186
+ } else if (!isValidLocation(location)) {
187
+ finishLocationFailure(
188
+ ERROR_LOCATION_UNAVAILABLE,
189
+ "Fused Location Provider returned invalid coordinates"
190
+ )
191
+ } else {
192
+ finishLocationSuccess(location, precision)
193
+ }
194
+ }
195
+ .addOnFailureListener { error ->
196
+ finishLocationFailure(
197
+ ERROR_LOCATION_REQUEST_FAILED,
198
+ error.message ?: "Fused Location Provider request failed",
199
+ error
200
+ )
201
+ }
202
+ } catch (error: SecurityException) {
203
+ finishLocationFailure(
204
+ ERROR_PERMISSION_DENIED,
205
+ "Foreground location permission is no longer available",
206
+ error
207
+ )
208
+ } catch (error: Exception) {
209
+ finishLocationFailure(
210
+ ERROR_LOCATION_REQUEST_FAILED,
211
+ error.message ?: "Unable to request the current location",
212
+ error
213
+ )
214
+ }
215
+ }
216
+
217
+ private fun hasPermission(permission: String): Boolean {
218
+ return reactApplicationContext.packageManager.checkPermission(
219
+ permission,
220
+ reactApplicationContext.packageName
221
+ ) == PackageManager.PERMISSION_GRANTED
222
+ }
223
+
224
+ private fun readLongOption(
225
+ options: ReadableMap,
226
+ key: String,
227
+ defaultValue: Long,
228
+ minimumValue: Long,
229
+ maximumValue: Long
230
+ ): Long {
231
+ if (!options.hasKey(key) || options.isNull(key)) {
232
+ return defaultValue
233
+ }
234
+
235
+ return try {
236
+ val value = options.getDouble(key)
237
+ if (value.isFinite()) {
238
+ value.toLong().coerceIn(minimumValue, maximumValue)
239
+ } else {
240
+ defaultValue
241
+ }
242
+ } catch (_: Exception) {
243
+ defaultValue
244
+ }
245
+ }
246
+
247
+ private fun isValidLocation(location: Location): Boolean {
248
+ return location.latitude.isFinite() &&
249
+ location.longitude.isFinite() &&
250
+ location.latitude in -90.0..90.0 &&
251
+ location.longitude in -180.0..180.0
252
+ }
253
+
254
+ private fun finishSettingsResolution(enabled: Boolean) {
255
+ val promises = synchronized(settingsLock) {
256
+ if (!settingsResolutionInProgress && pendingSettingsPromises.isEmpty()) {
257
+ return
258
+ }
259
+
260
+ settingsResolutionInProgress = false
261
+ pendingSettingsPromises.toList().also { pendingSettingsPromises.clear() }
262
+ }
263
+
264
+ promises.forEach { it.resolve(enabled) }
265
+ }
266
+
267
+ private fun finishLocationSuccess(location: Location, precision: String) {
268
+ val promises = takePendingLocationPromises() ?: return
269
+
270
+ promises.forEach { promise ->
271
+ val payload = Arguments.createMap().apply {
272
+ putDouble("latitude", location.latitude)
273
+ putDouble("longitude", location.longitude)
274
+ putDouble("accuracy", location.accuracy.toDouble())
275
+ putDouble("timestamp", location.time.toDouble())
276
+ putString("precision", precision)
277
+ putString("source", LOCATION_SOURCE)
278
+ }
279
+ promise.resolve(payload)
280
+ }
281
+ }
282
+
283
+ private fun finishLocationFailure(
284
+ code: String,
285
+ message: String,
286
+ error: Throwable? = null
287
+ ) {
288
+ val promises = takePendingLocationPromises() ?: return
289
+
290
+ promises.forEach { promise ->
291
+ if (error == null) {
292
+ promise.reject(code, message)
293
+ } else {
294
+ promise.reject(code, message, error)
295
+ }
296
+ }
297
+ }
298
+
299
+ private fun takePendingLocationPromises(): List<Promise>? {
300
+ return synchronized(locationLock) {
301
+ if (!locationRequestInProgress) {
302
+ return@synchronized null
303
+ }
304
+
305
+ locationRequestInProgress = false
306
+ locationTimeoutRunnable?.let { mainHandler.removeCallbacks(it) }
307
+ locationTimeoutRunnable = null
308
+ locationCancellationTokenSource = null
309
+ pendingLocationPromises.toList().also { pendingLocationPromises.clear() }
310
+ }
311
+ }
312
+
313
+ override fun invalidate() {
314
+ locationTimeoutRunnable?.let { mainHandler.removeCallbacks(it) }
315
+ locationCancellationTokenSource?.cancel()
316
+ synchronized(locationLock) {
317
+ locationRequestInProgress = false
318
+ pendingLocationPromises.clear()
319
+ }
320
+ synchronized(settingsLock) {
321
+ settingsResolutionInProgress = false
322
+ pendingSettingsPromises.clear()
323
+ }
324
+ reactApplicationContext.removeActivityEventListener(activityEventListener)
325
+ super.invalidate()
326
+ }
327
+
328
+ companion object {
329
+ const val NAME = "VisitLocationModule"
330
+
331
+ private const val REQUEST_LOCATION_SETTINGS = 48127
332
+ private const val LOCATION_SETTINGS_INTERVAL_MS = 10_000L
333
+ private const val DEFAULT_MAXIMUM_AGE_MS = 60_000L
334
+ private const val DEFAULT_TIMEOUT_MS = 10_000L
335
+ private const val MAXIMUM_ALLOWED_AGE_MS = 300_000L
336
+ private const val MINIMUM_TIMEOUT_MS = 1_000L
337
+ private const val MAXIMUM_TIMEOUT_MS = 60_000L
338
+
339
+ private const val PRECISION_PRECISE = "precise"
340
+ private const val PRECISION_APPROXIMATE = "approximate"
341
+ private const val LOCATION_SOURCE = "android-fused"
342
+
343
+ private const val ERROR_NO_ACTIVITY = "E_NO_ACTIVITY"
344
+ private const val ERROR_PERMISSION_DENIED = "E_LOCATION_PERMISSION_DENIED"
345
+ private const val ERROR_LOCATION_TIMEOUT = "E_LOCATION_TIMEOUT"
346
+ private const val ERROR_LOCATION_UNAVAILABLE = "E_LOCATION_UNAVAILABLE"
347
+ private const val ERROR_LOCATION_REQUEST_FAILED = "E_LOCATION_REQUEST_FAILED"
348
+ }
349
+ }
@@ -8,7 +8,7 @@ import com.facebook.react.uimanager.ViewManager
8
8
 
9
9
  class VisitRnSdkPackage : ReactPackage {
10
10
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
- return emptyList()
11
+ return listOf(VisitLocationModule(reactContext))
12
12
  }
13
13
 
14
14
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
@@ -0,0 +1,6 @@
1
+ #import <CoreLocation/CoreLocation.h>
2
+ #import <React/RCTBridgeModule.h>
3
+
4
+ @interface VisitLocationModule : NSObject <RCTBridgeModule, CLLocationManagerDelegate>
5
+
6
+ @end