react-native-okhi 1.2.31 → 1.2.32-beta.2

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 (151) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +34 -4
  3. package/ReactNativeOkhi.podspec +21 -0
  4. package/android/build.gradle +38 -99
  5. package/android/gradle.properties +3 -3
  6. package/android/src/main/AndroidManifest.xml +1 -3
  7. package/android/src/main/java/com/okhi/OkhiModule.kt +336 -0
  8. package/android/src/main/java/com/okhi/OkhiPackage.kt +33 -0
  9. package/ios/OkHiWrapper.swift +348 -0
  10. package/ios/Okhi.h +5 -0
  11. package/ios/Okhi.mm +170 -0
  12. package/lib/commonjs/NativeOkhi.js +9 -0
  13. package/lib/commonjs/NativeOkhi.js.map +1 -0
  14. package/lib/commonjs/index.js +234 -28
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/package.json +1 -0
  17. package/lib/commonjs/types.js.map +1 -0
  18. package/lib/module/NativeOkhi.js +5 -0
  19. package/lib/module/NativeOkhi.js.map +1 -0
  20. package/lib/module/index.js +221 -3
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/package.json +1 -0
  23. package/lib/module/types.js +2 -0
  24. package/lib/module/types.js.map +1 -0
  25. package/lib/typescript/commonjs/package.json +1 -0
  26. package/lib/typescript/commonjs/src/NativeOkhi.d.ts +25 -0
  27. package/lib/typescript/commonjs/src/NativeOkhi.d.ts.map +1 -0
  28. package/lib/typescript/commonjs/src/index.d.ts +22 -0
  29. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  30. package/lib/typescript/commonjs/src/types.d.ts +81 -0
  31. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  32. package/lib/typescript/module/package.json +1 -0
  33. package/lib/typescript/module/src/NativeOkhi.d.ts +25 -0
  34. package/lib/typescript/module/src/NativeOkhi.d.ts.map +1 -0
  35. package/lib/typescript/module/src/index.d.ts +22 -0
  36. package/lib/typescript/module/src/index.d.ts.map +1 -0
  37. package/lib/typescript/module/src/types.d.ts +81 -0
  38. package/lib/typescript/module/src/types.d.ts.map +1 -0
  39. package/package.json +91 -112
  40. package/src/NativeOkhi.ts +68 -0
  41. package/src/index.tsx +271 -3
  42. package/src/types.ts +90 -0
  43. package/android/src/main/java/com/reactnativeokhi/OkhiModule.java +0 -389
  44. package/android/src/main/java/com/reactnativeokhi/OkhiPackage.java +0 -28
  45. package/ios/OkHiExtension.swift +0 -27
  46. package/ios/OkHiStruct.swift +0 -29
  47. package/ios/Okhi-Bridging-Header.h +0 -3
  48. package/ios/Okhi.m +0 -62
  49. package/ios/Okhi.swift +0 -325
  50. package/ios/Okhi.xcodeproj/project.pbxproj +0 -283
  51. package/lib/commonjs/OkCollect/Helpers.js +0 -40
  52. package/lib/commonjs/OkCollect/Helpers.js.map +0 -1
  53. package/lib/commonjs/OkCollect/OkHiLocationManager.js +0 -305
  54. package/lib/commonjs/OkCollect/OkHiLocationManager.js.map +0 -1
  55. package/lib/commonjs/OkCollect/Spinner.js +0 -27
  56. package/lib/commonjs/OkCollect/Spinner.js.map +0 -1
  57. package/lib/commonjs/OkCollect/Util.js +0 -226
  58. package/lib/commonjs/OkCollect/Util.js.map +0 -1
  59. package/lib/commonjs/OkCollect/app.json +0 -4
  60. package/lib/commonjs/OkCollect/index.js +0 -47
  61. package/lib/commonjs/OkCollect/index.js.map +0 -1
  62. package/lib/commonjs/OkCollect/types.js +0 -6
  63. package/lib/commonjs/OkCollect/types.js.map +0 -1
  64. package/lib/commonjs/OkCore/Helpers.js +0 -386
  65. package/lib/commonjs/OkCore/Helpers.js.map +0 -1
  66. package/lib/commonjs/OkCore/OkHiException.js +0 -96
  67. package/lib/commonjs/OkCore/OkHiException.js.map +0 -1
  68. package/lib/commonjs/OkCore/OkHiMode.js +0 -14
  69. package/lib/commonjs/OkCore/OkHiMode.js.map +0 -1
  70. package/lib/commonjs/OkCore/_helpers.js +0 -41
  71. package/lib/commonjs/OkCore/_helpers.js.map +0 -1
  72. package/lib/commonjs/OkCore/_types.js +0 -2
  73. package/lib/commonjs/OkCore/_types.js.map +0 -1
  74. package/lib/commonjs/OkCore/index.js +0 -119
  75. package/lib/commonjs/OkCore/index.js.map +0 -1
  76. package/lib/commonjs/OkCore/types.js +0 -6
  77. package/lib/commonjs/OkCore/types.js.map +0 -1
  78. package/lib/commonjs/OkHiNativeModule/index.js +0 -19
  79. package/lib/commonjs/OkHiNativeModule/index.js.map +0 -1
  80. package/lib/commonjs/OkVerify/index.js +0 -211
  81. package/lib/commonjs/OkVerify/index.js.map +0 -1
  82. package/lib/commonjs/OkVerify/types.js.map +0 -1
  83. package/lib/module/OkCollect/Helpers.js +0 -34
  84. package/lib/module/OkCollect/Helpers.js.map +0 -1
  85. package/lib/module/OkCollect/OkHiLocationManager.js +0 -298
  86. package/lib/module/OkCollect/OkHiLocationManager.js.map +0 -1
  87. package/lib/module/OkCollect/Spinner.js +0 -20
  88. package/lib/module/OkCollect/Spinner.js.map +0 -1
  89. package/lib/module/OkCollect/Util.js +0 -214
  90. package/lib/module/OkCollect/Util.js.map +0 -1
  91. package/lib/module/OkCollect/app.json +0 -4
  92. package/lib/module/OkCollect/index.js +0 -4
  93. package/lib/module/OkCollect/index.js.map +0 -1
  94. package/lib/module/OkCollect/types.js +0 -2
  95. package/lib/module/OkCollect/types.js.map +0 -1
  96. package/lib/module/OkCore/Helpers.js +0 -363
  97. package/lib/module/OkCore/Helpers.js.map +0 -1
  98. package/lib/module/OkCore/OkHiException.js +0 -89
  99. package/lib/module/OkCore/OkHiException.js.map +0 -1
  100. package/lib/module/OkCore/OkHiMode.js +0 -8
  101. package/lib/module/OkCore/OkHiMode.js.map +0 -1
  102. package/lib/module/OkCore/_helpers.js +0 -34
  103. package/lib/module/OkCore/_helpers.js.map +0 -1
  104. package/lib/module/OkCore/_types.js +0 -2
  105. package/lib/module/OkCore/_types.js.map +0 -1
  106. package/lib/module/OkCore/index.js +0 -65
  107. package/lib/module/OkCore/index.js.map +0 -1
  108. package/lib/module/OkCore/types.js +0 -2
  109. package/lib/module/OkCore/types.js.map +0 -1
  110. package/lib/module/OkHiNativeModule/index.js +0 -13
  111. package/lib/module/OkHiNativeModule/index.js.map +0 -1
  112. package/lib/module/OkVerify/index.js +0 -195
  113. package/lib/module/OkVerify/index.js.map +0 -1
  114. package/lib/module/OkVerify/types.js +0 -2
  115. package/lib/module/OkVerify/types.js.map +0 -1
  116. package/lib/typescript/OkCollect/Helpers.d.ts +0 -9
  117. package/lib/typescript/OkCollect/OkHiLocationManager.d.ts +0 -7
  118. package/lib/typescript/OkCollect/Spinner.d.ts +0 -5
  119. package/lib/typescript/OkCollect/Util.d.ts +0 -31
  120. package/lib/typescript/OkCollect/index.d.ts +0 -3
  121. package/lib/typescript/OkCollect/types.d.ts +0 -139
  122. package/lib/typescript/OkCore/Helpers.d.ts +0 -95
  123. package/lib/typescript/OkCore/OkHiException.d.ts +0 -81
  124. package/lib/typescript/OkCore/OkHiMode.d.ts +0 -7
  125. package/lib/typescript/OkCore/_helpers.d.ts +0 -3
  126. package/lib/typescript/OkCore/_types.d.ts +0 -38
  127. package/lib/typescript/OkCore/index.d.ts +0 -17
  128. package/lib/typescript/OkCore/types.d.ts +0 -203
  129. package/lib/typescript/OkHiNativeModule/index.d.ts +0 -48
  130. package/lib/typescript/OkVerify/index.d.ts +0 -65
  131. package/lib/typescript/OkVerify/types.d.ts +0 -0
  132. package/lib/typescript/index.d.ts +0 -3
  133. package/react-native-okhi.podspec +0 -35
  134. package/src/OkCollect/Helpers.ts +0 -53
  135. package/src/OkCollect/OkHiLocationManager.tsx +0 -391
  136. package/src/OkCollect/Spinner.tsx +0 -18
  137. package/src/OkCollect/Util.ts +0 -270
  138. package/src/OkCollect/app.json +0 -4
  139. package/src/OkCollect/index.ts +0 -3
  140. package/src/OkCollect/types.ts +0 -154
  141. package/src/OkCore/Helpers.ts +0 -477
  142. package/src/OkCore/OkHiException.ts +0 -93
  143. package/src/OkCore/OkHiMode.ts +0 -7
  144. package/src/OkCore/_helpers.ts +0 -47
  145. package/src/OkCore/_types.ts +0 -37
  146. package/src/OkCore/index.ts +0 -87
  147. package/src/OkCore/types.ts +0 -235
  148. package/src/OkHiNativeModule/index.ts +0 -92
  149. package/src/OkVerify/index.ts +0 -259
  150. package/src/OkVerify/types.ts +0 -0
  151. /package/lib/commonjs/{OkVerify/types.js → types.js} +0 -0
