react-native-okaycam 3.0.4 → 3.0.6
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/README.md +42 -131
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/innov8tif/rnokaycam/RNOkayCamModule.java +28 -59
- package/index.ts +26 -68
- package/ios/RNOkayCam.swift +68 -105
- package/package.json +1 -1
- package/react-native-okaycam.podspec +1 -1
package/README.md
CHANGED
|
@@ -46,22 +46,25 @@ use_frameworks!
|
|
|
46
46
|
|
|
47
47
|
post_install do |installer|
|
|
48
48
|
installer.pods_project.targets.each do |target|
|
|
49
|
-
if target.name == "CryptoSwift"
|
|
50
|
-
puts "Enable module stability for CryptoSwift"
|
|
51
|
-
target.build_configurations.each do |config|
|
|
52
|
-
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
49
|
if (target.name&.eql?('FBReactNativeSpec'))
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
target.build_phases.each do |build_phase|
|
|
51
|
+
if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
|
|
52
|
+
target.build_phases.move(build_phase, 0)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
61
55
|
end
|
|
62
56
|
target.build_configurations.each do |config|
|
|
63
57
|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
|
|
64
58
|
config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
|
|
59
|
+
if target.name == "CryptoSwift"
|
|
60
|
+
puts "Enable module stability for CryptoSwift"
|
|
61
|
+
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
if target.name == 'fmt'
|
|
65
|
+
puts "Enable module stability for fmt"
|
|
66
|
+
config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++17'
|
|
67
|
+
end
|
|
65
68
|
end
|
|
66
69
|
end
|
|
67
70
|
end
|
|
@@ -106,134 +109,42 @@ const license = Platform.select({
|
|
|
106
109
|
|
|
107
110
|
### Configuration
|
|
108
111
|
|
|
109
|
-
| -
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
| - | showOverlay | transparent black overlay | true |
|
|
119
|
-
| topLabel | text | text of the top label | ""(empty string) |
|
|
120
|
-
| topLabel | color | color of the top label | #ffffff |
|
|
121
|
-
| topLabel | size | text size of the top label | 20 |
|
|
122
|
-
| bottomLabel | text | text of the bottom label | ""(empty string) |
|
|
123
|
-
| bottomLabel | color | color of the bottom label | #ffffff |
|
|
124
|
-
| bottomLabel | size | text size of the bottom label | 20 |
|
|
125
|
-
| timer | backgroundColor | background of the count down timer | #ffa500 |
|
|
126
|
-
| timer | textColor | text color of the count down timer | #ffffff |
|
|
127
|
-
| confirmBtnConfig | backgroundColor | background color of the confirm button | #ffa500 |
|
|
128
|
-
| confirmBtnConfig | contentColor | content color of the confirm button | #ffffff |
|
|
129
|
-
| retakeBtnConfig | backgroundColor | background color of the retake button | #ffa500 |
|
|
130
|
-
| retakeBtnConfig | contentColor | content color of the retake button | #ffffff |
|
|
131
|
-
| - | captureBtnColor | color of the capture button | #ffffff |
|
|
132
|
-
| - | firstPhotoConfig | config for the first capture | delay:0s,onFlash:false,outputPath: null |
|
|
133
|
-
| - | secondPhotoConfig | config for the second capture | null |
|
|
134
|
-
| preview | title | title on preview screen | ""(empty string) |
|
|
135
|
-
| preview | refImg | ref image on preview screen | null |
|
|
136
|
-
| preview | instruction1 | instruction on preview screen | ""(empty string) |
|
|
137
|
-
| preview | instruction2 | instruction on preview screen | ""(empty string) |
|
|
138
|
-
| preview | instruction3 | instruction on preview screen | ""(empty string) |
|
|
139
|
-
| preview | backgroundColor | background color of preview screen | null |
|
|
140
|
-
| instruction <sup>**New**</sup> | title | Instruction's title on camera caputre screen | ""(empty string) |
|
|
141
|
-
| instruction <sup>**New**</sup> | refImage1 | Instruction's reference image 1 | null |
|
|
142
|
-
| instruction <sup>**New**</sup> | refImage2 | Instruction's reference image 2 | null |
|
|
143
|
-
| - | showPreviewInstruction | Show or hide preview instruction for captured photos | false |
|
|
144
|
-
| - | autoCapture <sup>**New**</sup> | Boolean to auto capture document | false |
|
|
112
|
+
| - | Property name | Description | Default value |
|
|
113
|
+
| ----------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
|
|
114
|
+
| | width | width to resize the image | 2000 |
|
|
115
|
+
| | imageQuality | quality of cropped image | 1.0f |
|
|
116
|
+
| | **<sup>New</sup>** autoCapture | When set to `true`, the system will automatically capture the document once it is properly detected and aligned. When set to `false`, the user must manually trigger the capture instead. | true |
|
|
117
|
+
| **<sup>New</sup>** mode | FULL | Captures front of document, front of document with flash, and back of document automatically. This is the default mode for complete document capture. | ✅ |
|
|
118
|
+
| | FRONT_ONLY | Captures only the front of document. | ❌ |
|
|
119
|
+
| | FRONT_BACK | Captures both front and back of document automatically without flash. | ❌ |
|
|
120
|
+
| | FRONT_WITH_FLASH | Captures the front of document with flash enabled | ❌ |
|
|
145
121
|
|
|
146
122
|
## Usage
|
|
147
123
|
|
|
148
124
|
```
|
|
149
|
-
import { captureDocument } from "react-native-okaycam"
|
|
150
|
-
|
|
151
|
-
captureDocument(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
size: 20
|
|
163
|
-
},
|
|
164
|
-
frame: {
|
|
165
|
-
size: {
|
|
166
|
-
width: 1000,
|
|
167
|
-
height: 300,
|
|
168
|
-
},
|
|
169
|
-
color: "#4287f5",
|
|
170
|
-
content: require('./images/content.svg')
|
|
171
|
-
},
|
|
172
|
-
showOverlay: true,
|
|
173
|
-
timer: {
|
|
174
|
-
backgroundColor: "#4287f5",
|
|
175
|
-
textColor: "#ffffff"
|
|
176
|
-
},
|
|
177
|
-
torchBtnEnabled: true,
|
|
178
|
-
confirmBtnConfig: {
|
|
179
|
-
backgroundColor: "#4287f5",
|
|
180
|
-
contentColor: "#000000"
|
|
181
|
-
},
|
|
182
|
-
retakeBtnConfig: {
|
|
183
|
-
backgroundColor: "#4287f5",
|
|
184
|
-
contentColor: "#000000"
|
|
185
|
-
},
|
|
186
|
-
captureBtnColor: "#4287f5",
|
|
187
|
-
firstPhotoConfig: {
|
|
188
|
-
delay: 0,
|
|
189
|
-
onFlash: false,
|
|
190
|
-
outputPath: null
|
|
191
|
-
},
|
|
192
|
-
secondPhotoConfig: {
|
|
193
|
-
delay: 5,
|
|
194
|
-
onFlash: true,
|
|
195
|
-
outputPath: null
|
|
196
|
-
},
|
|
197
|
-
crop: true,
|
|
198
|
-
width: 2000,
|
|
199
|
-
imageQuality: 1.0,
|
|
200
|
-
preview: {
|
|
201
|
-
title: {text: 'testing', color: '#000000', size: 25},
|
|
202
|
-
refImage: require('./images/ref.png'),
|
|
203
|
-
instruction1: {text: 'instr1', color: '#000000', size: 14},
|
|
204
|
-
instruction2: {text: 'instr2', color: '#000000', size: 14},
|
|
205
|
-
instruction3: {text: 'instr3', color: '#000000', size: 14},
|
|
206
|
-
backgroundColor: '#374fff',
|
|
207
|
-
},
|
|
208
|
-
instruction: {
|
|
209
|
-
title: {text: 'instr1', color: '#ffffff', size: 14},
|
|
210
|
-
refImage1: {
|
|
211
|
-
title: {text: 'ref1', color: '#ffffff', size: 14},
|
|
212
|
-
img: require('./images/ref.png'),
|
|
213
|
-
},
|
|
214
|
-
refImage2: {
|
|
215
|
-
title: {text: 'ref2', color: '#ffffff', size: 14},
|
|
216
|
-
img: require('./images/ref.png'),
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
showPreviewInstruction: false,
|
|
220
|
-
autoCapture: true
|
|
221
|
-
}
|
|
222
|
-
)
|
|
223
|
-
.then(result => {
|
|
224
|
-
console.log(result)
|
|
225
|
-
})
|
|
226
|
-
.catch(error => {
|
|
227
|
-
console.log(error)
|
|
228
|
-
})
|
|
125
|
+
import { captureDocument, DocumentCaptureMode } from "react-native-okaycam"
|
|
126
|
+
|
|
127
|
+
captureDocument(license, false, {
|
|
128
|
+
width: 2000,
|
|
129
|
+
imageQuality: 0.8,
|
|
130
|
+
mode: DocumentCaptureMode.FULL,
|
|
131
|
+
})
|
|
132
|
+
.then(result => {
|
|
133
|
+
console.log(JSON.stringify(result));
|
|
134
|
+
})
|
|
135
|
+
.catch(error => {
|
|
136
|
+
console.log(JSON.stringify(error));
|
|
137
|
+
});
|
|
229
138
|
```
|
|
230
139
|
|
|
231
140
|
### Result
|
|
232
141
|
|
|
233
|
-
| Result | Description
|
|
234
|
-
| ------------------ |
|
|
235
|
-
| fullDocumentImage | Result of
|
|
236
|
-
| fullDocumentImage2 | Result of
|
|
142
|
+
| Result | Description |
|
|
143
|
+
| ------------------ | ------------------------------ |
|
|
144
|
+
| fullDocumentImage | Result of first photo |
|
|
145
|
+
| fullDocumentImage2 | Result of first photo cropped |
|
|
146
|
+
| fullDocumentImage3 | Result of second photo |
|
|
147
|
+
| fullDocumentImage4 | Result of second photo cropped |
|
|
237
148
|
|
|
238
149
|
## OkayCam Selfie
|
|
239
150
|
|
package/android/build.gradle
CHANGED
|
@@ -44,7 +44,7 @@ repositories {
|
|
|
44
44
|
|
|
45
45
|
dependencies {
|
|
46
46
|
compileOnly "com.facebook.react:react-android"
|
|
47
|
-
implementation('com.innov8tif.okaycam:OkayCam:3.
|
|
47
|
+
implementation('com.innov8tif.okaycam:OkayCam:3.1.3@aar') {
|
|
48
48
|
transitive = true
|
|
49
49
|
exclude group: "junit", module: "junit"
|
|
50
50
|
exclude group: "org.hamcrest", module: "hamcrest-core"
|
|
@@ -7,6 +7,7 @@ import android.graphics.BitmapFactory;
|
|
|
7
7
|
import android.graphics.Canvas;
|
|
8
8
|
import android.graphics.Color;
|
|
9
9
|
import android.util.Size;
|
|
10
|
+
import android.util.Log;
|
|
10
11
|
|
|
11
12
|
import com.caverock.androidsvg.PreserveAspectRatio;
|
|
12
13
|
import com.caverock.androidsvg.RenderOptions;
|
|
@@ -19,6 +20,7 @@ import com.facebook.react.bridge.ReactMethod;
|
|
|
19
20
|
import com.facebook.react.bridge.ReadableMap;
|
|
20
21
|
|
|
21
22
|
import com.innov8tif.okaycam.cam.OkayCamAutoDoc;
|
|
23
|
+
import com.innov8tif.okaycam.cam.OkayCamAutoSelfie;
|
|
22
24
|
import com.innov8tif.okaycam.config.CameraFacing;
|
|
23
25
|
import com.innov8tif.okaycam.config.OkayCamBtnConfig;
|
|
24
26
|
import com.innov8tif.okaycam.config.OkayCamCaptureConfig;
|
|
@@ -26,9 +28,9 @@ import com.innov8tif.okaycam.config.OkayCamAutoCaptureConfig;
|
|
|
26
28
|
import com.innov8tif.okaycam.config.OkaySelfieConfig;
|
|
27
29
|
import com.innov8tif.okaycam.config.OkaySelfieLabelConfig;
|
|
28
30
|
import com.innov8tif.okaycam.config.OkaySelfieSwichBtnConfig;
|
|
29
|
-
import com.innov8tif.okaycam.selfie.OkayCamSelfie;
|
|
30
|
-
import com.innov8tif.okaycam.utils.BitmapUtils;
|
|
31
31
|
import com.innov8tif.okaycam.config.OkayCamAutoCaptureMode;
|
|
32
|
+
import com.innov8tif.okaycam.config.OkayCamAutoSelfieConfig;
|
|
33
|
+
import com.innov8tif.okaycam.utils.BitmapUtils;
|
|
32
34
|
|
|
33
35
|
import org.json.JSONException;
|
|
34
36
|
import org.json.JSONObject;
|
|
@@ -42,11 +44,8 @@ import java.net.URL;
|
|
|
42
44
|
|
|
43
45
|
public class RNOkayCamModule extends ReactContextBaseJavaModule {
|
|
44
46
|
|
|
45
|
-
private final ReactApplicationContext reactContext;
|
|
46
|
-
|
|
47
47
|
public RNOkayCamModule(ReactApplicationContext reactContext) {
|
|
48
48
|
super(reactContext);
|
|
49
|
-
this.reactContext = reactContext;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
@Override
|
|
@@ -62,12 +61,24 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
|
|
|
62
61
|
ReadableMap userConfig = configs.getMap("config");
|
|
63
62
|
OkayCamAutoCaptureConfig config = OkayCamAutoCaptureConfig.init();
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
Log.d("OkayCam", "userConfig: " + userConfig.toString());
|
|
65
|
+
|
|
66
|
+
if (userConfig.hasKey("width") && !userConfig.isNull("width")) {
|
|
67
|
+
int width = userConfig.getInt("width");
|
|
68
|
+
if (width != -1) {
|
|
69
|
+
config.setWidth(width);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (userConfig.hasKey("imageQuality") && !userConfig.isNull("imageQuality")) {
|
|
74
|
+
double quality = userConfig.getDouble("imageQuality");
|
|
75
|
+
if (quality > 0.0) {
|
|
76
|
+
config.setImageQuality((float) quality);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
68
79
|
|
|
69
|
-
if (userConfig.
|
|
70
|
-
config.
|
|
80
|
+
if (userConfig.hasKey("autoCapture") && !userConfig.isNull("autoCapture")) {
|
|
81
|
+
config.setAutoCapture(userConfig.getBoolean("autoCapture"));
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
config.setMode(parseMode(userConfig.getString("mode")));
|
|
@@ -76,18 +87,18 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
|
|
|
76
87
|
if (success) {
|
|
77
88
|
JSONObject results = new JSONObject();
|
|
78
89
|
try {
|
|
79
|
-
results.put("fullDocumentImage", convertImgToBase64(base64, images.get(0)));
|
|
90
|
+
results.put("fullDocumentImage", base64 ? convertImgToBase64(base64, images.get(0)) : images.get(0));
|
|
80
91
|
|
|
81
92
|
if (images.size() > 1) {
|
|
82
|
-
results.put("fullDocumentImage2", convertImgToBase64(base64, images.get(1)));
|
|
93
|
+
results.put("fullDocumentImage2", base64 ? convertImgToBase64(base64, images.get(1)) : images.get(1));
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
if (images.size() > 2) {
|
|
86
|
-
results.put("fullDocumentImage3", convertImgToBase64(base64, images.get(2)));
|
|
97
|
+
results.put("fullDocumentImage3", base64 ? convertImgToBase64(base64, images.get(2)) : images.get(2));
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
if (images.size() > 3) {
|
|
90
|
-
results.put("fullDocumentImage4", convertImgToBase64(base64, images.get(3)));
|
|
101
|
+
results.put("fullDocumentImage4", base64 ? convertImgToBase64(base64, images.get(3)) : images.get(3));
|
|
91
102
|
}
|
|
92
103
|
|
|
93
104
|
promise.resolve(results.toString());
|
|
@@ -108,55 +119,13 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
|
|
|
108
119
|
|
|
109
120
|
Boolean base64 = configs.getBoolean("base64");
|
|
110
121
|
|
|
111
|
-
|
|
112
|
-
ReadableMap topLabel = userConfig.getMap("topLabel");
|
|
113
|
-
ReadableMap switchBtnConfig = userConfig.getMap("switchBtnConfig");
|
|
114
|
-
ReadableMap confirmBtnConfig = userConfig.getMap("confirmBtnConfig");
|
|
115
|
-
ReadableMap retakeBtnConfig = userConfig.getMap("retakeBtnConfig");
|
|
116
|
-
|
|
117
|
-
OkaySelfieConfig okaySelfieConfig = OkaySelfieConfig.init(this.getCurrentActivity());
|
|
118
|
-
|
|
119
|
-
okaySelfieConfig.setTopLabel(new OkaySelfieLabelConfig(
|
|
120
|
-
topLabel.getString("text"),
|
|
121
|
-
Color.parseColor(topLabel.getString("color")),
|
|
122
|
-
topLabel.getInt("size")
|
|
123
|
-
));
|
|
124
|
-
okaySelfieConfig.setBottomFrameColor(Color.parseColor(userConfig.getString("bottomFrameColor")));
|
|
125
|
-
|
|
126
|
-
okaySelfieConfig.setCaptureBtnColor(Color.parseColor(userConfig.getString("captureBtnColor")));
|
|
127
|
-
|
|
128
|
-
okaySelfieConfig.setSwitchBtnConfig(new OkaySelfieSwichBtnConfig(
|
|
129
|
-
Color.parseColor(switchBtnConfig.getString("color")),
|
|
130
|
-
switchBtnConfig.getBoolean("show")
|
|
131
|
-
));
|
|
132
|
-
|
|
133
|
-
okaySelfieConfig.setConfirmBtnConfig(new OkayCamBtnConfig(
|
|
134
|
-
Color.parseColor(confirmBtnConfig.getString("backgroundColor")),
|
|
135
|
-
Color.parseColor(confirmBtnConfig.getString("contentColor"))
|
|
136
|
-
));
|
|
137
|
-
|
|
138
|
-
okaySelfieConfig.setRetakeBtnConfig(new OkayCamBtnConfig(
|
|
139
|
-
Color.parseColor(retakeBtnConfig.getString("backgroundColor")),
|
|
140
|
-
Color.parseColor(retakeBtnConfig.getString("contentColor"))
|
|
141
|
-
));
|
|
142
|
-
|
|
143
|
-
if (userConfig.getString("defaultCameraFacing").equals("front")) {
|
|
144
|
-
okaySelfieConfig.setDefaultCameraFacing(CameraFacing.FRONT);
|
|
145
|
-
} else if (userConfig.getString("defaultCameraFacing").equals("back")) {
|
|
146
|
-
okaySelfieConfig.setDefaultCameraFacing(CameraFacing.BACK);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (userConfig.getInt("width") != -1) {
|
|
150
|
-
okaySelfieConfig.setWidth(userConfig.getInt("width"));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
okaySelfieConfig.setImageQuality((float) userConfig.getDouble("imageQuality"));
|
|
122
|
+
OkayCamAutoSelfieConfig okaySelfieConfig = OkayCamAutoSelfieConfig.init();
|
|
154
123
|
|
|
155
|
-
|
|
124
|
+
OkayCamAutoSelfie.start(this.getCurrentActivity(), LICENSE_KEY, okaySelfieConfig, (success, image, exception) -> {
|
|
156
125
|
if (success) {
|
|
157
126
|
JSONObject results = new JSONObject();
|
|
158
127
|
try {
|
|
159
|
-
results.put("selfieImage", convertImgToBase64(base64, image));
|
|
128
|
+
results.put("selfieImage", base64 ? convertImgToBase64(base64, image) : image);
|
|
160
129
|
promise.resolve(results.toString());
|
|
161
130
|
} catch (JSONException e) {
|
|
162
131
|
e.printStackTrace();
|
package/index.ts
CHANGED
|
@@ -9,51 +9,28 @@ export enum DocumentCaptureMode {
|
|
|
9
9
|
FRONT_WITH_FLASH = "FRONT_WITH_FLASH",
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
text: string;
|
|
14
|
-
color: string;
|
|
15
|
-
size: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface OkayCamBtnConfig {
|
|
19
|
-
backgroundColor: string;
|
|
20
|
-
contentColor: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface SwitchBtnConfig {
|
|
24
|
-
color: string;
|
|
25
|
-
show: Boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type cameraFacingType = "front" | "back";
|
|
29
|
-
|
|
30
|
-
// Set default values
|
|
31
|
-
const defaultColor = "#ffffff";
|
|
32
|
-
const defaultColor2 = "#ffa500";
|
|
33
|
-
const imageResizedWidth = -1;
|
|
34
|
-
|
|
35
|
-
const labelConfig: LabelConfig = {
|
|
36
|
-
text: "",
|
|
37
|
-
color: defaultColor,
|
|
38
|
-
size: 20,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const okayCamBtnConfig: OkayCamBtnConfig = {
|
|
42
|
-
backgroundColor: defaultColor2,
|
|
43
|
-
contentColor: defaultColor,
|
|
44
|
-
};
|
|
12
|
+
const imageResizedWidth = 1080;
|
|
45
13
|
|
|
46
14
|
// cal native capture document
|
|
47
15
|
export const captureDocument = (
|
|
48
16
|
license: string,
|
|
49
|
-
base64:
|
|
50
|
-
{
|
|
17
|
+
base64: boolean,
|
|
18
|
+
config: {
|
|
19
|
+
width?: number;
|
|
20
|
+
imageQuality?: number;
|
|
21
|
+
mode?: string;
|
|
22
|
+
autoCapture?: boolean;
|
|
23
|
+
} = {},
|
|
24
|
+
) => {
|
|
25
|
+
const {
|
|
51
26
|
width = imageResizedWidth,
|
|
52
27
|
imageQuality = 1.0,
|
|
53
28
|
mode = DocumentCaptureMode.FULL,
|
|
54
|
-
|
|
55
|
-
|
|
29
|
+
autoCapture = true,
|
|
30
|
+
} = config;
|
|
56
31
|
return new Promise(function (resolve, reject) {
|
|
32
|
+
console.log(`autoCapture: ${autoCapture}`);
|
|
33
|
+
console.log(`mode: ${mode}`);
|
|
57
34
|
RNOkayCam.captureDocument({
|
|
58
35
|
license: license,
|
|
59
36
|
base64: base64,
|
|
@@ -61,60 +38,41 @@ export const captureDocument = (
|
|
|
61
38
|
width: width,
|
|
62
39
|
imageQuality: imageQuality,
|
|
63
40
|
mode: mode,
|
|
41
|
+
autoCapture: autoCapture,
|
|
64
42
|
},
|
|
65
43
|
})
|
|
66
|
-
.then((result) => {
|
|
44
|
+
.then((result: string) => {
|
|
67
45
|
resolve(JSON.parse(result));
|
|
68
46
|
})
|
|
69
|
-
.catch((error) => {
|
|
47
|
+
.catch((error: any) => {
|
|
70
48
|
reject(error);
|
|
71
49
|
});
|
|
72
50
|
});
|
|
73
51
|
};
|
|
74
52
|
|
|
75
|
-
const defaultSwitchBtnConfig: SwitchBtnConfig = {
|
|
76
|
-
show: true,
|
|
77
|
-
color: defaultColor,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const cameraFacing: cameraFacingType = "front";
|
|
81
|
-
|
|
82
53
|
// call native capture selfie
|
|
83
54
|
export const captureSelfie = (
|
|
84
55
|
license: string,
|
|
85
|
-
base64:
|
|
86
|
-
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
switchBtnConfig = defaultSwitchBtnConfig,
|
|
91
|
-
confirmBtnConfig = okayCamBtnConfig,
|
|
92
|
-
retakeBtnConfig = okayCamBtnConfig,
|
|
93
|
-
defaultCameraFacing = cameraFacing,
|
|
94
|
-
width = imageResizedWidth,
|
|
95
|
-
imageQuality = 1.0,
|
|
96
|
-
},
|
|
56
|
+
base64: boolean,
|
|
57
|
+
config: {
|
|
58
|
+
width?: number;
|
|
59
|
+
height?: number;
|
|
60
|
+
} = {},
|
|
97
61
|
) => {
|
|
62
|
+
const { width = imageResizedWidth, height = 1920 } = config;
|
|
98
63
|
return new Promise(function (resolve, reject) {
|
|
99
64
|
RNOkayCam.captureSelfie({
|
|
100
65
|
license: license,
|
|
101
66
|
base64: base64,
|
|
102
67
|
config: {
|
|
103
|
-
topLabel: topLabel,
|
|
104
|
-
bottomFrameColor: bottomFrameColor,
|
|
105
|
-
captureBtnColor: captureBtnColor,
|
|
106
|
-
switchBtnConfig: switchBtnConfig,
|
|
107
|
-
confirmBtnConfig: confirmBtnConfig,
|
|
108
|
-
retakeBtnConfig: retakeBtnConfig,
|
|
109
|
-
defaultCameraFacing: defaultCameraFacing,
|
|
110
68
|
width: width,
|
|
111
|
-
|
|
69
|
+
height: height,
|
|
112
70
|
},
|
|
113
71
|
})
|
|
114
|
-
.then((result) => {
|
|
72
|
+
.then((result: string) => {
|
|
115
73
|
resolve(JSON.parse(result));
|
|
116
74
|
})
|
|
117
|
-
.catch((error) => {
|
|
75
|
+
.catch((error: any) => {
|
|
118
76
|
reject(error);
|
|
119
77
|
});
|
|
120
78
|
});
|
package/ios/RNOkayCam.swift
CHANGED
|
@@ -15,75 +15,89 @@ class RNOkayCam: NSObject {
|
|
|
15
15
|
var promiseResolve: RCTPromiseResolveBlock?
|
|
16
16
|
var promiseReject: RCTPromiseRejectBlock?
|
|
17
17
|
|
|
18
|
-
@objc func captureDocument(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
@objc func captureDocument(
|
|
19
|
+
_ configs: NSDictionary,
|
|
20
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
21
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
22
|
+
) {
|
|
23
|
+
|
|
24
|
+
guard let license = configs["license"] as? String else {
|
|
25
|
+
reject("invalid_license", "Missing license", nil)
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let base64 = configs["base64"] as? Bool ?? false
|
|
30
|
+
let rnOkayCamConfig = configs["config"] as? NSDictionary ?? [:]
|
|
31
|
+
|
|
32
|
+
let width = rnOkayCamConfig["width"] as? Int
|
|
33
|
+
let imageQuality = rnOkayCamConfig["imageQuality"] as? CGFloat
|
|
34
|
+
let mode = rnOkayCamConfig["mode"] as? String
|
|
35
|
+
let autoCapture = rnOkayCamConfig["autoCapture"] as? Bool
|
|
36
|
+
|
|
28
37
|
DispatchQueue.main.async {
|
|
29
38
|
guard let rootViewController = UIApplication.shared.windows.first?.rootViewController else {
|
|
30
39
|
reject("no_root_view_controller", "Root view controller not found", nil)
|
|
31
40
|
return
|
|
32
41
|
}
|
|
33
|
-
|
|
42
|
+
|
|
34
43
|
let config = OkayCamAutoCaptureConfig(viewController: rootViewController)
|
|
35
|
-
|
|
36
|
-
// if (width != -1) {
|
|
37
|
-
// config.width = width
|
|
38
|
-
// }
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
// width
|
|
46
|
+
if let width = width, width != -1 {
|
|
47
|
+
config.width = width
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// image quality
|
|
51
|
+
if let imageQuality = imageQuality, imageQuality > 0.0 {
|
|
41
52
|
config.imageQuality = imageQuality
|
|
42
53
|
}
|
|
43
54
|
|
|
55
|
+
// ✅ FIX: allow false
|
|
56
|
+
if let autoCapture = autoCapture {
|
|
57
|
+
config.autoCapture = autoCapture
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
config.mode = self.parseMode(mode)
|
|
45
61
|
|
|
46
|
-
|
|
47
|
-
OkayCamDocAutoCapture.start(
|
|
62
|
+
OkayCamAutoDoc.start(
|
|
48
63
|
okayCamConfig: config,
|
|
49
|
-
license: license
|
|
50
|
-
|
|
51
|
-
// handle error
|
|
52
|
-
do {
|
|
53
|
-
if let failed = error {
|
|
54
|
-
print(failed)
|
|
55
|
-
self.handleError(failed, rejecter: reject)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// handle success
|
|
59
|
-
if let urls = filePaths {
|
|
60
|
-
let okayCamObject:NSMutableDictionary = NSMutableDictionary()
|
|
61
|
-
|
|
62
|
-
okayCamObject.setValue(self.convertImgToBase64(base64: base64, image: urls[0]), forKey: "fullDocumentImage")
|
|
63
|
-
|
|
64
|
-
if (filePaths!.count > 1) {
|
|
65
|
-
okayCamObject.setValue(self.convertImgToBase64(base64: base64, image: urls[1]), forKey: "fullDocumentImage2")
|
|
66
|
-
}
|
|
64
|
+
license: license
|
|
65
|
+
) { filePaths, error in
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
if let error = error {
|
|
68
|
+
self.handleError(error, rejecter: reject)
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
guard let urls = filePaths else {
|
|
73
|
+
reject("no_result", "No images returned", nil)
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
do {
|
|
78
|
+
let result: NSMutableDictionary = [:]
|
|
79
|
+
|
|
80
|
+
result["fullDocumentImage"] = self.convertImgToBase64(base64: base64, image: urls[0])
|
|
81
|
+
|
|
82
|
+
if urls.count > 1 {
|
|
83
|
+
result["fullDocumentImage2"] = self.convertImgToBase64(base64: base64, image: urls[1])
|
|
81
84
|
}
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
if urls.count > 2 {
|
|
86
|
+
result["fullDocumentImage3"] = self.convertImgToBase64(base64: base64, image: urls[2])
|
|
84
87
|
}
|
|
88
|
+
if urls.count > 3 {
|
|
89
|
+
result["fullDocumentImage4"] = self.convertImgToBase64(base64: base64, image: urls[3])
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let jsonData = try JSONSerialization.data(withJSONObject: result)
|
|
93
|
+
let jsonString = String(data: jsonData, encoding: .utf8)!
|
|
94
|
+
|
|
95
|
+
resolve(jsonString)
|
|
96
|
+
|
|
97
|
+
} catch {
|
|
98
|
+
reject("json_error", error.localizedDescription, error)
|
|
85
99
|
}
|
|
86
|
-
|
|
100
|
+
}
|
|
87
101
|
}
|
|
88
102
|
}
|
|
89
103
|
|
|
@@ -91,16 +105,6 @@ class RNOkayCam: NSObject {
|
|
|
91
105
|
|
|
92
106
|
let license = configs.object(forKey: "license")! as! String
|
|
93
107
|
let base64 = configs.object(forKey: "base64") as! Bool
|
|
94
|
-
let rnOkayCamConfig = configs.object(forKey: "config") as! NSDictionary
|
|
95
|
-
let topLabel = rnOkayCamConfig.object(forKey: "topLabel") as! NSDictionary
|
|
96
|
-
let bottomFrameColor = rnOkayCamConfig.object(forKey: "bottomFrameColor") as! String
|
|
97
|
-
let captureBtnColor = rnOkayCamConfig.object(forKey: "captureBtnColor") as! String
|
|
98
|
-
let switchBtnConfig = rnOkayCamConfig.object(forKey: "switchBtnConfig") as! NSDictionary
|
|
99
|
-
let confirmBtnConfig = rnOkayCamConfig.object(forKey: "confirmBtnConfig") as! NSDictionary
|
|
100
|
-
let retakeBtnConfig = rnOkayCamConfig.object(forKey: "retakeBtnConfig") as! NSDictionary
|
|
101
|
-
let defaultCameraFacing = rnOkayCamConfig.object(forKey: "defaultCameraFacing") as! String
|
|
102
|
-
let width = rnOkayCamConfig.object(forKey: "width") as! Int
|
|
103
|
-
let imageQuality = rnOkayCamConfig.object(forKey: "imageQuality") as! CGFloat
|
|
104
108
|
|
|
105
109
|
DispatchQueue.main.async {
|
|
106
110
|
guard let rootViewController = UIApplication.shared.windows.first?.rootViewController else {
|
|
@@ -108,51 +112,10 @@ class RNOkayCam: NSObject {
|
|
|
108
112
|
return
|
|
109
113
|
}
|
|
110
114
|
|
|
111
|
-
let okaySelfieConfig =
|
|
112
|
-
|
|
113
|
-
// top label
|
|
114
|
-
okaySelfieConfig.topLabel.text = topLabel.object(forKey: "text") as! String
|
|
115
|
-
okaySelfieConfig.topLabel.color = self.hexStringToUIColor(hex: topLabel.object(forKey: "color") as! String)
|
|
116
|
-
okaySelfieConfig.topLabel.size = CGFloat(topLabel.object(forKey: "size") as! Int)
|
|
117
|
-
|
|
118
|
-
// bottom frame color
|
|
119
|
-
okaySelfieConfig.bottomFrameColor = self.hexStringToUIColor(hex: bottomFrameColor)
|
|
120
|
-
|
|
121
|
-
// capture button color
|
|
122
|
-
okaySelfieConfig.captureBtnColor = self.hexStringToUIColor(hex: captureBtnColor)
|
|
123
|
-
|
|
124
|
-
// capture configurations
|
|
125
|
-
okaySelfieConfig.captureBtnColor = self.hexStringToUIColor(hex: captureBtnColor)
|
|
126
|
-
|
|
127
|
-
// confirm button config
|
|
128
|
-
okaySelfieConfig.confirmBtnConfig.backgroundColor = self.hexStringToUIColor(hex: confirmBtnConfig.object(forKey: "backgroundColor") as! String)
|
|
129
|
-
okaySelfieConfig.confirmBtnConfig.contentColor = self.hexStringToUIColor(hex: confirmBtnConfig.object(forKey: "contentColor") as! String)
|
|
130
|
-
|
|
131
|
-
// retake button config
|
|
132
|
-
okaySelfieConfig.retakeBtnConfig.backgroundColor = self.hexStringToUIColor(hex: retakeBtnConfig.object(forKey: "backgroundColor") as! String)
|
|
133
|
-
okaySelfieConfig.retakeBtnConfig.contentColor = self.hexStringToUIColor(hex: retakeBtnConfig.object(forKey: "contentColor") as! String)
|
|
134
|
-
|
|
135
|
-
// switch button config
|
|
136
|
-
okaySelfieConfig.switchBtnConfig.color = self.hexStringToUIColor(hex: switchBtnConfig.object(forKey: "color") as! String)
|
|
137
|
-
// okaySelfieConfig.switchBtnConfig.show = switchBtnConfig.object(forKey: "show") as! Bool
|
|
138
|
-
okaySelfieConfig.switchBtnConfig.show = true
|
|
139
|
-
// camera facing
|
|
140
|
-
if (defaultCameraFacing == "front") {
|
|
141
|
-
okaySelfieConfig.defaultCameraFacing = OkayCam.CameraDevice.front
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
okaySelfieConfig.defaultCameraFacing = OkayCam.CameraDevice.back
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// resize
|
|
148
|
-
if (width != -1) {
|
|
149
|
-
okaySelfieConfig.width = width
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
okaySelfieConfig.imageQuality = imageQuality
|
|
115
|
+
let okaySelfieConfig = OkayCamAutoSelfieConfig(viewController: rootViewController)
|
|
153
116
|
|
|
154
117
|
// start the SDK
|
|
155
|
-
|
|
118
|
+
OkayCamAutoSelfie.start(
|
|
156
119
|
okaySelfieConfig: okaySelfieConfig,
|
|
157
120
|
license: license,
|
|
158
121
|
{ filePath, error in
|
package/package.json
CHANGED