react-native-okaycam 3.0.2 → 3.0.4
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/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/build.gradle +2 -2
- package/android/consumer-rules.pro +84 -0
- package/android/src/main/java/com/innov8tif/rnokaycam/RNOkayCamModule.java +26 -369
- package/index.ts +11 -173
- package/ios/RNOkayCam.swift +39 -175
- package/package.json +1 -1
- package/react-native-okaycam.podspec +2 -2
- package/setup_podfile.js +5 -5
|
Binary file
|
|
Binary file
|
package/android/build.gradle
CHANGED
|
@@ -43,8 +43,8 @@ repositories {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
dependencies {
|
|
46
|
-
|
|
47
|
-
implementation('com.innov8tif.okaycam:OkayCam:3.0.
|
|
46
|
+
compileOnly "com.facebook.react:react-android"
|
|
47
|
+
implementation('com.innov8tif.okaycam:OkayCam:3.0.9@aar') {
|
|
48
48
|
transitive = true
|
|
49
49
|
exclude group: "junit", module: "junit"
|
|
50
50
|
exclude group: "org.hamcrest", module: "hamcrest-core"
|
|
@@ -1,3 +1,70 @@
|
|
|
1
|
+
##---------------Begin: proguard configuration for Gson ----------
|
|
2
|
+
# Gson uses generic type information stored in a class file when working with
|
|
3
|
+
#fields. Proguard removes such information by default, so configure it to keep
|
|
4
|
+
#all of it.
|
|
5
|
+
-keepattributes Signature
|
|
6
|
+
|
|
7
|
+
# For using GSON @Expose annotation
|
|
8
|
+
-keepattributes *Annotation*
|
|
9
|
+
|
|
10
|
+
# Gson specific classes
|
|
11
|
+
-keep class sun.misc.Unsafe { *; }
|
|
12
|
+
#-keep class com.google.gson.stream.** { *; }
|
|
13
|
+
|
|
14
|
+
# Application classes that will be serialized/deserialized over Gson
|
|
15
|
+
-keep class com.xendity.util.models.** { *; }
|
|
16
|
+
-keep class com.xendity.util.R$drawable { *; }
|
|
17
|
+
-keep class com.xendity.util.R$raw { *; }
|
|
18
|
+
-keep class com.xendity.util.R$style { *; }
|
|
19
|
+
-keep class com.xendity.util.R { *; }
|
|
20
|
+
|
|
21
|
+
##---------------End: proguard configuration for Gson ----------
|
|
22
|
+
|
|
23
|
+
# region XScannerConfig
|
|
24
|
+
-keep class com.xendity.util.models.XScannerConfig {
|
|
25
|
+
*;
|
|
26
|
+
}
|
|
27
|
+
-keepclassmembers class com.xendity.util.models.XScannerConfig {
|
|
28
|
+
*;
|
|
29
|
+
}
|
|
30
|
+
-keepnames class com.xendity.util.models.XScannerConfig {
|
|
31
|
+
*;
|
|
32
|
+
}
|
|
33
|
+
-keepclassmembernames class com.xendity.util.models.XScannerConfig {
|
|
34
|
+
*;
|
|
35
|
+
}
|
|
36
|
+
# endregion
|
|
37
|
+
|
|
38
|
+
# region XenUtil
|
|
39
|
+
-keep class com.xendity.util.XenUtil {
|
|
40
|
+
public static *;
|
|
41
|
+
}
|
|
42
|
+
-keepclassmembers class com.xendity.util.XenUtil {
|
|
43
|
+
public static *;
|
|
44
|
+
}
|
|
45
|
+
-keepnames class com.xendity.util.XenUtil {
|
|
46
|
+
public static *;
|
|
47
|
+
}
|
|
48
|
+
-keepclassmembernames class com.xendity.util.XenUtil {
|
|
49
|
+
public static *;
|
|
50
|
+
}
|
|
51
|
+
# endregion
|
|
52
|
+
|
|
53
|
+
# region XenLoadingUtil
|
|
54
|
+
-keep class com.xendity.util.misc.XenLoadingUtil {
|
|
55
|
+
*;
|
|
56
|
+
}
|
|
57
|
+
-keepclassmembers class com.xendity.util.misc.XenLoadingUtil {
|
|
58
|
+
*;
|
|
59
|
+
}
|
|
60
|
+
-keepnames class com.xendity.util.misc.XenLoadingUtil {
|
|
61
|
+
*;
|
|
62
|
+
}
|
|
63
|
+
-keepclassmembernames class com.xendity.util.misc.XenLoadingUtil {
|
|
64
|
+
*;
|
|
65
|
+
}
|
|
66
|
+
# endregion
|
|
67
|
+
|
|
1
68
|
# This is a configuration file for ProGuard.
|
|
2
69
|
# http://proguard.sourceforge.net/index.html#manual/usage.html
|
|
3
70
|
#
|
|
@@ -118,6 +185,7 @@
|
|
|
118
185
|
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite { *; }
|
|
119
186
|
-keep class com.google.common.flogger.** { *; }
|
|
120
187
|
|
|
188
|
+
|
|
121
189
|
# These classes are duplicated between android.jar and org.apache.http.legacy.jar.
|
|
122
190
|
-dontnote org.apache.http.**
|
|
123
191
|
-dontnote android.net.http.**
|
|
@@ -130,3 +198,19 @@
|
|
|
130
198
|
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
|
|
131
199
|
-dontwarn com.google.errorprone.annotations.CheckReturnValue
|
|
132
200
|
-dontwarn com.google.errorprone.annotations.MustBeClosed
|
|
201
|
+
|
|
202
|
+
# Preserve MediaPipe task vision classes
|
|
203
|
+
-keep class com.google.mediapipe.tasks.** { *; }
|
|
204
|
+
|
|
205
|
+
# Preserve protocol buffer internals
|
|
206
|
+
-keep class com.google.protobuf.** { *; }
|
|
207
|
+
|
|
208
|
+
# Specifically preserve fields for generated proto messages
|
|
209
|
+
# MediaPipe needs these fields (like length_) for reflection
|
|
210
|
+
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite {
|
|
211
|
+
<fields>;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
# Ignore warnings
|
|
215
|
+
-dontwarn com.google.mediapipe.**
|
|
216
|
+
-dontwarn com.google.protobuf.**
|
|
@@ -18,23 +18,17 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
|
18
18
|
import com.facebook.react.bridge.ReactMethod;
|
|
19
19
|
import com.facebook.react.bridge.ReadableMap;
|
|
20
20
|
|
|
21
|
-
import com.innov8tif.okaycam.cam.
|
|
21
|
+
import com.innov8tif.okaycam.cam.OkayCamAutoDoc;
|
|
22
22
|
import com.innov8tif.okaycam.config.CameraFacing;
|
|
23
|
-
import com.innov8tif.okaycam.config.CaptureConfigPair;
|
|
24
23
|
import com.innov8tif.okaycam.config.OkayCamBtnConfig;
|
|
25
24
|
import com.innov8tif.okaycam.config.OkayCamCaptureConfig;
|
|
26
|
-
import com.innov8tif.okaycam.config.
|
|
27
|
-
import com.innov8tif.okaycam.config.OkayCamFrameConfig;
|
|
28
|
-
import com.innov8tif.okaycam.config.OkayCamInstruction;
|
|
29
|
-
import com.innov8tif.okaycam.config.OkayCamInstructionRefImg;
|
|
30
|
-
import com.innov8tif.okaycam.config.OkayCamLabelConfig;
|
|
31
|
-
import com.innov8tif.okaycam.config.OkayCamPreviewConfig;
|
|
32
|
-
import com.innov8tif.okaycam.config.OkayCamTimerConfig;
|
|
25
|
+
import com.innov8tif.okaycam.config.OkayCamAutoCaptureConfig;
|
|
33
26
|
import com.innov8tif.okaycam.config.OkaySelfieConfig;
|
|
34
27
|
import com.innov8tif.okaycam.config.OkaySelfieLabelConfig;
|
|
35
28
|
import com.innov8tif.okaycam.config.OkaySelfieSwichBtnConfig;
|
|
36
29
|
import com.innov8tif.okaycam.selfie.OkayCamSelfie;
|
|
37
30
|
import com.innov8tif.okaycam.utils.BitmapUtils;
|
|
31
|
+
import com.innov8tif.okaycam.config.OkayCamAutoCaptureMode;
|
|
38
32
|
|
|
39
33
|
import org.json.JSONException;
|
|
40
34
|
import org.json.JSONObject;
|
|
@@ -65,85 +59,20 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
|
|
|
65
59
|
String LICENSE_KEY = configs.getString("license");
|
|
66
60
|
|
|
67
61
|
Boolean base64 = configs.getBoolean("base64");
|
|
68
|
-
|
|
69
62
|
ReadableMap userConfig = configs.getMap("config");
|
|
70
|
-
|
|
71
|
-
ReadableMap bottomLabel = userConfig.getMap("bottomLabel");
|
|
72
|
-
ReadableMap frame = userConfig.getMap("frame");
|
|
73
|
-
ReadableMap timer = userConfig.getMap("timer");
|
|
74
|
-
ReadableMap confirmBtnConfig = userConfig.getMap("confirmBtnConfig");
|
|
75
|
-
ReadableMap retakeBtnConfig = userConfig.getMap("retakeBtnConfig");
|
|
76
|
-
ReadableMap captureConfigPair = userConfig.getMap("captureConfigPair");
|
|
77
|
-
ReadableMap firstPhoto = captureConfigPair.getMap("firstPhoto");
|
|
78
|
-
ReadableMap secondPhoto = captureConfigPair.getMap("secondPhoto");
|
|
79
|
-
ReadableMap preview = userConfig.getMap("preview");
|
|
80
|
-
ReadableMap instruction = userConfig.getMap("instruction");
|
|
63
|
+
OkayCamAutoCaptureConfig config = OkayCamAutoCaptureConfig.init();
|
|
81
64
|
|
|
82
|
-
|
|
65
|
+
// if (userConfig.getInt("width") != -1) {
|
|
66
|
+
// config.setWidth(userConfig.getInt("width"));
|
|
67
|
+
// }
|
|
83
68
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
okayCamConfig.setTorchBtnEnabled(userConfig.getBoolean("torchBtnEnabled"));
|
|
87
|
-
okayCamConfig.setCrop(userConfig.getBoolean("crop"));
|
|
88
|
-
|
|
89
|
-
if (userConfig.getInt("width") != -1) {
|
|
90
|
-
okayCamConfig.setWidth(userConfig.getInt("width"));
|
|
69
|
+
if (userConfig.getDouble("imageQuality") > 0.0) {
|
|
70
|
+
config.setImageQuality((float) userConfig.getDouble("imageQuality"));
|
|
91
71
|
}
|
|
92
72
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
okayCamConfig.setTopLabel(new OkayCamLabelConfig(
|
|
96
|
-
topLabel.getString("text"),
|
|
97
|
-
Color.parseColor(topLabel.getString("color")),
|
|
98
|
-
topLabel.getInt("size")
|
|
99
|
-
));
|
|
100
|
-
|
|
101
|
-
okayCamConfig.setBottomLabel(new OkayCamLabelConfig(
|
|
102
|
-
bottomLabel.getString("text"),
|
|
103
|
-
Color.parseColor(bottomLabel.getString("color")),
|
|
104
|
-
bottomLabel.getInt("size")
|
|
105
|
-
));
|
|
106
|
-
|
|
107
|
-
OkayCamFrameConfig frameConfig = getFrameConfig(frame);
|
|
108
|
-
okayCamConfig.setFrame(frameConfig);
|
|
109
|
-
|
|
110
|
-
okayCamConfig.setCaptureBtnColor(Color.parseColor(userConfig.getString("captureBtnColor")));
|
|
111
|
-
okayCamConfig.setTimer(new OkayCamTimerConfig(
|
|
112
|
-
Color.parseColor(timer.getString("backgroundColor")),
|
|
113
|
-
Color.parseColor(timer.getString("textColor"))
|
|
114
|
-
));
|
|
115
|
-
|
|
116
|
-
okayCamConfig.setConfirmBtnConfig(new OkayCamBtnConfig(
|
|
117
|
-
Color.parseColor(confirmBtnConfig.getString("backgroundColor")),
|
|
118
|
-
Color.parseColor(confirmBtnConfig.getString("contentColor"))
|
|
119
|
-
));
|
|
120
|
-
|
|
121
|
-
okayCamConfig.setRetakeBtnConfig(new OkayCamBtnConfig(
|
|
122
|
-
Color.parseColor(retakeBtnConfig.getString("backgroundColor")),
|
|
123
|
-
Color.parseColor(retakeBtnConfig.getString("contentColor"))
|
|
124
|
-
));
|
|
125
|
-
|
|
126
|
-
okayCamConfig.setCaptureConfig(new CaptureConfigPair(
|
|
127
|
-
firstPhoto != null ? new OkayCamCaptureConfig(
|
|
128
|
-
firstPhoto.getInt("delay"),
|
|
129
|
-
firstPhoto.getBoolean("onFlash"),
|
|
130
|
-
firstPhoto.getString("outputPath"),
|
|
131
|
-
firstPhoto.hasKey("onImageQuality") ? firstPhoto.getBoolean("onImageQuality") : false
|
|
132
|
-
) : null,
|
|
133
|
-
secondPhoto != null ? new OkayCamCaptureConfig(
|
|
134
|
-
secondPhoto.getInt("delay"),
|
|
135
|
-
secondPhoto.getBoolean("onFlash"),
|
|
136
|
-
secondPhoto.getString("outputPath"),
|
|
137
|
-
secondPhoto.hasKey("onImageQuality") ? secondPhoto.getBoolean("onImageQuality") : false
|
|
138
|
-
) : null
|
|
139
|
-
));
|
|
140
|
-
|
|
141
|
-
okayCamConfig.setPreview(getPreviewConfig(preview, frameConfig));
|
|
142
|
-
okayCamConfig.setInstruction(getInstructionConfig(instruction, frameConfig));
|
|
143
|
-
okayCamConfig.setAutoCapture(userConfig.getBoolean("autoCapture"));
|
|
144
|
-
|
|
145
|
-
OkayCamDoc.start(this.getCurrentActivity(), LICENSE_KEY, okayCamConfig, (success, images, exception) -> {
|
|
73
|
+
config.setMode(parseMode(userConfig.getString("mode")));
|
|
146
74
|
|
|
75
|
+
OkayCamAutoDoc.start(this.getCurrentActivity(), LICENSE_KEY, config, (success, images, exception) -> {
|
|
147
76
|
if (success) {
|
|
148
77
|
JSONObject results = new JSONObject();
|
|
149
78
|
try {
|
|
@@ -173,290 +102,6 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
|
|
|
173
102
|
});
|
|
174
103
|
}
|
|
175
104
|
|
|
176
|
-
private OkayCamInstruction getInstructionConfig(ReadableMap instruction, OkayCamFrameConfig frameConfig) {
|
|
177
|
-
if (instruction == null) return null;
|
|
178
|
-
OkayCamLabelConfig title = mapToLabelConfig(instruction.getMap("title"));
|
|
179
|
-
|
|
180
|
-
ReadableMap refMap1 = instruction.getMap("refImage1");
|
|
181
|
-
OkayCamInstructionRefImg ref1 = mapToRef(refMap1, frameConfig, "instr1");
|
|
182
|
-
|
|
183
|
-
ReadableMap refMap2 = instruction.getMap("refImage2");
|
|
184
|
-
OkayCamInstructionRefImg ref2 = mapToRef(refMap2, frameConfig, "instr2");
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return new OkayCamInstruction(
|
|
188
|
-
title,
|
|
189
|
-
ref1,
|
|
190
|
-
ref2
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private OkayCamInstructionRefImg mapToRef(ReadableMap refMap, OkayCamFrameConfig frameConfig, String fileName) {
|
|
195
|
-
if (refMap == null) return null;
|
|
196
|
-
OkayCamLabelConfig title = mapToLabelConfig(refMap.getMap("title"));
|
|
197
|
-
String img1 = getImageFromJs(refMap.getString("img"), frameConfig, fileName);
|
|
198
|
-
|
|
199
|
-
return new OkayCamInstructionRefImg(title, img1);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
private String getImageFromJs(String refImage, OkayCamFrameConfig frameConfig, String fileName) {
|
|
203
|
-
Size size = frameConfig.getSize();
|
|
204
|
-
int frameWidth = size.getWidth();
|
|
205
|
-
int frameHeight = size.getHeight();
|
|
206
|
-
|
|
207
|
-
Bitmap contentBmp = null;
|
|
208
|
-
try {
|
|
209
|
-
if (refImage != null) {
|
|
210
|
-
// In debug, the image is returned as URL
|
|
211
|
-
if (BuildConfig.DEBUG) {
|
|
212
|
-
InputStream inputStream = new URL(refImage).openStream();
|
|
213
|
-
|
|
214
|
-
if (refImage.contains("svg")) {
|
|
215
|
-
|
|
216
|
-
SVG svg = SVG.getFromInputStream(inputStream);
|
|
217
|
-
|
|
218
|
-
svg.setDocumentWidth(frameWidth);
|
|
219
|
-
svg.setDocumentHeight(frameHeight);
|
|
220
|
-
|
|
221
|
-
if (svg.getDocumentWidth() != -1) {
|
|
222
|
-
contentBmp = Bitmap.createBitmap((int) Math.ceil(svg.getDocumentWidth()),
|
|
223
|
-
(int) Math.ceil(svg.getDocumentHeight()),
|
|
224
|
-
Bitmap.Config.ARGB_8888);
|
|
225
|
-
|
|
226
|
-
Canvas bmcanvas = new Canvas(contentBmp);
|
|
227
|
-
|
|
228
|
-
// Render our document onto our canvas
|
|
229
|
-
svg.renderToCanvas(bmcanvas, new RenderOptions().preserveAspectRatio(PreserveAspectRatio.FULLSCREEN));
|
|
230
|
-
}
|
|
231
|
-
} else {
|
|
232
|
-
contentBmp = BitmapFactory.decodeStream(inputStream);
|
|
233
|
-
}
|
|
234
|
-
} else {
|
|
235
|
-
// In release, the image is returned as raw (svg) or drawable (png, jpeg and etc)
|
|
236
|
-
int resourceId = this.getCurrentActivity().getResources().getIdentifier(refImage, "raw", this.getCurrentActivity().getPackageName());
|
|
237
|
-
|
|
238
|
-
if (resourceId != 0) {
|
|
239
|
-
SVG svg = SVG.getFromResource(getReactApplicationContext(), resourceId);
|
|
240
|
-
|
|
241
|
-
svg.setDocumentWidth(frameWidth);
|
|
242
|
-
svg.setDocumentHeight(frameHeight);
|
|
243
|
-
|
|
244
|
-
if (svg.getDocumentWidth() != -1) {
|
|
245
|
-
contentBmp = Bitmap.createBitmap((int) Math.ceil(svg.getDocumentWidth()),
|
|
246
|
-
(int) Math.ceil(svg.getDocumentHeight()),
|
|
247
|
-
Bitmap.Config.ARGB_8888);
|
|
248
|
-
|
|
249
|
-
Canvas bmcanvas = new Canvas(contentBmp);
|
|
250
|
-
|
|
251
|
-
// Render our document onto our canvas
|
|
252
|
-
svg.renderToCanvas(bmcanvas, new RenderOptions().preserveAspectRatio(PreserveAspectRatio.FULLSCREEN));
|
|
253
|
-
}
|
|
254
|
-
} else {
|
|
255
|
-
resourceId = this.getCurrentActivity().getResources().getIdentifier(refImage, "drawable", this.getCurrentActivity().getPackageName());
|
|
256
|
-
contentBmp = BitmapFactory.decodeResource(getReactApplicationContext().getResources(), resourceId);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
} catch (SVGParseException | MalformedURLException e) {
|
|
261
|
-
e.printStackTrace();
|
|
262
|
-
} catch (IOException e) {
|
|
263
|
-
e.printStackTrace();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return generateFile(contentBmp, fileName);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
private OkayCamPreviewConfig getPreviewConfig(ReadableMap preview, OkayCamFrameConfig frameConfig) {
|
|
270
|
-
if (preview == null) return null;
|
|
271
|
-
OkayCamLabelConfig title = mapToLabelConfig(preview.getMap("title"));
|
|
272
|
-
OkayCamLabelConfig instr1 = mapToLabelConfig(preview.getMap("instruction1"));
|
|
273
|
-
OkayCamLabelConfig instr2 = mapToLabelConfig(preview.getMap("instruction2"));
|
|
274
|
-
OkayCamLabelConfig instr3 = mapToLabelConfig(preview.getMap("instruction3"));
|
|
275
|
-
|
|
276
|
-
int bgColor = Color.parseColor(preview.getString("backgroundColor"));
|
|
277
|
-
|
|
278
|
-
String refImage = preview.getString("refImage");
|
|
279
|
-
|
|
280
|
-
Size size = frameConfig.getSize();
|
|
281
|
-
int frameWidth = size.getWidth();
|
|
282
|
-
int frameHeight = size.getHeight();
|
|
283
|
-
|
|
284
|
-
Bitmap contentBmp = null;
|
|
285
|
-
try {
|
|
286
|
-
if (refImage != null) {
|
|
287
|
-
// In debug, the image is returned as URL
|
|
288
|
-
if (BuildConfig.DEBUG) {
|
|
289
|
-
InputStream inputStream = new URL(refImage).openStream();
|
|
290
|
-
|
|
291
|
-
if (refImage.contains("svg")) {
|
|
292
|
-
|
|
293
|
-
SVG svg = SVG.getFromInputStream(inputStream);
|
|
294
|
-
|
|
295
|
-
svg.setDocumentWidth(frameWidth);
|
|
296
|
-
svg.setDocumentHeight(frameHeight);
|
|
297
|
-
|
|
298
|
-
if (svg.getDocumentWidth() != -1) {
|
|
299
|
-
contentBmp = Bitmap.createBitmap((int) Math.ceil(svg.getDocumentWidth()),
|
|
300
|
-
(int) Math.ceil(svg.getDocumentHeight()),
|
|
301
|
-
Bitmap.Config.ARGB_8888);
|
|
302
|
-
|
|
303
|
-
Canvas bmcanvas = new Canvas(contentBmp);
|
|
304
|
-
|
|
305
|
-
// Render our document onto our canvas
|
|
306
|
-
svg.renderToCanvas(bmcanvas, new RenderOptions().preserveAspectRatio(PreserveAspectRatio.FULLSCREEN));
|
|
307
|
-
}
|
|
308
|
-
} else {
|
|
309
|
-
contentBmp = BitmapFactory.decodeStream(inputStream);
|
|
310
|
-
}
|
|
311
|
-
} else {
|
|
312
|
-
// In release, the image is returned as raw (svg) or drawable (png, jpeg and etc)
|
|
313
|
-
int resourceId = this.getCurrentActivity().getResources().getIdentifier(refImage, "raw", this.getCurrentActivity().getPackageName());
|
|
314
|
-
|
|
315
|
-
if (resourceId != 0) {
|
|
316
|
-
SVG svg = SVG.getFromResource(getReactApplicationContext(), resourceId);
|
|
317
|
-
|
|
318
|
-
svg.setDocumentWidth(frameWidth);
|
|
319
|
-
svg.setDocumentHeight(frameHeight);
|
|
320
|
-
|
|
321
|
-
if (svg.getDocumentWidth() != -1) {
|
|
322
|
-
contentBmp = Bitmap.createBitmap((int) Math.ceil(svg.getDocumentWidth()),
|
|
323
|
-
(int) Math.ceil(svg.getDocumentHeight()),
|
|
324
|
-
Bitmap.Config.ARGB_8888);
|
|
325
|
-
|
|
326
|
-
Canvas bmcanvas = new Canvas(contentBmp);
|
|
327
|
-
|
|
328
|
-
// Render our document onto our canvas
|
|
329
|
-
svg.renderToCanvas(bmcanvas, new RenderOptions().preserveAspectRatio(PreserveAspectRatio.FULLSCREEN));
|
|
330
|
-
}
|
|
331
|
-
} else {
|
|
332
|
-
resourceId = this.getCurrentActivity().getResources().getIdentifier(refImage, "drawable", this.getCurrentActivity().getPackageName());
|
|
333
|
-
contentBmp = BitmapFactory.decodeResource(getReactApplicationContext().getResources(), resourceId);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
} catch (SVGParseException | MalformedURLException e) {
|
|
338
|
-
e.printStackTrace();
|
|
339
|
-
} catch (IOException e) {
|
|
340
|
-
e.printStackTrace();
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return new OkayCamPreviewConfig(
|
|
345
|
-
title,
|
|
346
|
-
generateFile(contentBmp, "ref.png"),
|
|
347
|
-
instr1,
|
|
348
|
-
instr2,
|
|
349
|
-
instr3,
|
|
350
|
-
bgColor
|
|
351
|
-
);
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
private OkayCamLabelConfig mapToLabelConfig(ReadableMap map) {
|
|
356
|
-
return new OkayCamLabelConfig(
|
|
357
|
-
map.getString("text"),
|
|
358
|
-
Color.parseColor(map.getString("color")),
|
|
359
|
-
map.getInt("size")
|
|
360
|
-
);
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
private OkayCamFrameConfig getFrameConfig(ReadableMap frameConfig) {
|
|
365
|
-
ReadableMap frameSizeMap = frameConfig.getMap("size");
|
|
366
|
-
String frameColor = frameConfig.getString("color");
|
|
367
|
-
String frameContent = frameConfig.getString("content");
|
|
368
|
-
|
|
369
|
-
int frameWidth = frameSizeMap.getInt("width");
|
|
370
|
-
int frameHeight = frameSizeMap.getInt("height");
|
|
371
|
-
Size frameSize = new Size(frameWidth, frameHeight);
|
|
372
|
-
|
|
373
|
-
try {
|
|
374
|
-
if (frameContent != null) {
|
|
375
|
-
Bitmap contentBmp = null;
|
|
376
|
-
|
|
377
|
-
// In debug, the image is returned as URL
|
|
378
|
-
if (BuildConfig.DEBUG) {
|
|
379
|
-
InputStream inputStream = new URL(frameContent).openStream();
|
|
380
|
-
|
|
381
|
-
if (frameContent.contains("svg")) {
|
|
382
|
-
|
|
383
|
-
SVG svg = SVG.getFromInputStream(inputStream);
|
|
384
|
-
|
|
385
|
-
svg.setDocumentWidth(frameWidth);
|
|
386
|
-
svg.setDocumentHeight(frameHeight);
|
|
387
|
-
|
|
388
|
-
if (svg.getDocumentWidth() != -1) {
|
|
389
|
-
contentBmp = Bitmap.createBitmap((int) Math.ceil(svg.getDocumentWidth()),
|
|
390
|
-
(int) Math.ceil(svg.getDocumentHeight()),
|
|
391
|
-
Bitmap.Config.ARGB_8888);
|
|
392
|
-
|
|
393
|
-
Canvas bmcanvas = new Canvas(contentBmp);
|
|
394
|
-
|
|
395
|
-
// Render our document onto our canvas
|
|
396
|
-
svg.renderToCanvas(bmcanvas, new RenderOptions().preserveAspectRatio(PreserveAspectRatio.FULLSCREEN));
|
|
397
|
-
}
|
|
398
|
-
} else {
|
|
399
|
-
contentBmp = BitmapFactory.decodeStream(inputStream);
|
|
400
|
-
}
|
|
401
|
-
} else {
|
|
402
|
-
// In release, the image is returned as raw (svg) or drawable (png, jpeg and etc)
|
|
403
|
-
int resourceId = this.getCurrentActivity().getResources().getIdentifier(frameContent, "raw", this.getCurrentActivity().getPackageName());
|
|
404
|
-
|
|
405
|
-
if (resourceId != 0) {
|
|
406
|
-
SVG svg = SVG.getFromResource(getReactApplicationContext(), resourceId);
|
|
407
|
-
|
|
408
|
-
svg.setDocumentWidth(frameWidth);
|
|
409
|
-
svg.setDocumentHeight(frameHeight);
|
|
410
|
-
|
|
411
|
-
if (svg.getDocumentWidth() != -1) {
|
|
412
|
-
contentBmp = Bitmap.createBitmap((int) Math.ceil(svg.getDocumentWidth()),
|
|
413
|
-
(int) Math.ceil(svg.getDocumentHeight()),
|
|
414
|
-
Bitmap.Config.ARGB_8888);
|
|
415
|
-
|
|
416
|
-
Canvas bmcanvas = new Canvas(contentBmp);
|
|
417
|
-
|
|
418
|
-
// Render our document onto our canvas
|
|
419
|
-
svg.renderToCanvas(bmcanvas, new RenderOptions().preserveAspectRatio(PreserveAspectRatio.FULLSCREEN));
|
|
420
|
-
}
|
|
421
|
-
} else {
|
|
422
|
-
resourceId = this.getCurrentActivity().getResources().getIdentifier(frameContent, "drawable", this.getCurrentActivity().getPackageName());
|
|
423
|
-
contentBmp = BitmapFactory.decodeResource(getReactApplicationContext().getResources(), resourceId);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return new OkayCamFrameConfig(frameSize, Color.parseColor(frameColor), generateFile(contentBmp, "content.png"));
|
|
427
|
-
}
|
|
428
|
-
} catch (SVGParseException | MalformedURLException e) {
|
|
429
|
-
e.printStackTrace();
|
|
430
|
-
} catch (IOException e) {
|
|
431
|
-
e.printStackTrace();
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return new OkayCamFrameConfig(frameSize, Color.parseColor(frameColor), null);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
public String generateFile(Bitmap bitmap, String filename) {
|
|
438
|
-
try {
|
|
439
|
-
String resultedFolder = ".private";
|
|
440
|
-
File privateFolder = this.getReactApplicationContext().getExternalFilesDir(resultedFolder);
|
|
441
|
-
|
|
442
|
-
if (!privateFolder.exists()) {
|
|
443
|
-
privateFolder.mkdir();
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
File file = new File(privateFolder, filename);
|
|
447
|
-
file.createNewFile();
|
|
448
|
-
|
|
449
|
-
FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
|
|
450
|
-
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
|
451
|
-
|
|
452
|
-
return file.getAbsolutePath();
|
|
453
|
-
} catch (IOException e) {
|
|
454
|
-
e.printStackTrace();
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return null;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
105
|
@ReactMethod
|
|
461
106
|
public void captureSelfie(ReadableMap configs, Promise promise) {
|
|
462
107
|
String LICENSE_KEY = configs.getString("license");
|
|
@@ -508,15 +153,12 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
|
|
|
508
153
|
okaySelfieConfig.setImageQuality((float) userConfig.getDouble("imageQuality"));
|
|
509
154
|
|
|
510
155
|
OkayCamSelfie.start(this.getCurrentActivity(), LICENSE_KEY, okaySelfieConfig, (success, image, exception) -> {
|
|
511
|
-
|
|
512
156
|
if (success) {
|
|
513
|
-
|
|
514
157
|
JSONObject results = new JSONObject();
|
|
515
158
|
try {
|
|
516
159
|
results.put("selfieImage", convertImgToBase64(base64, image));
|
|
517
160
|
promise.resolve(results.toString());
|
|
518
161
|
} catch (JSONException e) {
|
|
519
|
-
// TODO Auto-generated catch block
|
|
520
162
|
e.printStackTrace();
|
|
521
163
|
promise.reject(this.getError(e.getMessage()));
|
|
522
164
|
}
|
|
@@ -554,4 +196,19 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
|
|
|
554
196
|
}
|
|
555
197
|
return new Exception(errorString);
|
|
556
198
|
}
|
|
199
|
+
|
|
200
|
+
private OkayCamAutoCaptureMode parseMode(String mode) {
|
|
201
|
+
if (mode == null) return OkayCamAutoCaptureMode.FULL;
|
|
202
|
+
|
|
203
|
+
switch (mode) {
|
|
204
|
+
case "FRONT_ONLY":
|
|
205
|
+
return OkayCamAutoCaptureMode.FRONT_ONLY;
|
|
206
|
+
case "FRONT_BACK":
|
|
207
|
+
return OkayCamAutoCaptureMode.FRONT_BACK;
|
|
208
|
+
case "FRONT_WITH_FLASH":
|
|
209
|
+
return OkayCamAutoCaptureMode.FRONT_WITH_FLASH;
|
|
210
|
+
default:
|
|
211
|
+
return OkayCamAutoCaptureMode.FULL;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
557
214
|
}
|
package/index.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
NativeModules,
|
|
3
|
-
Dimensions,
|
|
4
|
-
PixelRatio,
|
|
5
|
-
Image,
|
|
6
|
-
ImageResolvedAssetSource,
|
|
7
|
-
Platform,
|
|
8
|
-
} from "react-native";
|
|
1
|
+
import { NativeModules } from "react-native";
|
|
9
2
|
|
|
10
3
|
const { RNOkayCam } = NativeModules;
|
|
11
4
|
|
|
12
|
-
|
|
5
|
+
export enum DocumentCaptureMode {
|
|
6
|
+
FULL = "FULL",
|
|
7
|
+
FRONT_ONLY = "FRONT_ONLY",
|
|
8
|
+
FRONT_BACK = "FRONT_BACK",
|
|
9
|
+
FRONT_WITH_FLASH = "FRONT_WITH_FLASH",
|
|
10
|
+
}
|
|
13
11
|
|
|
14
12
|
interface LabelConfig {
|
|
15
13
|
text: string;
|
|
@@ -17,52 +15,11 @@ interface LabelConfig {
|
|
|
17
15
|
size: number;
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
interface OkayCamPreviewConfig {
|
|
21
|
-
title: LabelConfig;
|
|
22
|
-
refImage: ImageResolvedAssetSource;
|
|
23
|
-
instruction1: LabelConfig;
|
|
24
|
-
instruction2: LabelConfig;
|
|
25
|
-
instruction3: LabelConfig;
|
|
26
|
-
backgroundColor: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface OkaycamInstructionRefImg {
|
|
30
|
-
title: LabelConfig;
|
|
31
|
-
img: ImageResolvedAssetSource;
|
|
32
|
-
}
|
|
33
|
-
interface OkayCamInstruction {
|
|
34
|
-
title: LabelConfig;
|
|
35
|
-
refImage1: OkaycamInstructionRefImg;
|
|
36
|
-
refImage2?: OkaycamInstructionRefImg;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface FrameSize {
|
|
40
|
-
width: number;
|
|
41
|
-
height: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface Frame {
|
|
45
|
-
size: FrameSize;
|
|
46
|
-
color: string;
|
|
47
|
-
content: ImageResolvedAssetSource;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface TimerConfig {
|
|
51
|
-
backgroundColor: string;
|
|
52
|
-
textColor: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
18
|
interface OkayCamBtnConfig {
|
|
56
19
|
backgroundColor: string;
|
|
57
20
|
contentColor: string;
|
|
58
21
|
}
|
|
59
22
|
|
|
60
|
-
interface CaptureConfig {
|
|
61
|
-
delay: number;
|
|
62
|
-
onFlash: Boolean;
|
|
63
|
-
outputPath?: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
23
|
interface SwitchBtnConfig {
|
|
67
24
|
color: string;
|
|
68
25
|
show: Boolean;
|
|
@@ -81,148 +38,29 @@ const labelConfig: LabelConfig = {
|
|
|
81
38
|
size: 20,
|
|
82
39
|
};
|
|
83
40
|
|
|
84
|
-
const defaultFrame: Frame = {
|
|
85
|
-
size: {
|
|
86
|
-
width: screenWidth * 0.9,
|
|
87
|
-
height: (screenWidth * 54) / 85,
|
|
88
|
-
},
|
|
89
|
-
color: defaultColor,
|
|
90
|
-
content: null,
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const timerConfig: TimerConfig = {
|
|
94
|
-
backgroundColor: defaultColor2,
|
|
95
|
-
textColor: defaultColor,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
41
|
const okayCamBtnConfig: OkayCamBtnConfig = {
|
|
99
42
|
backgroundColor: defaultColor2,
|
|
100
43
|
contentColor: defaultColor,
|
|
101
44
|
};
|
|
102
45
|
|
|
103
|
-
const defaultCaptureBtnColor: string = defaultColor;
|
|
104
|
-
|
|
105
|
-
const captureConfigFirst: CaptureConfig = {
|
|
106
|
-
delay: 0,
|
|
107
|
-
onFlash: false,
|
|
108
|
-
outputPath: null,
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const defaultPreview: OkayCamPreviewConfig = null;
|
|
112
|
-
|
|
113
|
-
const defaultInstruction: OkayCamInstruction = null;
|
|
114
|
-
|
|
115
|
-
const captureConfigSecond: CaptureConfig = null;
|
|
116
|
-
|
|
117
|
-
const formatImage = (img: ImageResolvedAssetSource) => {
|
|
118
|
-
return Image.resolveAssetSource(img).uri;
|
|
119
|
-
// return img;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const formatInstruction = (
|
|
123
|
-
instruction: OkayCamInstruction
|
|
124
|
-
): OkayCamInstruction => {
|
|
125
|
-
if (instruction == null) return null;
|
|
126
|
-
|
|
127
|
-
const ref1: OkaycamInstructionRefImg = {
|
|
128
|
-
...instruction.refImage1,
|
|
129
|
-
img: formatImage(instruction.refImage1.img),
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
let ref2: OkaycamInstructionRefImg = null;
|
|
133
|
-
if (instruction.refImage2 != null) {
|
|
134
|
-
ref2 = {
|
|
135
|
-
...instruction.refImage2,
|
|
136
|
-
img: formatImage(instruction.refImage2.img),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const formattedInstruction: OkayCamInstruction = {
|
|
141
|
-
title: instruction.title,
|
|
142
|
-
refImage1: ref1,
|
|
143
|
-
refImage2: ref2,
|
|
144
|
-
};
|
|
145
|
-
return formattedInstruction;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
46
|
// cal native capture document
|
|
149
47
|
export const captureDocument = (
|
|
150
48
|
license: string,
|
|
151
49
|
base64: Boolean,
|
|
152
50
|
{
|
|
153
|
-
showOverlay = true,
|
|
154
|
-
topLabel = labelConfig,
|
|
155
|
-
bottomLabel = labelConfig,
|
|
156
|
-
frame = defaultFrame,
|
|
157
|
-
timer = timerConfig,
|
|
158
|
-
torchBtnEnabled = false,
|
|
159
|
-
confirmBtnConfig = okayCamBtnConfig,
|
|
160
|
-
retakeBtnConfig = okayCamBtnConfig,
|
|
161
|
-
captureBtnColor = defaultCaptureBtnColor,
|
|
162
|
-
firstPhotoConfig = captureConfigFirst,
|
|
163
|
-
secondPhotoConfig = captureConfigSecond,
|
|
164
|
-
crop = false,
|
|
165
51
|
width = imageResizedWidth,
|
|
166
52
|
imageQuality = 1.0,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
showPreviewInstruction = false,
|
|
170
|
-
autoCapture = true,
|
|
171
|
-
}
|
|
53
|
+
mode = DocumentCaptureMode.FULL,
|
|
54
|
+
},
|
|
172
55
|
) => {
|
|
173
|
-
if (frame.size == undefined) {
|
|
174
|
-
frame.size = defaultFrame.size;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const resultedPreview =
|
|
178
|
-
preview == null
|
|
179
|
-
? null
|
|
180
|
-
: {
|
|
181
|
-
...preview,
|
|
182
|
-
refImage: Image.resolveAssetSource(preview.refImage).uri,
|
|
183
|
-
};
|
|
184
|
-
|
|
185
56
|
return new Promise(function (resolve, reject) {
|
|
186
57
|
RNOkayCam.captureDocument({
|
|
187
58
|
license: license,
|
|
188
59
|
base64: base64,
|
|
189
60
|
config: {
|
|
190
|
-
showOverlay: showOverlay,
|
|
191
|
-
topLabel: topLabel,
|
|
192
|
-
bottomLabel: bottomLabel,
|
|
193
|
-
frame: {
|
|
194
|
-
size: Platform.select({
|
|
195
|
-
android: {
|
|
196
|
-
width: PixelRatio.getPixelSizeForLayoutSize(frame.size.width),
|
|
197
|
-
height: PixelRatio.getPixelSizeForLayoutSize(frame.size.height),
|
|
198
|
-
},
|
|
199
|
-
ios: {
|
|
200
|
-
width: frame.size.width,
|
|
201
|
-
height: frame.size.height,
|
|
202
|
-
},
|
|
203
|
-
}),
|
|
204
|
-
color: frame.color != null ? frame.color : defaultFrame.color,
|
|
205
|
-
content:
|
|
206
|
-
frame.content != null
|
|
207
|
-
? Image.resolveAssetSource(frame.content).uri
|
|
208
|
-
: null,
|
|
209
|
-
},
|
|
210
|
-
timer: timer,
|
|
211
|
-
torchBtnEnabled: torchBtnEnabled,
|
|
212
|
-
confirmBtnConfig: confirmBtnConfig,
|
|
213
|
-
retakeBtnConfig: retakeBtnConfig,
|
|
214
|
-
captureBtnColor: captureBtnColor,
|
|
215
|
-
captureConfigPair: {
|
|
216
|
-
firstPhoto: firstPhotoConfig,
|
|
217
|
-
secondPhoto: secondPhotoConfig,
|
|
218
|
-
},
|
|
219
|
-
crop: crop,
|
|
220
61
|
width: width,
|
|
221
62
|
imageQuality: imageQuality,
|
|
222
|
-
|
|
223
|
-
instruction: formatInstruction(instruction),
|
|
224
|
-
showPreviewInstruction: showPreviewInstruction,
|
|
225
|
-
autoCapture: autoCapture,
|
|
63
|
+
mode: mode,
|
|
226
64
|
},
|
|
227
65
|
})
|
|
228
66
|
.then((result) => {
|
|
@@ -255,7 +93,7 @@ export const captureSelfie = (
|
|
|
255
93
|
defaultCameraFacing = cameraFacing,
|
|
256
94
|
width = imageResizedWidth,
|
|
257
95
|
imageQuality = 1.0,
|
|
258
|
-
}
|
|
96
|
+
},
|
|
259
97
|
) => {
|
|
260
98
|
return new Promise(function (resolve, reject) {
|
|
261
99
|
RNOkayCam.captureSelfie({
|
package/ios/RNOkayCam.swift
CHANGED
|
@@ -20,124 +20,32 @@ class RNOkayCam: NSObject {
|
|
|
20
20
|
let license = configs.object(forKey: "license")! as! String
|
|
21
21
|
let base64 = configs.object(forKey: "base64") as! Bool
|
|
22
22
|
let rnOkayCamConfig = configs.object(forKey: "config") as! NSDictionary
|
|
23
|
-
let topLabel = rnOkayCamConfig.object(forKey: "topLabel") as! NSDictionary
|
|
24
|
-
let bottomLabel = rnOkayCamConfig.object(forKey: "bottomLabel") as! NSDictionary
|
|
25
|
-
|
|
26
|
-
// frame configurations
|
|
27
|
-
let frame = rnOkayCamConfig.object(forKey: "frame") as? NSDictionary
|
|
28
|
-
let frameSize = frame?.object(forKey: "size") as? NSDictionary
|
|
29
|
-
let frameWidth = frameSize?.object(forKey: "width") as? CGFloat
|
|
30
|
-
let frameHeight = frameSize?.object(forKey: "height") as? CGFloat
|
|
31
|
-
let frameColor = frame?.object(forKey: "color") as! String
|
|
32
|
-
let frameContent = frame?.object(forKey: "content") as? String
|
|
33
|
-
|
|
34
|
-
let showOverlay = rnOkayCamConfig.object(forKey: "showOverlay") as! Bool
|
|
35
23
|
|
|
36
|
-
let timer = rnOkayCamConfig.object(forKey: "timer") as! NSDictionary
|
|
37
|
-
let captureBtnColor = rnOkayCamConfig.object(forKey: "captureBtnColor") as! String
|
|
38
|
-
let captureConfigPair = rnOkayCamConfig.object(forKey: "captureConfigPair") as! NSDictionary
|
|
39
|
-
let confirmBtnConfig = rnOkayCamConfig.object(forKey: "confirmBtnConfig") as! NSDictionary
|
|
40
|
-
let retakeBtnConfig = rnOkayCamConfig.object(forKey: "retakeBtnConfig") as! NSDictionary
|
|
41
|
-
let firstPhoto = captureConfigPair.object(forKey: "firstPhoto") as! NSDictionary
|
|
42
|
-
let secondPhoto = captureConfigPair.object(forKey: "secondPhoto") as? NSDictionary
|
|
43
|
-
let crop = rnOkayCamConfig.object(forKey: "crop") as! Bool
|
|
44
|
-
let torchBtnEnabled = rnOkayCamConfig.object(forKey: "torchBtnEnabled") as! Bool
|
|
45
24
|
let width = rnOkayCamConfig.object(forKey: "width") as! Int
|
|
46
25
|
let imageQuality = rnOkayCamConfig.object(forKey: "imageQuality") as! CGFloat
|
|
47
|
-
let
|
|
26
|
+
let mode = rnOkayCamConfig.object(forKey: "mode") as? String
|
|
48
27
|
|
|
49
28
|
DispatchQueue.main.async {
|
|
50
|
-
let rootViewController =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// top label
|
|
55
|
-
okayCamConfig.topLabel.text = topLabel.object(forKey: "text") as! String
|
|
56
|
-
okayCamConfig.topLabel.color = self.hexStringToUIColor(hex: topLabel.object(forKey: "color") as! String)
|
|
57
|
-
okayCamConfig.topLabel.size = CGFloat(topLabel.object(forKey: "size") as! Int)
|
|
58
|
-
|
|
59
|
-
// bottom label
|
|
60
|
-
okayCamConfig.bottomLabel.text = bottomLabel.object(forKey: "text") as! String
|
|
61
|
-
okayCamConfig.bottomLabel.color = self.hexStringToUIColor(hex: bottomLabel.object(forKey: "color") as! String)
|
|
62
|
-
okayCamConfig.bottomLabel.size = bottomLabel.object(forKey: "size") as! CGFloat
|
|
63
|
-
|
|
64
|
-
// frame size
|
|
65
|
-
if (frameSize != nil) {
|
|
66
|
-
okayCamConfig.frame.size = CGSize(width: frameWidth!, height: frameHeight!)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// frame color
|
|
70
|
-
okayCamConfig.frame.color = self.hexStringToUIColor(hex: frameColor)
|
|
71
|
-
|
|
72
|
-
// frame contet
|
|
73
|
-
if (frameContent != nil) {
|
|
74
|
-
#if DEBUG
|
|
75
|
-
okayCamConfig.frame.content = URL(string: frameContent!)
|
|
76
|
-
#else
|
|
77
|
-
okayCamConfig.frame.content = URL(fileURLWithPath: frameContent!.replacingOccurrences(of: "file:///", with: ""))
|
|
78
|
-
#endif
|
|
29
|
+
guard let rootViewController = UIApplication.shared.windows.first?.rootViewController else {
|
|
30
|
+
reject("no_root_view_controller", "Root view controller not found", nil)
|
|
31
|
+
return
|
|
79
32
|
}
|
|
80
33
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// timer
|
|
84
|
-
okayCamConfig.timer.backgroundColor = self.hexStringToUIColor(hex: timer.object(forKey: "backgroundColor") as! String,alpha:0.5)
|
|
85
|
-
okayCamConfig.timer.textColor = self.hexStringToUIColor(hex: timer.object(forKey: "textColor") as! String)
|
|
86
|
-
|
|
87
|
-
// capture button color
|
|
88
|
-
okayCamConfig.captureBtnColor = self.hexStringToUIColor(hex: captureBtnColor)
|
|
89
|
-
|
|
90
|
-
// show torch button
|
|
91
|
-
okayCamConfig.torchBtnEnabled = torchBtnEnabled
|
|
34
|
+
let config = OkayCamAutoCaptureConfig(viewController: rootViewController)
|
|
92
35
|
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// confirm button config
|
|
97
|
-
okayCamConfig.confirmBtnConfig.backgroundColor = self.hexStringToUIColor(hex: confirmBtnConfig.object(forKey: "backgroundColor") as! String)
|
|
98
|
-
okayCamConfig.confirmBtnConfig.contentColor = self.hexStringToUIColor(hex: confirmBtnConfig.object(forKey: "contentColor") as! String)
|
|
36
|
+
// if (width != -1) {
|
|
37
|
+
// config.width = width
|
|
38
|
+
// }
|
|
99
39
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
okayCamConfig.retakeBtnConfig.contentColor = self.hexStringToUIColor(hex: retakeBtnConfig.object(forKey: "contentColor") as! String)
|
|
103
|
-
|
|
104
|
-
// capture configurations
|
|
105
|
-
let firstPhotoPath = firstPhoto.object(forKey: "outputPath") as? String
|
|
106
|
-
let secondPhotoPath = secondPhoto?.object(forKey: "outputPath") as? String
|
|
107
|
-
okayCamConfig.captureConfigPair = CaptureConfigPair(
|
|
108
|
-
firstPhoto: OkayCamCaptureConfig(
|
|
109
|
-
timeOut: firstPhoto.object(forKey: "delay") as! Int,
|
|
110
|
-
onFlash: firstPhoto.object(forKey: "onFlash") as! Bool,
|
|
111
|
-
outputPath: (firstPhotoPath != nil) ? URL(string: (firstPhoto.object(forKey: "outputPath") as? String)!) : nil
|
|
112
|
-
),
|
|
113
|
-
secondPhoto: (secondPhoto != nil) ? OkayCamCaptureConfig(
|
|
114
|
-
timeOut: secondPhoto?.object(forKey: "delay") as? Int ?? 0,
|
|
115
|
-
onFlash: secondPhoto?.object(forKey: "onFlash") as? Bool ?? false,
|
|
116
|
-
outputPath: (secondPhotoPath != nil) ? URL(string: (secondPhoto?.object(forKey: "outputPath") as! String?)!) : nil
|
|
117
|
-
) : nil
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
okayCamConfig.crop = crop
|
|
121
|
-
|
|
122
|
-
if (width != -1) {
|
|
123
|
-
okayCamConfig.width = width
|
|
40
|
+
if (imageQuality > 0.0) {
|
|
41
|
+
config.imageQuality = imageQuality
|
|
124
42
|
}
|
|
125
|
-
|
|
126
|
-
// preview config
|
|
127
|
-
|
|
128
|
-
let previewConfig = rnOkayCamConfig.object(forKey: "preview") as? NSDictionary
|
|
129
|
-
|
|
130
|
-
okayCamConfig.preview = self.getOkaycamPreview(previewConfig: previewConfig)
|
|
131
43
|
|
|
132
|
-
|
|
133
|
-
let instructionConfig = rnOkayCamConfig.object(forKey: "instruction") as? NSDictionary
|
|
134
|
-
okayCamConfig.instruction = self.getOkayCamInstruction(instructionConfig: instructionConfig)
|
|
135
|
-
|
|
136
|
-
okayCamConfig.autoCapture = autoCapture
|
|
44
|
+
config.mode = self.parseMode(mode)
|
|
137
45
|
|
|
138
46
|
// start the SDK
|
|
139
|
-
|
|
140
|
-
okayCamConfig:
|
|
47
|
+
OkayCamDocAutoCapture.start(
|
|
48
|
+
okayCamConfig: config,
|
|
141
49
|
license: license,
|
|
142
50
|
{ filePaths, error in
|
|
143
51
|
// handle error
|
|
@@ -179,71 +87,6 @@ class RNOkayCam: NSObject {
|
|
|
179
87
|
}
|
|
180
88
|
}
|
|
181
89
|
|
|
182
|
-
func getOkaycamPreview(previewConfig: NSDictionary?) -> OkayCamPreviewConfig?{
|
|
183
|
-
if previewConfig == nil { return nil}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
let title = configToOkayCamLabel(config: previewConfig?.object(forKey: "title") as! NSDictionary)
|
|
187
|
-
|
|
188
|
-
let instr1 = configToOkayCamLabel(config: previewConfig?.object(forKey: "instruction1") as! NSDictionary)
|
|
189
|
-
|
|
190
|
-
let instr2 = configToOkayCamLabel(config: previewConfig?.object(forKey: "instruction2") as! NSDictionary)
|
|
191
|
-
|
|
192
|
-
let instr3 = configToOkayCamLabel(config: previewConfig?.object(forKey: "instruction3") as! NSDictionary)
|
|
193
|
-
|
|
194
|
-
let bgColor = self.hexStringToUIColor(hex: previewConfig?.object(forKey: "backgroundColor") as! String)
|
|
195
|
-
|
|
196
|
-
// frame contet
|
|
197
|
-
let ref = previewConfig?.object(forKey: "refImage") as? String
|
|
198
|
-
var refUrl:URL? = nil
|
|
199
|
-
if (ref != nil) {
|
|
200
|
-
#if DEBUG
|
|
201
|
-
refUrl = URL(string: ref!)!
|
|
202
|
-
#else
|
|
203
|
-
refUrl = URL(fileURLWithPath: ref!.replacingOccurrences(of: "file:///", with: ""))
|
|
204
|
-
#endif
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return OkayCamPreviewConfig(title: title, refImage: refUrl!, instruction1: instr1, instruction2: instr2, instruction3: instr3, backgroundColor: bgColor)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
func getOkayCamInstruction(instructionConfig: NSDictionary?) -> OkayCamInstruction?{
|
|
211
|
-
if instructionConfig == nil {return nil}
|
|
212
|
-
|
|
213
|
-
let title = configToOkayCamLabel(config: instructionConfig?.object(forKey: "title") as! NSDictionary)
|
|
214
|
-
|
|
215
|
-
let ref1 = getInstructionRefImage(refImage: instructionConfig?.object(forKey: "refImage1") as! NSDictionary)
|
|
216
|
-
|
|
217
|
-
let ref2 = getInstructionRefImage(refImage: instructionConfig?.object(forKey: "refImage2") as? NSDictionary)
|
|
218
|
-
|
|
219
|
-
return OkayCamInstruction(title:title,refImage1:ref1!,refImage2:ref2)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
func getInstructionRefImage(refImage:NSDictionary?) -> OkaycamInstructionRefImg?{
|
|
223
|
-
if refImage == nil {return nil}
|
|
224
|
-
|
|
225
|
-
let title = configToOkayCamLabel(config: refImage?.object(forKey: "title") as! NSDictionary)
|
|
226
|
-
|
|
227
|
-
// frame contet
|
|
228
|
-
let ref = refImage?.object(forKey: "img") as? String
|
|
229
|
-
var refUrl:URL? = nil
|
|
230
|
-
if (ref != nil) {
|
|
231
|
-
#if DEBUG
|
|
232
|
-
refUrl = URL(string: ref!)!
|
|
233
|
-
#else
|
|
234
|
-
refUrl = URL(fileURLWithPath: ref!.replacingOccurrences(of: "file:///", with: ""))
|
|
235
|
-
#endif
|
|
236
|
-
}
|
|
237
|
-
return OkaycamInstructionRefImg(title:title,img:refUrl!)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
func configToOkayCamLabel(config:NSDictionary) -> OkayCamLabelConfig{
|
|
241
|
-
let text = config.object(forKey: "text") as! String
|
|
242
|
-
let color = self.hexStringToUIColor(hex: config.object(forKey: "color") as! String)
|
|
243
|
-
let size = CGFloat(config.object(forKey: "size") as! Int)
|
|
244
|
-
return OkayCamLabelConfig(text: text, color: color, size: size)
|
|
245
|
-
}
|
|
246
|
-
|
|
247
90
|
@objc func captureSelfie(_ configs: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
248
91
|
|
|
249
92
|
let license = configs.object(forKey: "license")! as! String
|
|
@@ -260,8 +103,11 @@ class RNOkayCam: NSObject {
|
|
|
260
103
|
let imageQuality = rnOkayCamConfig.object(forKey: "imageQuality") as! CGFloat
|
|
261
104
|
|
|
262
105
|
DispatchQueue.main.async {
|
|
263
|
-
let rootViewController =
|
|
264
|
-
|
|
106
|
+
guard let rootViewController = UIApplication.shared.windows.first?.rootViewController else {
|
|
107
|
+
reject("no_root_view_controller", "Root view controller not found", nil)
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
265
111
|
let okaySelfieConfig = OkaySelfieConfig(viewController: rootViewController)
|
|
266
112
|
|
|
267
113
|
// top label
|
|
@@ -399,12 +245,30 @@ class RNOkayCam: NSObject {
|
|
|
399
245
|
case .cameraPermission:
|
|
400
246
|
reject("camera permission denied", "camera permission denied", nil)
|
|
401
247
|
return
|
|
402
|
-
case .failedToCreateIADBundle:
|
|
403
|
-
reject("failed to create IAD bundle", "failed to create IAD bundle", nil)
|
|
404
|
-
return
|
|
405
248
|
@unknown default:
|
|
406
249
|
reject("no error", "no error", nil)
|
|
407
250
|
return
|
|
408
251
|
}
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
func parseMode(_ mode: String?) -> OkayCamAutoCaptureMode {
|
|
256
|
+
guard let mode = mode else {
|
|
257
|
+
return .full
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
switch mode {
|
|
261
|
+
case "FRONT_ONLY":
|
|
262
|
+
return .frontOnly
|
|
263
|
+
|
|
264
|
+
case "FRONT_BACK":
|
|
265
|
+
return .frontBack
|
|
266
|
+
|
|
267
|
+
case "FRONT_WITH_FLASH":
|
|
268
|
+
return .frontWithFlash
|
|
269
|
+
|
|
270
|
+
default:
|
|
271
|
+
return .full
|
|
272
|
+
}
|
|
409
273
|
}
|
|
410
274
|
}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.homepage = "https://gitlab.com/innov8tif-ekyc-product/okaycam/mobile/react-native-okaycam.git"
|
|
11
11
|
s.license = "MIT"
|
|
12
12
|
s.authors = { "Innov8tif" => "ekyc.team@innov8tif.com" }
|
|
13
|
-
s.platforms = { :ios => "15.
|
|
13
|
+
s.platforms = { :ios => "15.6" }
|
|
14
14
|
s.source = { :git => "https://gitlab.com/innov8tif-ekyc-product/okaycam/mobile/react-native-okaycam.git", :tag => "#{s.version}" }
|
|
15
15
|
|
|
16
16
|
s.source_files = "ios/**/*.{h,m,swift}"
|
|
@@ -26,7 +26,7 @@ Pod::Spec.new do |s|
|
|
|
26
26
|
s.dependency "React-RCTFabric"
|
|
27
27
|
|
|
28
28
|
# OkayCam CocoaPod dependency
|
|
29
|
-
s.dependency "OkayCam", "3.0.
|
|
29
|
+
s.dependency "OkayCam", "3.0.15"
|
|
30
30
|
s.dependency "CryptoSwift", "1.8.2"
|
|
31
31
|
|
|
32
32
|
s.pod_target_xcconfig = {
|
package/setup_podfile.js
CHANGED
|
@@ -50,7 +50,7 @@ post_install do |installer|
|
|
|
50
50
|
script = <<~SCRIPT
|
|
51
51
|
echo "Re-signing embedded frameworks..."
|
|
52
52
|
set -e
|
|
53
|
-
APP_PATH="
|
|
53
|
+
APP_PATH="\${TARGET_BUILD_DIR}/\${WRAPPER_NAME}"
|
|
54
54
|
find "$APP_PATH/Frameworks" -type d -name "*.framework" | while read framework
|
|
55
55
|
do
|
|
56
56
|
echo "Re-signing $framework"
|
|
@@ -67,7 +67,7 @@ end
|
|
|
67
67
|
|
|
68
68
|
if (podfile.includes("post_install do |installer|")) {
|
|
69
69
|
console.log(
|
|
70
|
-
"🔧 Detected existing post_install block — injecting after react_native_post_install"
|
|
70
|
+
"🔧 Detected existing post_install block — injecting after react_native_post_install",
|
|
71
71
|
);
|
|
72
72
|
|
|
73
73
|
const innerHook = `
|
|
@@ -80,7 +80,7 @@ if (podfile.includes("post_install do |installer|")) {
|
|
|
80
80
|
script = <<~SCRIPT
|
|
81
81
|
echo "Re-signing embedded frameworks..."
|
|
82
82
|
set -e
|
|
83
|
-
APP_PATH="
|
|
83
|
+
APP_PATH="\${TARGET_BUILD_DIR}/\${WRAPPER_NAME}"
|
|
84
84
|
find "$APP_PATH/Frameworks" -type d -name "*.framework" | while read framework
|
|
85
85
|
do
|
|
86
86
|
echo "Re-signing $framework"
|
|
@@ -97,12 +97,12 @@ if (podfile.includes("post_install do |installer|")) {
|
|
|
97
97
|
if (podfile.includes("react_native_post_install")) {
|
|
98
98
|
podfile = podfile.replace(
|
|
99
99
|
/(react_native_post_install\s*\(.*\)\s*)/,
|
|
100
|
-
`$1\n${innerHook}
|
|
100
|
+
`$1\n${innerHook}`,
|
|
101
101
|
);
|
|
102
102
|
console.log("✨ Injected OkayCam hook after react_native_post_install.");
|
|
103
103
|
} else {
|
|
104
104
|
console.log(
|
|
105
|
-
"⚠️ react_native_post_install not found, appending before end of post_install."
|
|
105
|
+
"⚠️ react_native_post_install not found, appending before end of post_install.",
|
|
106
106
|
);
|
|
107
107
|
podfile = podfile.replace(/end\s*$/, `${innerHook}\nend`);
|
|
108
108
|
}
|