@@ -1,154 +0,0 @@
1
- import type { ViewStyle } from 'react-native';
2
- import type { JSX } from 'react';
3
- import type { OkHiException } from '../OkCore/OkHiException';
4
- import type { OkHiUser, OkHiLocation, UsageType } from '../OkCore/types';
5
-
6
- /**
7
- * The OkCollect Success Response object contains information about the newly created user and location once an address has been successfully created.
8
- * It can be used to extract information about the address and/or start address verification process.
9
- */
10
- export interface OkCollectSuccessResponse {
11
- /**
12
- * The [OkHiUser](https://okhi.github.io/react-native-core/interfaces/okhiuser.html) object containing information about the newly created user.
13
- */
14
- user: OkHiUser;
15
- /**
16
- * The [OkHiLocation](https://okhi.github.io/react-native-core/interfaces/okhilocation.html) object containing information about the newly created user.
17
- */
18
- location: OkHiLocation;
19
-
20
- /**
21
- * Starts address verification
22
- */
23
- startVerification: () => Promise<string>;
24
- }
25
-
26
- /**
27
- * The OkHiLocationManager exposes props that you can use to customise it's functionality and appearance.
28
- */
29
- export interface OkHiLocationManagerProps {
30
- /**
31
- * **Required:** A boolean flag that determines whether or not to show the Location Manager.
32
- */
33
- launch: boolean;
34
- /**
35
- * **Required:** A defined [OkHiUser](https://okhi.github.io/react-native-core/interfaces/okhiuser.html) object, with a mandatory "phone" key property.
36
- */
37
- user: OkHiUser;
38
- /**
39
- * **Optional:** A custom JSX.Element that'll be used as a loading indicator.
40
- */
41
- loader?: JSX.Element;
42
- /**
43
- * **Optional:** Used to customise the appearance of the Container that wraps the location manager.
44
- */
45
- style?: ViewStyle;
46
- /**
47
- * **Required:** A callback that'll be invoked with an {@link OkCollectSuccessResponse} once an accurate OkHi address has been successfully created.
48
- */
49
- onSuccess: (response: OkCollectSuccessResponse) => any;
50
- /**
51
- * **Required:** A callback that'll be invoked whenever an error occurs during the address creation process.
52
- */
53
- onError: (error: OkHiException) => any;
54
- /**
55
- * **Required:** A callback that'll be invoked whenever a user taps on the close button.
56
- */
57
- onCloseRequest: () => any;
58
- /**
59
- * **Optional:** An object that'll be used to customise the appearance of the Location Manager to better match your branding requirements.
60
- */
61
- theme?: {
62
- appBar?: {
63
- backgroundColor?: string;
64
- logo?: string;
65
- };
66
- colors?: {
67
- primary?: string;
68
- };
69
- };
70
- /**
71
- * **Optional:** An object that'll be used to customise the functionality of the Location Manager. This object dictates whether you want some features on or off.
72
- */
73
- config?: {
74
- streetView?: boolean;
75
- appBar?: {
76
- visible?: boolean;
77
- };
78
- addressTypes?: {
79
- home?: boolean;
80
- work?: boolean;
81
- };
82
- usageTypes?: UsageType;
83
- };
84
-
85
- /**
86
- * **Optional:** Enable a user to either select an existing address, or force to create a new one
87
- */
88
- mode?: 'create' | 'select';
89
-
90
- location?: {
91
- id?: string;
92
- };
93
- }
94
-
95
- /**
96
- * @ignore
97
- */
98
- export interface OkHiLocationManagerStartDataPayload {
99
- style?: {
100
- base?: {
101
- color?: string;
102
- logo?: string;
103
- name?: string;
104
- };
105
- };
106
- auth: {
107
- authToken: string;
108
- };
109
- context: {
110
- container?: {
111
- name?: string;
112
- version?: string;
113
- };
114
- developer: {
115
- name: string;
116
- };
117
- library: {
118
- name: string;
119
- version: string;
120
- };
121
- platform: {
122
- name: 'react-native';
123
- };
124
- };
125
- config?: {
126
- streetView?: boolean;
127
- appBar?: {
128
- color?: string;
129
- visible?: boolean;
130
- };
131
- usageTypes: UsageType;
132
- };
133
- user: OkHiUser;
134
- }
135
-
136
- /**
137
- * @ignore
138
- */
139
- export type OkHiLocationManagerStartMessage = 'select_location' | 'start_app';
140
-
141
- /**
142
- * @ignore
143
- */
144
- export interface OkHiLocationManagerResponse {
145
- message:
146
- | 'location_selected'
147
- | 'location_created'
148
- | 'location_updated'
149
- | 'exit_app'
150
- | 'request_enable_protected_apps'
151
- | 'fatal_exit'
152
- | 'request_location_permission';
153
- payload: any;
154
- }
@@ -1,477 +0,0 @@
1
- import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';
2
- import { Alert, Permission, PermissionsAndroid, Platform } from 'react-native';
3
- import { errorHandler, isValidPlatform } from './_helpers';
4
- import type {
5
- LocationPermissionCallback,
6
- LocationPermissionStatus,
7
- LocationRequestPermissionType,
8
- } from './types';
9
- import { OkHiException } from './OkHiException';
10
-
11
- /**
12
- * Checks whether location services are enabled
13
- * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available
14
- */
15
- export const isLocationServicesEnabled = (): Promise<boolean> => {
16
- return isValidPlatform(OkHiNativeModule.isLocationServicesEnabled);
17
- };
18
-
19
- /**
20
- * Checks whether when in use location permission is granted
21
- * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted
22
- */
23
- export const isLocationPermissionGranted = (): Promise<boolean> => {
24
- return isValidPlatform(OkHiNativeModule.isLocationPermissionGranted);
25
- };
26
-
27
- const isBackgroundLocationPermissionGrantedAndroid =
28
- async (): Promise<boolean> => {
29
- const sdkVersion = await OkHiNativeModule.getSystemVersion();
30
- if (Number(sdkVersion) < 23) {
31
- return true;
32
- }
33
- if (Number(sdkVersion) < 29) {
34
- return await isLocationPermissionGranted();
35
- }
36
- if (
37
- typeof PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION !==
38
- 'undefined'
39
- ) {
40
- const hasPermission = await PermissionsAndroid.check(
41
- PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION as Permission
42
- );
43
- return hasPermission;
44
- }
45
- console.warn(
46
- `PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION is undefined, this is an issue with the current version of RN you are running. Please consider upgrading`
47
- );
48
- return false;
49
- };
50
-
51
- const isBackgroundLocationPermissionGrantedIOS = (): Promise<boolean> => {
52
- return OkHiNativeModule.isBackgroundLocationPermissionGranted();
53
- };
54
-
55
- /**
56
- * Checks whether background location permission is granted
57
- * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted
58
- */
59
- export const isBackgroundLocationPermissionGranted = (): Promise<boolean> => {
60
- const fn =
61
- Platform.OS === 'android'
62
- ? isBackgroundLocationPermissionGrantedAndroid
63
- : isBackgroundLocationPermissionGrantedIOS;
64
- return isValidPlatform(fn);
65
- };
66
-
67
- const requestLocationPermissionAndroid = async (): Promise<boolean> => {
68
- const status: any = await PermissionsAndroid.requestMultiple([
69
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION as Permission,
70
- PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION as Permission,
71
- ]);
72
- return status['android.permission.ACCESS_FINE_LOCATION'] === 'granted';
73
- };
74
-
75
- const requestLocationPermissionIOS = (): Promise<boolean> => {
76
- return OkHiNativeModule.requestLocationPermission();
77
- };
78
-
79
- /**
80
- * Requests for when in use location permission
81
- * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted
82
- */
83
- export const requestLocationPermission = async (): Promise<boolean> => {
84
- const isGranted = await isLocationPermissionGranted();
85
- if (isGranted) return isGranted;
86
- return errorHandler(
87
- Platform.OS === 'android'
88
- ? requestLocationPermissionAndroid
89
- : requestLocationPermissionIOS
90
- );
91
- };
92
-
93
- const requestBackgroundLocationPermissionAndroid =
94
- async (): Promise<boolean> => {
95
- const sdkVersion = await OkHiNativeModule.getSystemVersion();
96
- if (Number(sdkVersion) < 23) return true;
97
- if (Number(sdkVersion) >= 29) {
98
- const permissions: any = [
99
- PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,
100
- ];
101
- const status: any = await PermissionsAndroid.requestMultiple(permissions);
102
- return (
103
- status['android.permission.ACCESS_BACKGROUND_LOCATION'] === 'granted'
104
- );
105
- } else {
106
- return await requestLocationPermissionAndroid();
107
- }
108
- };
109
-
110
- const requestBackgroundLocationPermissionIOS = (): Promise<boolean> => {
111
- return OkHiNativeModule.requestBackgroundLocationPermission();
112
- };
113
-
114
- /**
115
- * Requests for background location permission
116
- * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted
117
- */
118
- export const requestBackgroundLocationPermission =
119
- async (): Promise<boolean> => {
120
- const isGranted = await isBackgroundLocationPermissionGranted();
121
- if (isGranted) return isGranted;
122
- return errorHandler(
123
- Platform.OS === 'android'
124
- ? requestBackgroundLocationPermissionAndroid
125
- : requestBackgroundLocationPermissionIOS
126
- );
127
- };
128
-
129
- /**
130
- * Requests the user to enable location services by showing an in app modal on android and opening location settings on iOS
131
- * @returns {Promise<boolean>} A promise that resolves to either a boolean value on android or null on iOS
132
- */
133
- export const requestEnableLocationServices = (): Promise<boolean | null> => {
134
- return isValidPlatform(OkHiNativeModule.requestEnableLocationServices);
135
- };
136
-
137
- /**
138
- * Android Only - Checks if Google Play Services is available
139
- * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe
140
- */
141
- export const isGooglePlayServicesAvailable = (): Promise<boolean> => {
142
- return isValidPlatform(
143
- OkHiNativeModule.isGooglePlayServicesAvailable,
144
- 'android'
145
- );
146
- };
147
-
148
- /**
149
- * Android Only - Requests user to enable Google Play Services
150
- * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe
151
- */
152
- export const requestEnableGooglePlayServices = (): Promise<boolean> => {
153
- return isValidPlatform(
154
- OkHiNativeModule.requestEnableGooglePlayServices,
155
- 'android'
156
- );
157
- };
158
-
159
- /**
160
- * Returns the system version of the current platform
161
- * @returns {Promise<boolean>} A promise that resolves either a string on iOS or number on Android
162
- */
163
- export const getSystemVersion = (): Promise<string | number> =>
164
- isValidPlatform(OkHiNativeModule.getSystemVersion);
165
-
166
- /**
167
- * Requests location permission from the user. It'll also attempt to activate any disbaled services (Android Only)
168
- */
169
- export const request = (
170
- locationPermissionType: LocationRequestPermissionType,
171
- rationale: {
172
- title: string;
173
- text: string;
174
- successButton?: { label: string };
175
- denyButton?: { label: string };
176
- } | null,
177
- callback: LocationPermissionCallback
178
- ) => {
179
- const serviceError = new OkHiException({
180
- code: OkHiException.SERVICE_UNAVAILABLE_CODE,
181
- message:
182
- 'Location service is currently not available. Please enable in app settings',
183
- });
184
-
185
- const googlePlayError = new OkHiException({
186
- code: OkHiException.SERVICE_UNAVAILABLE_CODE,
187
- message:
188
- 'Google Play Services is currently unavailable. Please enable in settings',
189
- });
190
-
191
- const handleError = (error: OkHiException) => {
192
- callback(null, error);
193
- };
194
-
195
- const handleGooglePlayServiceRequest = () => {
196
- requestEnableGooglePlayServices().then((googlePlayStatus) => {
197
- if (!googlePlayStatus) {
198
- handleError(googlePlayError);
199
- } else {
200
- handleRationaleRequest();
201
- }
202
- });
203
- };
204
-
205
- const handleRationaleAlert = (alertRationale: {
206
- title: string;
207
- text: string;
208
- grantButton?: { label: string };
209
- denyButton?: { label: string };
210
- }) => {
211
- return new Promise((resolve, _) => {
212
- Alert.alert(
213
- alertRationale.title,
214
- alertRationale.text,
215
- [
216
- {
217
- text: alertRationale.grantButton
218
- ? alertRationale.grantButton.label
219
- : 'Grant',
220
- onPress: () => {
221
- resolve(true);
222
- },
223
- },
224
- {
225
- text: alertRationale.denyButton
226
- ? alertRationale.denyButton.label
227
- : 'Deny',
228
- onPress: () => {
229
- resolve(false);
230
- },
231
- style: 'cancel',
232
- },
233
- ],
234
- {
235
- onDismiss: () => {
236
- resolve(false);
237
- },
238
- }
239
- );
240
- });
241
- };
242
-
243
- const handlePermissionRequest = () => {
244
- if (Platform.OS === 'ios') {
245
- OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');
246
- OkHiNativeEvents.addListener(
247
- 'onLocationPermissionStatusUpdate',
248
- (permissionUpdate) => {
249
- callback(permissionUpdate, null);
250
- }
251
- );
252
- if (locationPermissionType === 'whenInUse') {
253
- OkHiNativeModule.requestLocationPermission();
254
- } else {
255
- OkHiNativeModule.requestBackgroundLocationPermission();
256
- }
257
- } else {
258
- if (locationPermissionType === 'whenInUse') {
259
- requestLocationPermissionAndroid().then((whenInUseResult) =>
260
- callback(whenInUseResult ? 'authorizedWhenInUse' : 'denied', null)
261
- );
262
- } else {
263
- requestLocationPermissionAndroid().then((initialWhenInUseResult) => {
264
- if (!initialWhenInUseResult) {
265
- callback('denied', null);
266
- } else {
267
- callback('authorizedWhenInUse', null);
268
- requestBackgroundLocationPermission().then((alwaysResult) => {
269
- callback(
270
- alwaysResult ? 'authorizedAlways' : 'authorizedWhenInUse',
271
- null
272
- );
273
- });
274
- }
275
- });
276
- }
277
- }
278
- };
279
-
280
- const handleRationaleRequest = async () => {
281
- const currentStatus = await retriveLocationPermissionStatus();
282
- let showRationale = true;
283
- if (
284
- locationPermissionType === 'whenInUse' &&
285
- (currentStatus === 'authorizedWhenInUse' ||
286
- currentStatus === 'authorizedAlways')
287
- ) {
288
- showRationale = false;
289
- }
290
- if (
291
- locationPermissionType === 'always' &&
292
- currentStatus === 'authorizedAlways'
293
- ) {
294
- showRationale = false;
295
- }
296
- if (rationale && showRationale) {
297
- const result = await handleRationaleAlert(rationale);
298
- if (!result) {
299
- callback('rationaleDissmissed', null);
300
- } else {
301
- handlePermissionRequest();
302
- }
303
- } else {
304
- handlePermissionRequest();
305
- }
306
- };
307
-
308
- isLocationServicesEnabled()
309
- .then((serviceStatus) => {
310
- if (!serviceStatus && Platform.OS === 'ios') {
311
- handleError(serviceError);
312
- } else if (!serviceStatus && Platform.OS === 'android') {
313
- requestEnableLocationServices()
314
- .then((enableResult) => {
315
- if (!enableResult) {
316
- handleError(serviceError);
317
- } else {
318
- handleGooglePlayServiceRequest();
319
- }
320
- })
321
- .catch(handleError);
322
- } else {
323
- if (Platform.OS === 'ios') {
324
- handleRationaleRequest();
325
- } else {
326
- handleGooglePlayServiceRequest();
327
- }
328
- }
329
- })
330
- .catch(handleError);
331
- };
332
-
333
- /**
334
- * Open the device's app settings.
335
- */
336
- export const openAppSettings = () => {
337
- OkHiNativeModule.openAppSettings();
338
- };
339
-
340
- /**
341
- * Retrives the location permission status from the device
342
- */
343
- export const retriveLocationPermissionStatus =
344
- async (): Promise<LocationPermissionStatus> => {
345
- if (Platform.OS === 'ios') {
346
- return OkHiNativeModule.retriveLocationPermissionStatus() as Promise<LocationPermissionStatus>;
347
- }
348
- const alwaysPerm = await isBackgroundLocationPermissionGranted();
349
- if (alwaysPerm) {
350
- return 'authorizedAlways';
351
- }
352
- const whenInUsePerm = await isLocationPermissionGranted();
353
- return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';
354
- };
355
-
356
- /**
357
- * Requests tracking authorization from the user. iOS only, iOS version >= 14
358
- * Read more: https://developer.apple.com/app-store/user-privacy-and-data-use/
359
- */
360
- export const requestTrackingAuthorization = async (): Promise<
361
- string | null
362
- > => {
363
- return isValidPlatform(async () => {
364
- const result = await OkHiNativeModule.requestTrackingAuthorization();
365
- return result;
366
- }, 'ios');
367
- };
368
-
369
- /**
370
- * Checks whether current device can open "Protected Apps Settings" available in Transsion Group android devices such as Infinix and Tecno
371
- * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.
372
- */
373
- export const canOpenProtectedAppsSettings = (): Promise<boolean> => {
374
- return isValidPlatform(async () => {
375
- const result = await OkHiNativeModule.canOpenProtectedAppsSettings();
376
- return result;
377
- }, 'android');
378
- };
379
-
380
- /**
381
- * Opens "Protected Apps Settings" available in Transsion Group android devices such as Infinix and Tecno
382
- * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.
383
- */
384
- export const openProtectedAppsSettings = (): Promise<boolean> => {
385
- return isValidPlatform(async () => {
386
- const result = await OkHiNativeModule.openProtectedAppsSettings();
387
- return result;
388
- }, 'android');
389
- };
390
-
391
- const isAndroidNotificationGranted = async (): Promise<boolean> => {
392
- return isValidPlatform(async () => {
393
- const sdkVersion = await OkHiNativeModule.getSystemVersion();
394
- if (Number(sdkVersion) < 33) {
395
- return true;
396
- }
397
- const permission =
398
- PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS ||
399
- PermissionsAndroid.PERMISSIONS.POST_NOTIFICATION;
400
- if (!permission)
401
- throw new Error('Unable to request notification permission');
402
- const hasPermission = await PermissionsAndroid.check(
403
- PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS ||
404
- (PermissionsAndroid.PERMISSIONS.POST_NOTIFICATION as Permission)
405
- );
406
- return hasPermission;
407
- }, 'android');
408
- };
409
-
410
- const requestAndroidNotificationPermission = async (): Promise<boolean> => {
411
- return isValidPlatform(async () => {
412
- const existingPermissionStatus = await isAndroidNotificationGranted();
413
- if (existingPermissionStatus) {
414
- return true;
415
- }
416
- const status: any = await PermissionsAndroid.request(
417
- PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS as Permission
418
- );
419
- return status === 'granted';
420
- }, 'android');
421
- };
422
-
423
- const isIOSNotificationGranted = async (): Promise<boolean> => {
424
- return isValidPlatform(async () => {
425
- return OkHiNativeModule.isNotificationPermissionGranted();
426
- }, 'ios');
427
- };
428
-
429
- const requestIOSNotificationPermission = async (): Promise<boolean> => {
430
- return isValidPlatform(async () => {
431
- const existingPermissionStatus = await isIOSNotificationGranted();
432
- if (existingPermissionStatus) {
433
- return true;
434
- }
435
- return OkHiNativeModule.requestNotificationPermission();
436
- }, 'ios');
437
- };
438
-
439
- /**
440
- * Checks whether notification permission is granted on both android and ios devices
441
- */
442
- export const isNotificationPermissionGranted = async (): Promise<boolean> => {
443
- if (Platform.OS === 'android') {
444
- return isAndroidNotificationGranted();
445
- } else if (Platform.OS === 'ios') {
446
- return isIOSNotificationGranted();
447
- } else {
448
- throw new OkHiException({
449
- code: OkHiException.UNSUPPORTED_PLATFORM_CODE,
450
- message: OkHiException.UNSUPPORTED_PLATFORM_MESSAGE,
451
- });
452
- }
453
- };
454
-
455
- /**
456
- * Requests notification permission from both android and ios devices
457
- */
458
- export const requestNotificationPermission = async (): Promise<boolean> => {
459
- if (Platform.OS === 'android') {
460
- return requestAndroidNotificationPermission();
461
- } else if (Platform.OS === 'ios') {
462
- return requestIOSNotificationPermission();
463
- } else {
464
- throw new OkHiException({
465
- code: OkHiException.UNSUPPORTED_PLATFORM_CODE,
466
- message: OkHiException.UNSUPPORTED_PLATFORM_MESSAGE,
467
- });
468
- }
469
- };
470
-
471
- /**
472
- * Determines the current location accuracy level of the device
473
- * @returns "no_permission" | "approximate" | "precise"
474
- */
475
- export const getLocationAccuracyLevel = async () => {
476
- return OkHiNativeModule.getLocationAccuracyLevel();
477
- };