react-native-okhi 1.0.3-2.beta.1
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.
- package/LICENSE +20 -0
- package/README.md +174 -0
- package/android/build.gradle +139 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/reactnativeokhi/OkhiModule.java +317 -0
- package/android/src/main/java/com/reactnativeokhi/OkhiPackage.java +28 -0
- package/ios/OkHiExtension.swift +27 -0
- package/ios/OkHiStruct.swift +29 -0
- package/ios/Okhi-Bridging-Header.h +3 -0
- package/ios/Okhi.m +41 -0
- package/ios/Okhi.swift +207 -0
- package/ios/Okhi.xcodeproj/project.pbxproj +283 -0
- package/ios/Okhi.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/lib/commonjs/OkCollect/Helpers.js +47 -0
- package/lib/commonjs/OkCollect/Helpers.js.map +1 -0
- package/lib/commonjs/OkCollect/OkHiLocationManager.js +202 -0
- package/lib/commonjs/OkCollect/OkHiLocationManager.js.map +1 -0
- package/lib/commonjs/OkCollect/Spinner.js +32 -0
- package/lib/commonjs/OkCollect/Spinner.js.map +1 -0
- package/lib/commonjs/OkCollect/Util.js +192 -0
- package/lib/commonjs/OkCollect/Util.js.map +1 -0
- package/lib/commonjs/OkCollect/app.json +4 -0
- package/lib/commonjs/OkCollect/index.js +52 -0
- package/lib/commonjs/OkCollect/index.js.map +1 -0
- package/lib/commonjs/OkCollect/types.js +6 -0
- package/lib/commonjs/OkCollect/types.js.map +1 -0
- package/lib/commonjs/OkCore/Helpers.js +367 -0
- package/lib/commonjs/OkCore/Helpers.js.map +1 -0
- package/lib/commonjs/OkCore/OkHiAuth.js +126 -0
- package/lib/commonjs/OkCore/OkHiAuth.js.map +1 -0
- package/lib/commonjs/OkCore/OkHiException.js +133 -0
- package/lib/commonjs/OkCore/OkHiException.js.map +1 -0
- package/lib/commonjs/OkCore/OkHiMode.js +16 -0
- package/lib/commonjs/OkCore/OkHiMode.js.map +1 -0
- package/lib/commonjs/OkCore/_helpers.js +50 -0
- package/lib/commonjs/OkCore/_helpers.js.map +1 -0
- package/lib/commonjs/OkCore/_types.js +2 -0
- package/lib/commonjs/OkCore/_types.js.map +1 -0
- package/lib/commonjs/OkCore/index.js +117 -0
- package/lib/commonjs/OkCore/index.js.map +1 -0
- package/lib/commonjs/OkCore/types.js +2 -0
- package/lib/commonjs/OkCore/types.js.map +1 -0
- package/lib/commonjs/OkHiNativeModule/index.js +24 -0
- package/lib/commonjs/OkHiNativeModule/index.js.map +1 -0
- package/lib/commonjs/OkVerify/index.js +246 -0
- package/lib/commonjs/OkVerify/index.js.map +1 -0
- package/lib/commonjs/OkVerify/types.js +2 -0
- package/lib/commonjs/OkVerify/types.js.map +1 -0
- package/lib/commonjs/index.js +45 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/OkCollect/Helpers.js +36 -0
- package/lib/module/OkCollect/Helpers.js.map +1 -0
- package/lib/module/OkCollect/OkHiLocationManager.js +179 -0
- package/lib/module/OkCollect/OkHiLocationManager.js.map +1 -0
- package/lib/module/OkCollect/Spinner.js +20 -0
- package/lib/module/OkCollect/Spinner.js.map +1 -0
- package/lib/module/OkCollect/Util.js +171 -0
- package/lib/module/OkCollect/Util.js.map +1 -0
- package/lib/module/OkCollect/app.json +4 -0
- package/lib/module/OkCollect/index.js +4 -0
- package/lib/module/OkCollect/index.js.map +1 -0
- package/lib/module/OkCollect/types.js +2 -0
- package/lib/module/OkCollect/types.js.map +1 -0
- package/lib/module/OkCore/Helpers.js +315 -0
- package/lib/module/OkCore/Helpers.js.map +1 -0
- package/lib/module/OkCore/OkHiAuth.js +112 -0
- package/lib/module/OkCore/OkHiAuth.js.map +1 -0
- package/lib/module/OkCore/OkHiException.js +124 -0
- package/lib/module/OkCore/OkHiException.js.map +1 -0
- package/lib/module/OkCore/OkHiMode.js +8 -0
- package/lib/module/OkCore/OkHiMode.js.map +1 -0
- package/lib/module/OkCore/_helpers.js +38 -0
- package/lib/module/OkCore/_helpers.js.map +1 -0
- package/lib/module/OkCore/_types.js +2 -0
- package/lib/module/OkCore/_types.js.map +1 -0
- package/lib/module/OkCore/index.js +50 -0
- package/lib/module/OkCore/index.js.map +1 -0
- package/lib/module/OkCore/types.js +2 -0
- package/lib/module/OkCore/types.js.map +1 -0
- package/lib/module/OkHiNativeModule/index.js +14 -0
- package/lib/module/OkHiNativeModule/index.js.map +1 -0
- package/lib/module/OkVerify/index.js +187 -0
- package/lib/module/OkVerify/index.js.map +1 -0
- package/lib/module/OkVerify/types.js +2 -0
- package/lib/module/OkVerify/types.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/OkCollect/Helpers.d.ts +9 -0
- package/lib/typescript/OkCollect/OkHiLocationManager.d.ts +6 -0
- package/lib/typescript/OkCollect/Spinner.d.ts +4 -0
- package/lib/typescript/OkCollect/Util.d.ts +26 -0
- package/lib/typescript/OkCollect/index.d.ts +3 -0
- package/lib/typescript/OkCollect/types.d.ts +133 -0
- package/lib/typescript/OkCore/Helpers.d.ts +82 -0
- package/lib/typescript/OkCore/OkHiAuth.d.ts +16 -0
- package/lib/typescript/OkCore/OkHiException.d.ts +81 -0
- package/lib/typescript/OkCore/OkHiMode.d.ts +7 -0
- package/lib/typescript/OkCore/_helpers.d.ts +3 -0
- package/lib/typescript/OkCore/_types.d.ts +38 -0
- package/lib/typescript/OkCore/index.d.ts +17 -0
- package/lib/typescript/OkCore/types.d.ts +180 -0
- package/lib/typescript/OkHiNativeModule/index.d.ts +34 -0
- package/lib/typescript/OkVerify/index.d.ts +60 -0
- package/lib/typescript/OkVerify/types.d.ts +5 -0
- package/lib/typescript/index.d.ts +3 -0
- package/package.json +152 -0
- package/react-native-okhi.podspec +36 -0
- package/src/OkCollect/Helpers.ts +53 -0
- package/src/OkCollect/OkHiLocationManager.tsx +209 -0
- package/src/OkCollect/Spinner.tsx +18 -0
- package/src/OkCollect/Util.ts +195 -0
- package/src/OkCollect/app.json +4 -0
- package/src/OkCollect/index.ts +3 -0
- package/src/OkCollect/types.ts +142 -0
- package/src/OkCore/Helpers.ts +389 -0
- package/src/OkCore/OkHiAuth.ts +106 -0
- package/src/OkCore/OkHiException.ts +93 -0
- package/src/OkCore/OkHiMode.ts +7 -0
- package/src/OkCore/_helpers.ts +48 -0
- package/src/OkCore/_types.ts +37 -0
- package/src/OkCore/index.ts +59 -0
- package/src/OkCore/types.ts +203 -0
- package/src/OkHiNativeModule/index.ts +63 -0
- package/src/OkVerify/index.ts +243 -0
- package/src/OkVerify/types.ts +3 -0
- package/src/index.tsx +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 OkHi
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# OkHi React Native
|
|
2
|
+
|
|
3
|
+
The official OkHi React Native library will enable you to start collecting and verifying your user's addresses.
|
|
4
|
+
|
|
5
|
+
# Prerequisites
|
|
6
|
+
|
|
7
|
+
## OkHi Client Key and Branch Id
|
|
8
|
+
|
|
9
|
+
First you need to obtain your OkHi client key and branch ID. You can get these by signing up [here](https://docs.google.com/forms/d/e/1FAIpQLSed2rhgKQ8iv-xiJrJnDqOTaPiP6c7oE7DzrhTPF_d3VTihDQ/viewform).
|
|
10
|
+
Use your sandbox keys while you test and develop, and your production mode keys before you publish your app.
|
|
11
|
+
|
|
12
|
+
## Android
|
|
13
|
+
|
|
14
|
+
### Change your minSdkVersion target
|
|
15
|
+
|
|
16
|
+
This library targets android devices >= SDK 23. Make sure you're targeting at-least the same by modifying your `android/build.gradle` file
|
|
17
|
+
|
|
18
|
+
```gradle
|
|
19
|
+
minSdkVersion = 23
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Add necessary permissions to your `AndroidManifest.xml`
|
|
23
|
+
|
|
24
|
+
```xml
|
|
25
|
+
<manifest ...>
|
|
26
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
27
|
+
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
|
28
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
29
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
30
|
+
...
|
|
31
|
+
|
|
32
|
+
<application>
|
|
33
|
+
...
|
|
34
|
+
</application>
|
|
35
|
+
|
|
36
|
+
</manifest>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If you're targeting Android versions > 8 and you're using the OkVerify library you need to make sure your users select on "Allow always" when granting permissions otherwise the verification process won't work.
|
|
40
|
+
|
|
41
|
+
## iOS
|
|
42
|
+
|
|
43
|
+
### Enable background mode in your application
|
|
44
|
+
|
|
45
|
+
OkHi obtains verification signals in the background, to enable this make sure to add "Location updates" and "Background fetch" to your Background Modes under Signing & Capabilities of your target.
|
|
46
|
+
|
|
47
|
+

|
|
48
|
+
|
|
49
|
+
### Change your deployment target
|
|
50
|
+
|
|
51
|
+
All OkHi React Native libraries target ios devices >= 12. Make sure you're targeting at-least the same by modifying your both your Podfile and deployment target in xcode.
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
Podile located under: `ios/Podfile`
|
|
56
|
+
|
|
57
|
+
```xml
|
|
58
|
+
platform :ios, '12.0'
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Add necessary permissions to your `Info.plist`
|
|
62
|
+
|
|
63
|
+
```xml
|
|
64
|
+
<key>NSLocationWhenInUseUsageDescription</key>
|
|
65
|
+
<string>String that explains why you need when in use location permission</string>
|
|
66
|
+
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
|
|
67
|
+
<string>String that explains why you need always location permission</string>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
Run the bellow command in the root directory of your React Native project.
|
|
73
|
+
|
|
74
|
+
```yaml
|
|
75
|
+
yarn add react-native-okhi react-native-webview
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Finally install all required pods by running the following command in the ios directory
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
cd ios/ && pod install && cd ../
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
# Usage
|
|
85
|
+
|
|
86
|
+
## Initialization
|
|
87
|
+
|
|
88
|
+
Add the following initialization code to your index.js file. Replace my_branch_id and my_client_key with the keys provided to you after sign up.
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
import * as OkHi from 'react-native-okhi';
|
|
92
|
+
|
|
93
|
+
OkHi.initialize({
|
|
94
|
+
credentials: {
|
|
95
|
+
branchId: '<my_branch_id>',
|
|
96
|
+
clientKey: '<my_client_key>',
|
|
97
|
+
},
|
|
98
|
+
context: {
|
|
99
|
+
mode: 'sandbox',
|
|
100
|
+
},
|
|
101
|
+
notification: {
|
|
102
|
+
title: 'Address verification in progress',
|
|
103
|
+
text: 'Tap here to view your verification status.',
|
|
104
|
+
channelId: 'okhi',
|
|
105
|
+
channelName: 'OkHi Channel',
|
|
106
|
+
channelDescription: 'OkHi verification alerts',
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
.then(() => console.log('init done'))
|
|
110
|
+
.catch(console.log);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Address Creation and Verification
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
import React, { useState, useEffect } from 'react';
|
|
117
|
+
import { View, Text } from 'react-native';
|
|
118
|
+
import { OkHiLocationManager, canStartVerification } from 'react-native-okhi';
|
|
119
|
+
|
|
120
|
+
const App = () => {
|
|
121
|
+
const [launch, setLaunch] = useState(false);
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
canStartVerification({ requestServices: true }).then((result) => {
|
|
125
|
+
setLaunch(result);
|
|
126
|
+
}); // checks & requests for required services for verification to run
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const user = {
|
|
130
|
+
phone: '+254712345678', // required
|
|
131
|
+
firstName: 'Julius',
|
|
132
|
+
lastName: 'Kiano',
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const handleOnSuccess = async (response) => {
|
|
136
|
+
console.log(response.user); // user information
|
|
137
|
+
console.log(response.location); // address information
|
|
138
|
+
await response.startVerification();
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const handleOnError = (error) => {
|
|
142
|
+
console.log(error.code); // user information
|
|
143
|
+
console.log(error.message); // address information
|
|
144
|
+
setLaunch(false);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
if (launch) {
|
|
148
|
+
return (
|
|
149
|
+
<View style={{ flex: 1 }}>
|
|
150
|
+
<OkHiLocationManager
|
|
151
|
+
user={user}
|
|
152
|
+
launch={launch}
|
|
153
|
+
onSuccess={handleOnSuccess}
|
|
154
|
+
onCloseRequest={() => setLaunch(false)} // called when user taps on the top right close button
|
|
155
|
+
onError={handleOnError}
|
|
156
|
+
/>
|
|
157
|
+
</View>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
|
163
|
+
<Text>Loading..</Text>
|
|
164
|
+
</View>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export default App;
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
# Documentation
|
|
172
|
+
|
|
173
|
+
- [Guide](https://docs.okhi.co/v/v5.1-beta/okhi-on-your-react-native-app)
|
|
174
|
+
- [Best practices](https://docs.google.com/document/d/1kxolQJ4n6tEgReuqVLYpDVMW--xvqv5UQ7AdvrN0Uw0/edit)
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath 'com.android.tools.build:gradle:7.2.2'
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def isNewArchitectureEnabled() {
|
|
13
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
apply plugin: 'com.android.library'
|
|
17
|
+
|
|
18
|
+
if (isNewArchitectureEnabled()) {
|
|
19
|
+
apply plugin: 'com.facebook.react'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def getExtOrDefault(name) {
|
|
23
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Okhi_' + name]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def getExtOrIntegerDefault(name) {
|
|
27
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Okhi_' + name]).toInteger()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
android {
|
|
31
|
+
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
|
|
35
|
+
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
|
|
36
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
37
|
+
}
|
|
38
|
+
buildTypes {
|
|
39
|
+
release {
|
|
40
|
+
minifyEnabled false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
lintOptions {
|
|
45
|
+
disable 'GradleCompatible'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
compileOptions {
|
|
49
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
50
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
repositories {
|
|
55
|
+
mavenCentral()
|
|
56
|
+
google()
|
|
57
|
+
|
|
58
|
+
def found = false
|
|
59
|
+
def defaultDir = null
|
|
60
|
+
def androidSourcesName = 'React Native sources'
|
|
61
|
+
|
|
62
|
+
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
|
63
|
+
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
|
64
|
+
} else {
|
|
65
|
+
defaultDir = new File(
|
|
66
|
+
projectDir,
|
|
67
|
+
'/../../../node_modules/react-native/android'
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (defaultDir.exists()) {
|
|
72
|
+
maven {
|
|
73
|
+
url defaultDir.toString()
|
|
74
|
+
name androidSourcesName
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
|
|
78
|
+
found = true
|
|
79
|
+
} else {
|
|
80
|
+
def parentDir = rootProject.projectDir
|
|
81
|
+
|
|
82
|
+
1.upto(5, {
|
|
83
|
+
if (found) return true
|
|
84
|
+
parentDir = parentDir.parentFile
|
|
85
|
+
|
|
86
|
+
def androidSourcesDir = new File(
|
|
87
|
+
parentDir,
|
|
88
|
+
'node_modules/react-native'
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def androidPrebuiltBinaryDir = new File(
|
|
92
|
+
parentDir,
|
|
93
|
+
'node_modules/react-native/android'
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if (androidPrebuiltBinaryDir.exists()) {
|
|
97
|
+
maven {
|
|
98
|
+
url androidPrebuiltBinaryDir.toString()
|
|
99
|
+
name androidSourcesName
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
|
|
103
|
+
found = true
|
|
104
|
+
} else if (androidSourcesDir.exists()) {
|
|
105
|
+
maven {
|
|
106
|
+
url androidSourcesDir.toString()
|
|
107
|
+
name androidSourcesName
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
|
|
111
|
+
found = true
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!found) {
|
|
117
|
+
throw new GradleException(
|
|
118
|
+
"${project.name}: unable to locate React Native android sources. " +
|
|
119
|
+
"Ensure you have you installed React Native as a dependency in your project and try again."
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
dependencies {
|
|
126
|
+
//noinspection GradleDynamicVersion
|
|
127
|
+
implementation "com.facebook.react:react-native:+"
|
|
128
|
+
implementation 'com.github.OkHi:android-core:v1.5.9'
|
|
129
|
+
implementation 'com.github.OkHi:android-okverify:v1.9.10'
|
|
130
|
+
// From node_modules
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isNewArchitectureEnabled()) {
|
|
134
|
+
react {
|
|
135
|
+
jsRootDir = file("../src/")
|
|
136
|
+
libraryName = "Okhi"
|
|
137
|
+
codegenJavaPackageName = "com.reactnativeokhi"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
package com.reactnativeokhi;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.app.NotificationManager;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.net.Uri;
|
|
7
|
+
import android.os.Build;
|
|
8
|
+
import android.provider.Settings;
|
|
9
|
+
import android.util.Base64;
|
|
10
|
+
|
|
11
|
+
import androidx.annotation.NonNull;
|
|
12
|
+
|
|
13
|
+
import com.facebook.react.bridge.ActivityEventListener;
|
|
14
|
+
import com.facebook.react.bridge.Dynamic;
|
|
15
|
+
import com.facebook.react.bridge.Promise;
|
|
16
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
17
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
18
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
19
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
20
|
+
import com.facebook.react.bridge.WritableMap;
|
|
21
|
+
import com.facebook.react.bridge.WritableNativeMap;
|
|
22
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
23
|
+
|
|
24
|
+
import org.json.JSONObject;
|
|
25
|
+
|
|
26
|
+
import io.okhi.android_core.OkHi;
|
|
27
|
+
import io.okhi.android_core.interfaces.OkHiRequestHandler;
|
|
28
|
+
import io.okhi.android_core.models.OkHiAppContext;
|
|
29
|
+
import io.okhi.android_core.models.OkHiAuth;
|
|
30
|
+
import io.okhi.android_core.models.OkHiException;
|
|
31
|
+
import io.okhi.android_core.models.OkHiLocation;
|
|
32
|
+
import io.okhi.android_core.models.OkHiPermissionService;
|
|
33
|
+
import io.okhi.android_core.models.OkHiUser;
|
|
34
|
+
import io.okhi.android_core.models.OkPreference;
|
|
35
|
+
import io.okhi.android_okverify.OkVerify;
|
|
36
|
+
import io.okhi.android_okverify.interfaces.OkVerifyCallback;
|
|
37
|
+
import io.okhi.android_okverify.models.OkHiNotification;
|
|
38
|
+
|
|
39
|
+
@ReactModule(name = OkhiModule.NAME)
|
|
40
|
+
public class OkhiModule extends ReactContextBaseJavaModule {
|
|
41
|
+
public static final String NAME = "Okhi";
|
|
42
|
+
OkHi okHi;
|
|
43
|
+
OkVerify okVerify;
|
|
44
|
+
OkHiAuth auth;
|
|
45
|
+
|
|
46
|
+
public OkhiModule(ReactApplicationContext reactContext) {
|
|
47
|
+
super(reactContext);
|
|
48
|
+
try {
|
|
49
|
+
ActivityEventListener activityEventListener = new ActivityEventListener() {
|
|
50
|
+
@Override
|
|
51
|
+
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
|
52
|
+
if (okHi != null) {
|
|
53
|
+
okHi.onActivityResult(requestCode, resultCode, data);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Override
|
|
58
|
+
public void onNewIntent(Intent intent) {
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
reactContext.addActivityEventListener(activityEventListener);
|
|
62
|
+
} catch (Exception e) {
|
|
63
|
+
e.printStackTrace();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class RequestHandler implements OkHiRequestHandler<Boolean> {
|
|
68
|
+
Promise promise;
|
|
69
|
+
|
|
70
|
+
RequestHandler(Promise promise) {
|
|
71
|
+
this.promise = promise;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@Override
|
|
75
|
+
public void onResult(Boolean result) {
|
|
76
|
+
promise.resolve(result);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Override
|
|
80
|
+
public void onError(OkHiException exception) {
|
|
81
|
+
promise.reject(exception);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Override
|
|
86
|
+
@NonNull
|
|
87
|
+
public String getName() {
|
|
88
|
+
return NAME;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@ReactMethod
|
|
92
|
+
public void isLocationServicesEnabled(Promise promise) {
|
|
93
|
+
boolean result = OkHi.isLocationServicesEnabled(getReactApplicationContext());
|
|
94
|
+
promise.resolve(result);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@ReactMethod
|
|
98
|
+
public void isLocationPermissionGranted(Promise promise) {
|
|
99
|
+
boolean result = OkHi.isLocationPermissionGranted(getReactApplicationContext());
|
|
100
|
+
promise.resolve(result);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@ReactMethod
|
|
104
|
+
public void isBackgroundLocationPermissionGranted(Promise promise) {
|
|
105
|
+
boolean result = OkHi.isBackgroundLocationPermissionGranted(getReactApplicationContext());
|
|
106
|
+
promise.resolve(result);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@ReactMethod
|
|
110
|
+
public void isGooglePlayServicesAvailable(Promise promise) {
|
|
111
|
+
promise.resolve(OkHi.isGooglePlayServicesAvailable(getReactApplicationContext()));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@ReactMethod
|
|
115
|
+
public void requestEnableLocationServices(Promise promise) {
|
|
116
|
+
if (OkHi.isLocationServicesEnabled(getReactApplicationContext())) {
|
|
117
|
+
promise.resolve(true);
|
|
118
|
+
} else if (getCurrentActivity() == null) {
|
|
119
|
+
promise.reject(new OkHiException(OkHiException.UNKNOWN_ERROR_CODE, "Main activity hasn't loaded yet"));
|
|
120
|
+
} else {
|
|
121
|
+
okHi = new OkHi(getCurrentActivity());
|
|
122
|
+
okHi.requestEnableLocationServices(new RequestHandler(promise));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@ReactMethod
|
|
127
|
+
public void requestEnableGooglePlayServices(Promise promise) {
|
|
128
|
+
if (OkHi.isGooglePlayServicesAvailable(getReactApplicationContext())) {
|
|
129
|
+
promise.resolve(true);
|
|
130
|
+
} else if (getCurrentActivity() == null) {
|
|
131
|
+
promise.reject(new OkHiException(OkHiException.UNKNOWN_ERROR_CODE, "Main activity hasn't loaded yet"));
|
|
132
|
+
} else {
|
|
133
|
+
okHi = new OkHi(getCurrentActivity());
|
|
134
|
+
okHi.requestEnableGooglePlayServices(new RequestHandler(promise));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@ReactMethod
|
|
139
|
+
public void getSystemVersion (Promise promise) {
|
|
140
|
+
promise.resolve(android.os.Build.VERSION.SDK_INT);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@ReactMethod
|
|
144
|
+
public void getAuthToken(String branchId, String clientKey, Promise promise) {
|
|
145
|
+
String concat = branchId + ":" + clientKey;
|
|
146
|
+
String token = Base64.encodeToString(concat.getBytes(), Base64.NO_WRAP);
|
|
147
|
+
promise.resolve("Token " + token);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@ReactMethod
|
|
151
|
+
public void initialize(String configuration, Promise promise) {
|
|
152
|
+
try {
|
|
153
|
+
JSONObject config = new JSONObject(configuration);
|
|
154
|
+
String branchId = config.getJSONObject("credentials").getString("branchId");
|
|
155
|
+
String clientKey = config.getJSONObject("credentials").getString("clientKey");
|
|
156
|
+
String mode = config.getJSONObject("context").getString("mode");
|
|
157
|
+
String developer = config.getJSONObject("context").optString("developer", "external");
|
|
158
|
+
OkHiAppContext context = new OkHiAppContext(getReactApplicationContext(), mode, "react-native", developer);
|
|
159
|
+
auth = new OkHiAuth(getReactApplicationContext(), branchId, clientKey, context);
|
|
160
|
+
if (getCurrentActivity() != null && getCurrentActivity().getApplicationContext() != null) {
|
|
161
|
+
okVerify = new OkVerify.Builder(getCurrentActivity(), auth).build();
|
|
162
|
+
if (config.has("notification")) {
|
|
163
|
+
JSONObject notificationConfig = config.getJSONObject("notification");
|
|
164
|
+
int importance = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? NotificationManager.IMPORTANCE_DEFAULT : 3;
|
|
165
|
+
OkVerify.init(getReactApplicationContext(), new OkHiNotification(
|
|
166
|
+
notificationConfig.optString("title", "Verification in progress"),
|
|
167
|
+
notificationConfig.optString("text", "Address Verification in progress"),
|
|
168
|
+
notificationConfig.optString("channelId", "okhi"),
|
|
169
|
+
notificationConfig.optString("channelName", "OkHi Channel"),
|
|
170
|
+
notificationConfig.optString("channelDescription", "OkHi verification alerts"),
|
|
171
|
+
importance
|
|
172
|
+
));
|
|
173
|
+
}
|
|
174
|
+
promise.resolve(true);
|
|
175
|
+
} else {
|
|
176
|
+
promise.resolve(false);
|
|
177
|
+
}
|
|
178
|
+
} catch (Exception e) {
|
|
179
|
+
e.printStackTrace();
|
|
180
|
+
promise.reject("unauthorized", "unable to parse credentials", e);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@ReactMethod
|
|
185
|
+
public void startAddressVerification(String phoneNumber, String locationId, Float lat, Float lon, ReadableMap config, Promise promise) {
|
|
186
|
+
if (okVerify == null) {
|
|
187
|
+
promise.reject("unauthorized", "failed to initialise okhi");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
OkHiUser user = new OkHiUser.Builder(phoneNumber).build();
|
|
191
|
+
OkHiLocation location = new OkHiLocation.Builder(locationId, lat, lon).build();
|
|
192
|
+
Boolean withForeground = true;
|
|
193
|
+
Dynamic foregroundConfig = getConfig(config, "withForeground");
|
|
194
|
+
if(foregroundConfig != null) {
|
|
195
|
+
withForeground = foregroundConfig.asBoolean();
|
|
196
|
+
}
|
|
197
|
+
okVerify.start(user, location, withForeground, new OkVerifyCallback<String>() {
|
|
198
|
+
@Override
|
|
199
|
+
public void onSuccess(String result) {
|
|
200
|
+
promise.resolve(result);
|
|
201
|
+
}
|
|
202
|
+
@Override
|
|
203
|
+
public void onError(OkHiException e) {
|
|
204
|
+
promise.reject(e.getCode(), e.getMessage(), e);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@ReactMethod
|
|
210
|
+
public void stopAddressVerification(String phoneNumber, String locationId, Promise promise) {
|
|
211
|
+
OkVerify.stop(getReactApplicationContext(), locationId, new OkVerifyCallback<String>() {
|
|
212
|
+
@Override
|
|
213
|
+
public void onSuccess(String result) {
|
|
214
|
+
promise.resolve(result);
|
|
215
|
+
}
|
|
216
|
+
@Override
|
|
217
|
+
public void onError(OkHiException e) {
|
|
218
|
+
promise.reject(e.getCode(), e.getMessage(), e);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@ReactMethod
|
|
224
|
+
public void startForegroundService(Promise promise) {
|
|
225
|
+
try {
|
|
226
|
+
OkVerify.startForegroundService(getReactApplicationContext());
|
|
227
|
+
promise.resolve(true);
|
|
228
|
+
} catch (OkHiException e) {
|
|
229
|
+
e.printStackTrace();
|
|
230
|
+
promise.reject(e.getCode(), e.getMessage(), e);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@ReactMethod
|
|
235
|
+
public void stopForegroundService(Promise promise) {
|
|
236
|
+
OkVerify.stopForegroundService(getReactApplicationContext());
|
|
237
|
+
promise.resolve(true);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@ReactMethod
|
|
241
|
+
public void isForegroundServiceRunning(Promise promise) {
|
|
242
|
+
Boolean result = OkVerify.isForegroundServiceRunning(getReactApplicationContext());
|
|
243
|
+
promise.resolve(result);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@ReactMethod
|
|
247
|
+
public void openAppSettings(Promise promise) {
|
|
248
|
+
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
249
|
+
Uri uri = Uri.fromParts("package", getReactApplicationContext().getPackageName(), null);
|
|
250
|
+
intent.setData(uri);
|
|
251
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
252
|
+
getReactApplicationContext().startActivity(intent);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@ReactMethod
|
|
256
|
+
public void canOpenProtectedAppsSettings(Promise promise) {
|
|
257
|
+
promise.resolve(OkHiPermissionService.canOpenProtectedApps(getReactApplicationContext()));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@ReactMethod
|
|
261
|
+
public void openProtectedAppsSettings(Promise promise) {
|
|
262
|
+
try {
|
|
263
|
+
Activity activity = getCurrentActivity();
|
|
264
|
+
if (activity != null) {
|
|
265
|
+
OkHiPermissionService.openProtectedAppsSettings(getCurrentActivity(), 69);
|
|
266
|
+
promise.resolve(true);
|
|
267
|
+
} else {
|
|
268
|
+
throw new OkHiException(OkHiException.UNKNOWN_ERROR_CODE, "unable to retrieve current activity");
|
|
269
|
+
}
|
|
270
|
+
} catch (OkHiException e) {
|
|
271
|
+
promise.reject(e.getCode(), e.getMessage(), e);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
@ReactMethod
|
|
276
|
+
public void retrieveDeviceInfo(Promise promise) {
|
|
277
|
+
WritableMap map = new WritableNativeMap();
|
|
278
|
+
map.putString("manufacturer", Build.MANUFACTURER);
|
|
279
|
+
map.putString("model", Build.MODEL);
|
|
280
|
+
promise.resolve(map);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private Dynamic getConfig(ReadableMap map, String prop) {
|
|
284
|
+
if (map != null && map.hasKey("android")) {
|
|
285
|
+
ReadableMap config = map.getMap("android");
|
|
286
|
+
if (config.hasKey("withForeground")) {
|
|
287
|
+
return config.getDynamic("withForeground");
|
|
288
|
+
} else {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Required for rn built in EventEmitter Calls.
|
|
296
|
+
@ReactMethod
|
|
297
|
+
public void addListener(String eventName) {
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@ReactMethod
|
|
302
|
+
public void removeListeners(Integer count) {
|
|
303
|
+
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@ReactMethod
|
|
307
|
+
public void setItem(String key, String value, Promise promise) {
|
|
308
|
+
try {
|
|
309
|
+
OkPreference.setItem(key, value, getReactApplicationContext());
|
|
310
|
+
promise.resolve(true);
|
|
311
|
+
} catch (OkHiException e) {
|
|
312
|
+
promise.reject(e.getCode(), e.getMessage(), e);
|
|
313
|
+
e.printStackTrace();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package com.reactnativeokhi;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.ReactPackage;
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
9
|
+
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
|
|
14
|
+
public class OkhiPackage implements ReactPackage {
|
|
15
|
+
@NonNull
|
|
16
|
+
@Override
|
|
17
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
18
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
19
|
+
modules.add(new OkhiModule(reactContext));
|
|
20
|
+
return modules;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@NonNull
|
|
24
|
+
@Override
|
|
25
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
26
|
+
return Collections.emptyList();
|
|
27
|
+
}
|
|
28
|
+
}
|