@qore-id/react-native-qoreid-sdk 0.1.0-snapshot

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 (56) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +127 -0
  3. package/android/Untitled +0 -0
  4. package/android/build.gradle +109 -0
  5. package/android/gradle.properties +9 -0
  6. package/android/src/main/AndroidManifest.xml +4 -0
  7. package/android/src/main/java/com/qoreidsdk/QoreIdJSData.kt +49 -0
  8. package/android/src/main/java/com/qoreidsdk/QoreIdReactButtonFragment.kt +116 -0
  9. package/android/src/main/java/com/qoreidsdk/QoreIdReactButtonManager.kt +168 -0
  10. package/android/src/main/java/com/qoreidsdk/QoreidSdkModule.kt +88 -0
  11. package/android/src/main/java/com/qoreidsdk/QoreidSdkPackage.kt +20 -0
  12. package/android/src/main/java/com/qoreidsdk/StyleOption.kt +7 -0
  13. package/ios/QoreidSdk.h +12 -0
  14. package/ios/QoreidSdk.mm +27 -0
  15. package/ios/QoreidSdk.xcodeproj/project.pbxproj +274 -0
  16. package/ios/QoreidSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  17. package/lib/commonjs/index.js +25 -0
  18. package/lib/commonjs/index.js.map +1 -0
  19. package/lib/commonjs/qoreIdButton.android.js +97 -0
  20. package/lib/commonjs/qoreIdButton.android.js.map +1 -0
  21. package/lib/commonjs/qoreIdButton.ios.js +129 -0
  22. package/lib/commonjs/qoreIdButton.ios.js.map +1 -0
  23. package/lib/commonjs/react-native-qoreid-sdk.d.js +6 -0
  24. package/lib/commonjs/react-native-qoreid-sdk.d.js.map +1 -0
  25. package/lib/commonjs/types.d.js +6 -0
  26. package/lib/commonjs/types.d.js.map +1 -0
  27. package/lib/commonjs/utils.js +20 -0
  28. package/lib/commonjs/utils.js.map +1 -0
  29. package/lib/module/index.js +4 -0
  30. package/lib/module/index.js.map +1 -0
  31. package/lib/module/qoreIdButton.android.js +88 -0
  32. package/lib/module/qoreIdButton.android.js.map +1 -0
  33. package/lib/module/qoreIdButton.ios.js +121 -0
  34. package/lib/module/qoreIdButton.ios.js.map +1 -0
  35. package/lib/module/react-native-qoreid-sdk.d.js +2 -0
  36. package/lib/module/react-native-qoreid-sdk.d.js.map +1 -0
  37. package/lib/module/types.d.js +2 -0
  38. package/lib/module/types.d.js.map +1 -0
  39. package/lib/module/utils.js +13 -0
  40. package/lib/module/utils.js.map +1 -0
  41. package/lib/typescript/index.d.ts +5 -0
  42. package/lib/typescript/index.d.ts.map +1 -0
  43. package/lib/typescript/qoreIdButton.android.d.ts +4 -0
  44. package/lib/typescript/qoreIdButton.android.d.ts.map +1 -0
  45. package/lib/typescript/qoreIdButton.ios.d.ts +4 -0
  46. package/lib/typescript/qoreIdButton.ios.d.ts.map +1 -0
  47. package/lib/typescript/utils.d.ts +9 -0
  48. package/lib/typescript/utils.d.ts.map +1 -0
  49. package/package.json +165 -0
  50. package/react-native-qoreid-sdk.podspec +35 -0
  51. package/src/index.tsx +10 -0
  52. package/src/qoreIdButton.android.tsx +136 -0
  53. package/src/qoreIdButton.ios.tsx +150 -0
  54. package/src/react-native-qoreid-sdk.d.ts +3 -0
  55. package/src/types.d.ts +99 -0
  56. package/src/utils.ts +73 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Emmanuel Ugwuoke
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,127 @@
1
+ # @qore-id/react-native-qoreid-sdk
2
+
3
+ QoreID React Native SDK
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install @qore-id/react-native-qoreid-sdk
9
+ ```
10
+
11
+ ```sh
12
+ yarn add @qore-id/react-native-qoreid-sdk
13
+ ```
14
+
15
+ ### Android
16
+
17
+ Add the following to your `app/build.gradle`
18
+ ```groovy
19
+ repositories {
20
+ ...
21
+ maven {
22
+ url "https://repo.qoreid.com/repository/maven-releases/"
23
+ }
24
+ }
25
+ ```
26
+
27
+ ### iOS
28
+
29
+ You will be required to install WebView package if you don't already have it installed in your project.
30
+
31
+ ```sh
32
+ npm i react-native-webview
33
+ ```
34
+
35
+
36
+
37
+
38
+ ## Usage
39
+
40
+ ```tsx
41
+ //verify.android.tsx
42
+ import React from 'react'
43
+ import { QoreIdButton } from '@qore-id/react-native-qoreid-sdk';
44
+
45
+
46
+ function App() {
47
+
48
+ let clientId = /* CLIENT ID */
49
+ const customButton = ({ onPress }) => <Button onPress={onPress} title="QoreId Button" />
50
+
51
+ const onError = (data) => {
52
+ console.error(data);
53
+ Alert.alert('Error', data);
54
+ };
55
+
56
+ const onSumitted = (data) => {
57
+ console.debug(data);
58
+ Alert.alert('Sumitted', data);
59
+ };
60
+
61
+ const onClosed = (data) => {
62
+ console.debug(data);
63
+ Alert.alert('Closed', data);
64
+ };
65
+
66
+ return (
67
+ <View>
68
+ {/* Other components */}
69
+ <QoreIdButton
70
+ title="Verify"
71
+ flowId=""
72
+ clientId={clientId} {/* Required */}
73
+ productCode="" {/* Required */}
74
+ customerReference={customerRef} {/* Required */}
75
+ applicantData={{
76
+ firstName:"",
77
+ middleName:"",
78
+ lastName:"",
79
+ gender:"",
80
+ phoneNumber:"",
81
+ email:"",
82
+ }}
83
+ identityData={{ idType: "", idNumber:"" }}
84
+ addressData={{
85
+ address: "",
86
+ city:"",
87
+ lga:"",
88
+ }}
89
+ ocrAcceptedDocuments="DRIVERS_LICENSE_NGA,VOTERS_CARD_NGA,NIN_SLIP_NGA,PASSPORT_NGA"
90
+ onQoreIDSdkSubmitted={onSumitted}
91
+ onQoreIDSdkError={onError}
92
+ onQoreIDSdkClosed={onClosed}
93
+ render={customButton} {/* Only supported for iOS */}
94
+ />
95
+ </View>
96
+ )
97
+ }
98
+
99
+ ```
100
+
101
+
102
+
103
+ ### Utilities
104
+
105
+ QoreId SDK exposes utilities that you can easily use
106
+
107
+ ```tsx
108
+
109
+ import React from 'react'
110
+ import { QoreIdButton, utils } from '@qore-id/react-native-qoreid-sdk';
111
+
112
+ function App() {
113
+
114
+ // Array of string
115
+ //For more information check -> https://docs.qoreid.com/docs/product-codes
116
+ const productIds = utils.productCodes;
117
+
118
+
119
+ //An array of accepted documents in a specific country
120
+ //For more information check -> https://docs.qoreid.com/docs/ocr-accepted-documents#accepted-documents-for-ocr-verifications
121
+ const ocrLists = utils.acceptedDocuments["Nigeria"]
122
+ ...
123
+ }
124
+
125
+ ```
126
+ - Link to [doc/product-code]('https://docs.qoreid.com/docs/product-codes')
127
+ - Link to [doc/accepted-documents]('https://docs.qoreid.com/docs/ocr-accepted-documents#accepted-documents-for-ocr-verifications')
Binary file
@@ -0,0 +1,109 @@
1
+ buildscript {
2
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["QoreidSdk_kotlinVersion"]
4
+ repositories {
5
+ google()
6
+ mavenCentral()
7
+ }
8
+
9
+
10
+ dependencies {
11
+ classpath "com.android.tools.build:gradle:7.2.1"
12
+ // noinspection DifferentKotlinGradleVersion
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ }
15
+ }
16
+
17
+ def isNewArchitectureEnabled() {
18
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
+ }
20
+
21
+ apply plugin: "com.android.library"
22
+ apply plugin: "kotlin-android"
23
+ apply plugin: "maven-publish"
24
+
25
+
26
+ def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
27
+
28
+ if (isNewArchitectureEnabled()) {
29
+ apply plugin: "com.facebook.react"
30
+ }
31
+
32
+ def getExtOrDefault(name) {
33
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["QoreidSdk_" + name]
34
+ }
35
+
36
+ def getExtOrIntegerDefault(name) {
37
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["QoreidSdk_" + name]).toInteger()
38
+ }
39
+
40
+ android {
41
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
42
+ sourceSets {
43
+ main {
44
+ // ...
45
+ res.srcDirs = ['src/main/res']
46
+ }
47
+ }
48
+ defaultConfig {
49
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
50
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
51
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
52
+ multiDexEnabled true
53
+ }
54
+ buildTypes {
55
+ release {
56
+ minifyEnabled false
57
+ }
58
+ debug {
59
+ gradle.properties['isReleaseBuild'] = false
60
+ }
61
+ }
62
+
63
+ lintOptions {
64
+ disable "GradleCompatible"
65
+ }
66
+
67
+ compileOptions {
68
+ sourceCompatibility JavaVersion.VERSION_1_8
69
+ targetCompatibility JavaVersion.VERSION_1_8
70
+ }
71
+
72
+ kotlinOptions {
73
+ jvmTarget = "1.8"
74
+ }
75
+
76
+
77
+ }
78
+
79
+ repositories {
80
+ mavenCentral()
81
+ google()
82
+ mavenLocal()
83
+ maven { url "https://repo.qoreid.com/repository/maven-releases/" }
84
+ maven { url 'https://jitpack.io' }
85
+ }
86
+
87
+ def kotlin_version = getExtOrDefault("kotlinVersion")
88
+
89
+
90
+ dependencies {
91
+ // For < 0.71, this will be from the local maven repo
92
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
93
+ //noinspection GradleDynamicVersion
94
+ implementation 'com.qoreid:qoreid-sdk:1.0.1'
95
+ implementation 'com.google.android.material:material:1.7.0'
96
+ implementation "com.google.code.gson:gson:2.8.5"
97
+ implementation "com.facebook.react:react-native:+"
98
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
99
+
100
+ }
101
+
102
+
103
+ if (isNewArchitectureEnabled()) {
104
+ react {
105
+ jsRootDir = file("../src/")
106
+ libraryName = "QoreidSdk"
107
+ codegenJavaPackageName = "com.qoreidsdk"
108
+ }
109
+ }
@@ -0,0 +1,9 @@
1
+ QoreidSdk_kotlinVersion=1.7.0
2
+ QoreidSdk_minSdkVersion=21
3
+ QoreidSdk_targetSdkVersion=31
4
+ QoreidSdk_compileSdkVersion=31
5
+ QoreidSdk_ndkversion=21.4.7075529
6
+ android.useAndroidX=true
7
+ android.enableJetifier=true
8
+ isReleaseBuild=true
9
+
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.qoreidsdk">
3
+
4
+ </manifest>
@@ -0,0 +1,49 @@
1
+ package com.qoreidsdk
2
+
3
+ data class Config (
4
+ val flowId: Long? = 0,
5
+ val customerRef: String,
6
+ val productCode: String,
7
+ val clientId: String,
8
+ )
9
+
10
+ data class ApplicantData(
11
+ val firstName: String,
12
+ val lastName: String,
13
+ val phoneNumber: String,
14
+ val email: String,
15
+ val dob: String,
16
+ val gender: String,
17
+ val middleName:String
18
+ )
19
+
20
+ data class IdentityData(
21
+ val idType: String,
22
+ val idNumber: String,
23
+ )
24
+
25
+ data class AddressData(
26
+ val address: String,
27
+ val town: String,
28
+ val lga: String,
29
+ val city: String,
30
+ val state: String,
31
+ val region: String,
32
+ val district: String,
33
+ val virAddress: String
34
+ )
35
+
36
+ data class QoreIdJSData(
37
+ val config: Config,
38
+ val applicantData: ApplicantData,
39
+ val addressData: AddressData,
40
+ val acceptedDocuments: List<String>,
41
+ val identityData: IdentityData
42
+ )
43
+
44
+
45
+ data class StyleOptionsData (
46
+ val color:String,
47
+ val backgroundColor:String,
48
+ val title: String
49
+ )
@@ -0,0 +1,116 @@
1
+ package com.qoreidsdk
2
+
3
+
4
+ import android.graphics.Color
5
+ import android.os.Bundle
6
+ import android.util.Log
7
+ import android.view.LayoutInflater
8
+ import android.view.View
9
+ import android.view.ViewGroup
10
+ import androidx.fragment.app.Fragment
11
+ import com.google.gson.Gson
12
+ import com.qoreid.sdk.core.QoreIDButton
13
+ import com.qoreid.sdk.core.QoreIDParams
14
+ import com.qoreid.sdk.core.models.AddressData
15
+ import com.qoreid.sdk.core.models.ApplicantData
16
+
17
+
18
+ class QoreIdReactButtonFragment : Fragment() {
19
+ private lateinit var qoredIdButton: QoreIDButton
20
+ var clientId: String = ""
21
+ var buttonPropsString: String = "";
22
+ private val gson = Gson()
23
+
24
+ override fun onCreateView(
25
+ inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
26
+ ): View {
27
+ super.onCreateView(inflater, container, savedInstanceState)
28
+ qoredIdButton = QoreIDButton(requireContext())
29
+ qoredIdButton.setText("Launch QoreID")
30
+ if (buttonPropsString != "") {
31
+ val buttonProps = gson.fromJson(buttonPropsString, StyleOptionsData::class.java)
32
+ qoredIdButton.setText(buttonProps.title)
33
+
34
+ }
35
+
36
+
37
+ return qoredIdButton // this qoreIdButton could be any view that you want to render
38
+ }
39
+
40
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
41
+ super.onViewCreated(view, savedInstanceState)
42
+
43
+ qoredIdButton
44
+ .params(
45
+ QoreIDParams()
46
+ .clientId(clientId)
47
+ )
48
+
49
+ }
50
+
51
+
52
+ fun dataEventListener(jsonData: String) {
53
+ Log.i("QoredID Event", "listening")
54
+ Log.d("INITIALIze",::qoredIdButton.isInitialized.toString())
55
+ if (!::qoredIdButton.isInitialized) {
56
+ return
57
+ }
58
+
59
+ val qoreIdJSData = gson.fromJson(jsonData, QoreIdJSData::class.java)
60
+
61
+ Log.i("QOREIDPARAMS", qoreIdJSData.toString())
62
+
63
+ val config = qoreIdJSData.config
64
+ val apD = qoreIdJSData.applicantData
65
+ val applicantData = ApplicantData(
66
+ apD.firstName,
67
+ apD.lastName,
68
+ apD.phoneNumber,
69
+ apD.middleName,
70
+ apD.dob,
71
+ apD.dob,
72
+ apD.gender
73
+ )
74
+
75
+ val adD = qoreIdJSData.addressData
76
+ val addressData = AddressData(
77
+ adD.address,
78
+ adD.city,
79
+ adD.lga,
80
+ adD.state,
81
+ )
82
+
83
+
84
+ val qoreIDParams = if (config.flowId != 0L) {
85
+ QoreIDParams()
86
+ .clientId(config.clientId)
87
+ .customerReference(qoreIdJSData.config.customerRef)
88
+ .inputData(applicantData, addressData)
89
+ .ocrAcceptedDocuments(qoreIdJSData.acceptedDocuments)
90
+ .workflow(config.flowId!!)
91
+ } else {
92
+ QoreIDParams()
93
+ .clientId(config.clientId)
94
+ .customerReference(qoreIdJSData.config.customerRef)
95
+ .inputData(applicantData, addressData)
96
+ .ocrAcceptedDocuments(qoreIdJSData.acceptedDocuments)
97
+ .collection(config.productCode)
98
+ }
99
+
100
+ qoredIdButton
101
+ .params(qoreIDParams)
102
+
103
+ }
104
+
105
+ companion object {
106
+ private var instance: QoreIdReactButtonFragment? = null
107
+
108
+ fun getInstance(): QoreIdReactButtonFragment {
109
+ if (instance == null) {
110
+ instance = QoreIdReactButtonFragment()
111
+ }
112
+ return instance as QoreIdReactButtonFragment
113
+ }
114
+ }
115
+ }
116
+
@@ -0,0 +1,168 @@
1
+ package com.qoreidsdk
2
+
3
+
4
+ import android.util.Log
5
+ import android.view.Choreographer
6
+ import android.view.View
7
+ import android.view.ViewGroup
8
+ import android.view.ViewTreeObserver
9
+ import android.widget.FrameLayout
10
+ import androidx.fragment.app.FragmentActivity
11
+ import com.facebook.react.bridge.ReactApplicationContext
12
+ import com.facebook.react.bridge.ReadableArray
13
+ import com.facebook.react.uimanager.ThemedReactContext
14
+ import com.facebook.react.uimanager.ViewGroupManager
15
+ import com.facebook.react.uimanager.annotations.ReactPropGroup
16
+
17
+ class QoreIdReactButtonManager(
18
+ private val reactContext: ReactApplicationContext
19
+ ) : ViewGroupManager<FrameLayout>() {
20
+ private var propWidth: Int? = null
21
+ private var propHeight: Int? = null
22
+
23
+ override fun getName() = REACT_CLASS
24
+
25
+ /**
26
+ * Return a FrameLayout which will later hold the Fragment
27
+ */
28
+ override fun createViewInstance(reactContext: ThemedReactContext): FrameLayout {
29
+ return FrameLayout(reactContext)
30
+ }
31
+
32
+
33
+ /**
34
+ * Map the "create, update" command to an integer
35
+ */
36
+ override fun getCommandsMap() = mapOf(
37
+ "create" to COMMAND_CREATE,
38
+ "update" to COMMAND_DATA_CHANGE,
39
+ )
40
+
41
+ /**
42
+ * Handle "create, update" command (called from JS) and call createFragment method
43
+ */
44
+ override fun receiveCommand(
45
+ root: FrameLayout, commandId: String, args: ReadableArray?
46
+ ) {
47
+ super.receiveCommand(root, commandId, args)
48
+
49
+
50
+ when (commandId.toInt()) {
51
+ COMMAND_CREATE -> {
52
+ val reactNativeViewId = requireNotNull(args).getInt(0)
53
+ var clientId = requireNotNull(args).getString(1)
54
+ var btnString = args?.getString(2) ?: ""
55
+
56
+ createFragment(root, reactNativeViewId, clientId, btnString)
57
+ }
58
+ COMMAND_DATA_CHANGE -> {
59
+ val data = requireNotNull(args).getString(0)
60
+ onDataChange(data);
61
+ }
62
+ }
63
+ }
64
+
65
+ @ReactPropGroup(names = ["width", "height"], customType = "Style")
66
+ fun setStyle(view: FrameLayout, index: Int, value: Int) {
67
+ if (index == 0) propWidth = value
68
+ if (index == 1) propHeight = value
69
+ }
70
+
71
+
72
+ /**
73
+ * Replace your React Native view with a custom fragment
74
+ */
75
+ fun createFragment(root: FrameLayout, reactNativeViewId: Int, clientId: String, btn: String?) {
76
+ val parentView = root.findViewById<ViewGroup>(reactNativeViewId)
77
+ setupLayout(parentView)
78
+
79
+ val mFragment = QoreIdReactButtonFragment.getInstance()
80
+ mFragment.clientId = clientId
81
+
82
+ if(btn != null) {
83
+ mFragment.buttonPropsString = btn
84
+ }
85
+ val activity = reactContext.currentActivity as FragmentActivity
86
+ activity.supportFragmentManager.beginTransaction()
87
+ .replace(reactNativeViewId, mFragment, reactNativeViewId.toString()).commit()
88
+
89
+ // Add an `OnGlobalLayoutListener` to the parent view to detect when the view is unmounted
90
+ parentView.viewTreeObserver.addOnGlobalLayoutListener(object :
91
+ ViewTreeObserver.OnGlobalLayoutListener {
92
+ override fun onGlobalLayout() {
93
+ // Remove the fragment if the parent view is no longer attached to the window or its parent
94
+ if (!parentView.isAttachedToWindow || parentView.parent == null) {
95
+ val fragment =
96
+ activity.supportFragmentManager.findFragmentById(reactNativeViewId)
97
+ if (fragment != null) {
98
+ activity.supportFragmentManager.beginTransaction().remove(fragment).commit()
99
+ }
100
+ parentView.viewTreeObserver.removeOnGlobalLayoutListener(this)
101
+
102
+ }
103
+ }
104
+ })
105
+
106
+ // Add an `OnAttachStateChangeListener` to the parent view to detect when the view is unmounted
107
+ parentView.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
108
+ override fun onViewAttachedToWindow(view: View) {
109
+ // Do nothing
110
+ }
111
+
112
+ override fun onViewDetachedFromWindow(view: View) {
113
+
114
+ }
115
+ })
116
+ }
117
+
118
+ // function for listening on that changes from RN app
119
+ fun onDataChange(str: String) {
120
+ val mFragment = QoreIdReactButtonFragment.getInstance()
121
+ mFragment.dataEventListener(str)
122
+ }
123
+
124
+ fun setupLayout(view: View) {
125
+ Choreographer.getInstance().postFrameCallback(object : Choreographer.FrameCallback {
126
+ override fun doFrame(frameTimeNanos: Long) {
127
+ manuallyLayoutChildren(view)
128
+ view.viewTreeObserver.dispatchOnGlobalLayout()
129
+ Choreographer.getInstance().postFrameCallback(this)
130
+ }
131
+ })
132
+ }
133
+
134
+ /**
135
+ * Layout all children properly
136
+ */
137
+ private fun manuallyLayoutChildren(view: View) {
138
+
139
+ // Get the parent view's dimensions
140
+ val parentWidth =
141
+ view.parent as? View ?: return // return if the parent is null or not a view
142
+ val width = parentWidth.width
143
+
144
+ val parentHeight =
145
+ view.parent as? View ?: return // return if the parent is null or not a view
146
+ val height = parentHeight.height
147
+
148
+ view.measure(
149
+ View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
150
+ View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY)
151
+ )
152
+
153
+ // Set the view's layout params to match parent width and height
154
+ val layoutParams = view.layoutParams
155
+ layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT
156
+ layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
157
+ view.layoutParams = layoutParams
158
+
159
+ view.layout(0, 0, width, height)
160
+ }
161
+
162
+
163
+ companion object {
164
+ private const val REACT_CLASS = "QoreIdReactButtonManager"
165
+ private const val COMMAND_CREATE = 1
166
+ private const val COMMAND_DATA_CHANGE = 2
167
+ }
168
+ }
@@ -0,0 +1,88 @@
1
+ package com.qoreidsdk
2
+
3
+
4
+
5
+ import android.app.Activity
6
+ import android.content.Intent
7
+ import android.os.Build
8
+ import com.facebook.react.bridge.*
9
+ import com.facebook.react.modules.core.DeviceEventManagerModule
10
+ import com.qoreid.sdk.core.QoreIdSdkKt.QORE_ID_RESULT_CODE
11
+ import com.qoreid.sdk.core.QoreIdSdkKt.QORE_ID_RESULT_EXTRA_KEY
12
+ import com.qoreid.sdk.core.models.ErrorResult
13
+ import com.qoreid.sdk.core.models.QoreIDResult
14
+ import com.qoreid.sdk.core.models.SuccessResult
15
+
16
+
17
+ class QoreidSdkModule(val reactContext: ReactApplicationContext) :
18
+ ReactContextBaseJavaModule(reactContext) {
19
+
20
+ private var qoreIdResult: QoreIDResult? = null;
21
+
22
+ private val activityEventListener =
23
+ object : BaseActivityEventListener() {
24
+ override fun onActivityResult(
25
+ activity: Activity?,
26
+ requestCode: Int,
27
+ resultCode: Int,
28
+ intent: Intent?
29
+ ) {
30
+
31
+ if (resultCode == QORE_ID_RESULT_CODE && intent != null) {
32
+ qoreIdResult = if (Build.VERSION.SDK_INT < 33) {
33
+ intent.extras?.getSerializable(QORE_ID_RESULT_EXTRA_KEY) as QoreIDResult
34
+ } else {
35
+ intent.extras?.getSerializable(QORE_ID_RESULT_EXTRA_KEY, QoreIDResult::class.java)
36
+ }
37
+
38
+ processQoreIDResult(reactContext, qoreIdResult!!)
39
+ }
40
+ }
41
+ }
42
+
43
+ init {
44
+ reactContext.addActivityEventListener(activityEventListener)
45
+ }
46
+
47
+ override fun getName(): String {
48
+ return NAME
49
+ }
50
+
51
+
52
+ fun processQoreIDResult(context: ReactContext, qoreIdResult: QoreIDResult) {
53
+ when (qoreIdResult) {
54
+ is ErrorResult -> {
55
+ // Handle error.
56
+ val event = Arguments.createMap().apply {
57
+ putString("code", qoreIdResult.code.toString())
58
+ putString("data", qoreIdResult.data.toString())
59
+ putString("message", qoreIdResult.message)
60
+ }
61
+
62
+ sendEvent(context, "onResult", event)
63
+
64
+ }
65
+ is SuccessResult -> {
66
+ // Handle success.
67
+ val event = Arguments.createMap().apply {
68
+ putString("data", qoreIdResult.data.toString())
69
+ putString("message", qoreIdResult.message)
70
+ }
71
+
72
+ sendEvent(context, "onResult", event)
73
+ }
74
+ }
75
+ }
76
+
77
+
78
+ private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
79
+ reactContext
80
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
81
+ .emit(eventName, params)
82
+ }
83
+
84
+ companion object {
85
+ const val NAME = "QoreidSdk"
86
+ }
87
+
88
+ }