react-native-okaycam 3.0.3 → 3.0.5

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 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
- target.build_phases.each do |build_phase|
57
- if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
58
- target.build_phases.move(build_phase, 0)
59
- end
60
- end
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
- | - | Property name | Description | Default value |
110
- | ------------------------------ | ------------------------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
111
- | - | torchBtnEnabled | to show torch button. If set to true, it will only be shown if onFlash from captureConfig is set to false. | false |
112
- | - | crop | crop the frame area | false |
113
- | - | width | width to resize the image | original width |
114
- | - | imageQuality | quality of image | 1.0 (range from 0.0 to 1.0) |
115
- | frame | size | size of the frame (width and height) | 90% of screen width and height is scaled proportionally according to card ratio |
116
- | frame | color | color of the frame | #ffffff |
117
- | frame | content | content of the frame (able to display svg file within the frame for guidance | null |
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
- license,
153
- {
154
- topLabel: {
155
- text: "Align your card within the frame",
156
- color: "#4287f5",
157
- size: 20
158
- },
159
- bottomLabel: {
160
- text: "Tap to Focus",
161
- color: "#4287f5",
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 firstPhotoConfig |
236
- | fullDocumentImage2 | Result of secondPhotoConfig. Will only return if secondPhotoConfig is configured |
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
 
@@ -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.0.6@aar') {
47
+ implementation('com.innov8tif.okaycam:OkayCam:3.0.11@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;
@@ -18,23 +19,17 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
18
19
  import com.facebook.react.bridge.ReactMethod;
19
20
  import com.facebook.react.bridge.ReadableMap;
20
21
 
21
- import com.innov8tif.okaycam.cam.OkayCamDoc;
22
+ import com.innov8tif.okaycam.cam.OkayCamAutoDoc;
22
23
  import com.innov8tif.okaycam.config.CameraFacing;
23
- import com.innov8tif.okaycam.config.CaptureConfigPair;
24
24
  import com.innov8tif.okaycam.config.OkayCamBtnConfig;
25
25
  import com.innov8tif.okaycam.config.OkayCamCaptureConfig;
26
- import com.innov8tif.okaycam.config.OkayCamConfig;
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;
26
+ import com.innov8tif.okaycam.config.OkayCamAutoCaptureConfig;
33
27
  import com.innov8tif.okaycam.config.OkaySelfieConfig;
34
28
  import com.innov8tif.okaycam.config.OkaySelfieLabelConfig;
35
29
  import com.innov8tif.okaycam.config.OkaySelfieSwichBtnConfig;
36
30
  import com.innov8tif.okaycam.selfie.OkayCamSelfie;
37
31
  import com.innov8tif.okaycam.utils.BitmapUtils;
32
+ import com.innov8tif.okaycam.config.OkayCamAutoCaptureMode;
38
33
 
39
34
  import org.json.JSONException;
40
35
  import org.json.JSONObject;
@@ -65,85 +60,32 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
65
60
  String LICENSE_KEY = configs.getString("license");
66
61
 
67
62
  Boolean base64 = configs.getBoolean("base64");
68
-
69
63
  ReadableMap userConfig = configs.getMap("config");
70
- ReadableMap topLabel = userConfig.getMap("topLabel");
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");
64
+ OkayCamAutoCaptureConfig config = OkayCamAutoCaptureConfig.init();
81
65
 
82
- OkayCamConfig okayCamConfig = OkayCamConfig.init(this.getCurrentActivity());
66
+ Log.d("OkayCam", "userConfig: " + userConfig.toString());
83
67
 
84
- okayCamConfig.setShowOverlay(userConfig.getBoolean("showOverlay"));
85
- okayCamConfig.setShowPreviewInstruction(userConfig.getBoolean("showPreviewInstruction"));
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"));
68
+ if (userConfig.hasKey("width") && !userConfig.isNull("width")) {
69
+ int width = userConfig.getInt("width");
70
+ if (width != -1) {
71
+ config.setWidth(width);
72
+ }
91
73
  }
92
74
 
93
- okayCamConfig.setImageQuality((float) userConfig.getDouble("imageQuality"));
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
- ));
75
+ if (userConfig.hasKey("imageQuality") && !userConfig.isNull("imageQuality")) {
76
+ double quality = userConfig.getDouble("imageQuality");
77
+ if (quality > 0.0) {
78
+ config.setImageQuality((float) quality);
79
+ }
80
+ }
140
81
 
141
- okayCamConfig.setPreview(getPreviewConfig(preview, frameConfig));
142
- okayCamConfig.setInstruction(getInstructionConfig(instruction, frameConfig));
143
- okayCamConfig.setAutoCapture(userConfig.getBoolean("autoCapture"));
82
+ if (userConfig.hasKey("autoCapture") && !userConfig.isNull("autoCapture")) {
83
+ config.setAutoCapture(userConfig.getBoolean("autoCapture"));
84
+ }
144
85
 
145
- OkayCamDoc.start(this.getCurrentActivity(), LICENSE_KEY, okayCamConfig, (success, images, exception) -> {
86
+ config.setMode(parseMode(userConfig.getString("mode")));
146
87
 
88
+ OkayCamAutoDoc.start(this.getCurrentActivity(), LICENSE_KEY, config, (success, images, exception) -> {
147
89
  if (success) {
148
90
  JSONObject results = new JSONObject();
149
91
  try {
@@ -173,290 +115,6 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
173
115
  });
174
116
  }
175
117
 
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
118
  @ReactMethod
461
119
  public void captureSelfie(ReadableMap configs, Promise promise) {
462
120
  String LICENSE_KEY = configs.getString("license");
@@ -508,15 +166,12 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
508
166
  okaySelfieConfig.setImageQuality((float) userConfig.getDouble("imageQuality"));
509
167
 
510
168
  OkayCamSelfie.start(this.getCurrentActivity(), LICENSE_KEY, okaySelfieConfig, (success, image, exception) -> {
511
-
512
169
  if (success) {
513
-
514
170
  JSONObject results = new JSONObject();
515
171
  try {
516
172
  results.put("selfieImage", convertImgToBase64(base64, image));
517
173
  promise.resolve(results.toString());
518
174
  } catch (JSONException e) {
519
- // TODO Auto-generated catch block
520
175
  e.printStackTrace();
521
176
  promise.reject(this.getError(e.getMessage()));
522
177
  }
@@ -554,4 +209,19 @@ public class RNOkayCamModule extends ReactContextBaseJavaModule {
554
209
  }
555
210
  return new Exception(errorString);
556
211
  }
212
+
213
+ private OkayCamAutoCaptureMode parseMode(String mode) {
214
+ if (mode == null) return OkayCamAutoCaptureMode.FULL;
215
+
216
+ switch (mode) {
217
+ case "FRONT_ONLY":
218
+ return OkayCamAutoCaptureMode.FRONT_ONLY;
219
+ case "FRONT_BACK":
220
+ return OkayCamAutoCaptureMode.FRONT_BACK;
221
+ case "FRONT_WITH_FLASH":
222
+ return OkayCamAutoCaptureMode.FRONT_WITH_FLASH;
223
+ default:
224
+ return OkayCamAutoCaptureMode.FULL;
225
+ }
226
+ }
557
227
  }
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
- const screenWidth = Dimensions.get("screen").width;
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,55 +15,14 @@ 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
- show: Boolean;
25
+ show: boolean;
69
26
  }
70
27
 
71
28
  type cameraFacingType = "front" | "back";
@@ -81,154 +38,45 @@ 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
- base64: Boolean,
152
- {
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,
49
+ base64: boolean,
50
+ config: {
51
+ width?: number;
52
+ imageQuality?: number;
53
+ mode?: string;
54
+ autoCapture?: boolean;
55
+ } = {},
56
+ ) => {
57
+ const {
165
58
  width = imageResizedWidth,
166
59
  imageQuality = 1.0,
167
- preview = defaultPreview,
168
- instruction = defaultInstruction,
169
- showPreviewInstruction = false,
60
+ mode = DocumentCaptureMode.FULL,
170
61
  autoCapture = true,
171
- }
172
- ) => {
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
-
62
+ } = config;
185
63
  return new Promise(function (resolve, reject) {
64
+ console.log(`autoCapture: ${autoCapture}`);
65
+ console.log(`mode: ${mode}`);
186
66
  RNOkayCam.captureDocument({
187
67
  license: license,
188
68
  base64: base64,
189
69
  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
70
  width: width,
221
71
  imageQuality: imageQuality,
222
- preview: resultedPreview,
223
- instruction: formatInstruction(instruction),
224
- showPreviewInstruction: showPreviewInstruction,
72
+ mode: mode,
225
73
  autoCapture: autoCapture,
226
74
  },
227
75
  })
228
- .then((result) => {
76
+ .then((result: string) => {
229
77
  resolve(JSON.parse(result));
230
78
  })
231
- .catch((error) => {
79
+ .catch((error: any) => {
232
80
  reject(error);
233
81
  });
234
82
  });
@@ -244,7 +92,7 @@ const cameraFacing: cameraFacingType = "front";
244
92
  // call native capture selfie
245
93
  export const captureSelfie = (
246
94
  license: string,
247
- base64: Boolean,
95
+ base64: boolean,
248
96
  {
249
97
  topLabel = labelConfig,
250
98
  bottomFrameColor = defaultColor2,
@@ -255,7 +103,7 @@ export const captureSelfie = (
255
103
  defaultCameraFacing = cameraFacing,
256
104
  width = imageResizedWidth,
257
105
  imageQuality = 1.0,
258
- }
106
+ },
259
107
  ) => {
260
108
  return new Promise(function (resolve, reject) {
261
109
  RNOkayCam.captureSelfie({
@@ -273,10 +121,10 @@ export const captureSelfie = (
273
121
  imageQuality: imageQuality,
274
122
  },
275
123
  })
276
- .then((result) => {
124
+ .then((result: string) => {
277
125
  resolve(JSON.parse(result));
278
126
  })
279
- .catch((error) => {
127
+ .catch((error: any) => {
280
128
  reject(error);
281
129
  });
282
130
  });
@@ -15,233 +15,90 @@ class RNOkayCam: NSObject {
15
15
  var promiseResolve: RCTPromiseResolveBlock?
16
16
  var promiseReject: RCTPromiseRejectBlock?
17
17
 
18
- @objc func captureDocument(_ configs: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
19
-
20
- let license = configs.object(forKey: "license")! as! String
21
- let base64 = configs.object(forKey: "base64") as! Bool
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
-
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
- let width = rnOkayCamConfig.object(forKey: "width") as! Int
46
- let imageQuality = rnOkayCamConfig.object(forKey: "imageQuality") as! CGFloat
47
- let autoCapture = rnOkayCamConfig.object(forKey: "autoCapture") as! Bool
48
-
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
+
49
37
  DispatchQueue.main.async {
50
- let rootViewController = (UIApplication.shared.keyWindow?.rootViewController)!
51
-
52
- let okayCamConfig = OkayCamConfig(viewController: rootViewController)
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)
38
+ guard let rootViewController = UIApplication.shared.windows.first?.rootViewController else {
39
+ reject("no_root_view_controller", "Root view controller not found", nil)
40
+ return
41
+ }
58
42
 
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
43
+ let config = OkayCamAutoCaptureConfig(viewController: rootViewController)
63
44
 
64
- // frame size
65
- if (frameSize != nil) {
66
- okayCamConfig.frame.size = CGSize(width: frameWidth!, height: frameHeight!)
45
+ // width
46
+ if let width = width, width != -1 {
47
+ config.width = width
67
48
  }
68
49
 
69
- // frame color
70
- okayCamConfig.frame.color = self.hexStringToUIColor(hex: frameColor)
50
+ // image quality
51
+ if let imageQuality = imageQuality, imageQuality > 0.0 {
52
+ config.imageQuality = imageQuality
53
+ }
71
54
 
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
55
+ // FIX: allow false
56
+ if let autoCapture = autoCapture {
57
+ config.autoCapture = autoCapture
79
58
  }
80
-
81
- okayCamConfig.showOverlay = showOverlay
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
59
 
87
- // capture button color
88
- okayCamConfig.captureBtnColor = self.hexStringToUIColor(hex: captureBtnColor)
60
+ config.mode = self.parseMode(mode)
89
61
 
90
- // show torch button
91
- okayCamConfig.torchBtnEnabled = torchBtnEnabled
92
-
93
- // set image quality
94
- okayCamConfig.imageQuality = imageQuality
62
+ OkayCamDocAutoCapture.start(
63
+ okayCamConfig: config,
64
+ license: license
65
+ ) { filePaths, error in
95
66
 
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)
67
+ if let error = error {
68
+ self.handleError(error, rejecter: reject)
69
+ return
70
+ }
99
71
 
100
- // retake button config
101
- okayCamConfig.retakeBtnConfig.backgroundColor = self.hexStringToUIColor(hex: retakeBtnConfig.object(forKey: "backgroundColor") as! String)
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
124
- }
125
-
126
- // preview config
127
-
128
- let previewConfig = rnOkayCamConfig.object(forKey: "preview") as? NSDictionary
129
-
130
- okayCamConfig.preview = self.getOkaycamPreview(previewConfig: previewConfig)
72
+ guard let urls = filePaths else {
73
+ reject("no_result", "No images returned", nil)
74
+ return
75
+ }
131
76
 
132
- // instruction config
133
- let instructionConfig = rnOkayCamConfig.object(forKey: "instruction") as? NSDictionary
134
- okayCamConfig.instruction = self.getOkayCamInstruction(instructionConfig: instructionConfig)
135
-
136
- okayCamConfig.autoCapture = autoCapture
77
+ do {
78
+ let result: NSMutableDictionary = [:]
137
79
 
138
- // start the SDK
139
- OkayCamDoc.start(
140
- okayCamConfig: okayCamConfig,
141
- license: license,
142
- { filePaths, error in
143
- // handle error
144
- do {
145
- if let failed = error {
146
- print(failed)
147
- self.handleError(failed, rejecter: reject)
148
- }
149
-
150
- // handle success
151
- if let urls = filePaths {
152
- let okayCamObject:NSMutableDictionary = NSMutableDictionary()
153
-
154
- okayCamObject.setValue(self.convertImgToBase64(base64: base64, image: urls[0]), forKey: "fullDocumentImage")
155
-
156
- if (filePaths!.count > 1) {
157
- okayCamObject.setValue(self.convertImgToBase64(base64: base64, image: urls[1]), forKey: "fullDocumentImage2")
158
- }
80
+ result["fullDocumentImage"] = self.convertImgToBase64(base64: base64, image: urls[0])
159
81
 
160
- if (filePaths!.count > 2) {
161
- okayCamObject.setValue(self.convertImgToBase64(base64: base64, image: urls[2]), forKey: "fullDocumentImage3")
162
- }
163
-
164
- if (filePaths!.count > 3) {
165
- okayCamObject.setValue(self.convertImgToBase64(base64: base64, image: urls[3]), forKey: "fullDocumentImage4")
166
- }
167
-
168
- let jsonData = try JSONSerialization.data(withJSONObject: okayCamObject, options: .prettyPrinted)
169
- let jsonString = String(data: jsonData, encoding: String.Encoding.ascii)!
170
-
171
- resolve(jsonString)
172
- }
82
+ if urls.count > 1 {
83
+ result["fullDocumentImage2"] = self.convertImgToBase64(base64: base64, image: urls[1])
173
84
  }
174
- catch {
175
- print("Error:", error)
85
+ if urls.count > 2 {
86
+ result["fullDocumentImage3"] = self.convertImgToBase64(base64: base64, image: urls[2])
87
+ }
88
+ if urls.count > 3 {
89
+ result["fullDocumentImage4"] = self.convertImgToBase64(base64: base64, image: urls[3])
176
90
  }
177
- }
178
- )
179
- }
180
- }
181
-
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
91
 
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
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)
99
+ }
100
+ }
236
101
  }
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
102
  }
246
103
 
247
104
  @objc func captureSelfie(_ configs: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
@@ -260,8 +117,11 @@ class RNOkayCam: NSObject {
260
117
  let imageQuality = rnOkayCamConfig.object(forKey: "imageQuality") as! CGFloat
261
118
 
262
119
  DispatchQueue.main.async {
263
- let rootViewController = (UIApplication.shared.keyWindow?.rootViewController)!
264
-
120
+ guard let rootViewController = UIApplication.shared.windows.first?.rootViewController else {
121
+ reject("no_root_view_controller", "Root view controller not found", nil)
122
+ return
123
+ }
124
+
265
125
  let okaySelfieConfig = OkaySelfieConfig(viewController: rootViewController)
266
126
 
267
127
  // top label
@@ -403,5 +263,26 @@ class RNOkayCam: NSObject {
403
263
  reject("no error", "no error", nil)
404
264
  return
405
265
  }
266
+
267
+ }
268
+
269
+ func parseMode(_ mode: String?) -> OkayCamAutoCaptureMode {
270
+ guard let mode = mode else {
271
+ return .full
272
+ }
273
+
274
+ switch mode {
275
+ case "FRONT_ONLY":
276
+ return .frontOnly
277
+
278
+ case "FRONT_BACK":
279
+ return .frontBack
280
+
281
+ case "FRONT_WITH_FLASH":
282
+ return .frontWithFlash
283
+
284
+ default:
285
+ return .full
286
+ }
406
287
  }
407
288
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-okaycam",
3
3
  "title": "React Native OkayCam",
4
- "version": "3.0.3",
4
+ "version": "3.0.5",
5
5
  "description": "React-Native version of OkayCam",
6
6
  "main": "index.ts",
7
7
  "files": [
@@ -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.12"
29
+ s.dependency "OkayCam", "3.0.16"
30
30
  s.dependency "CryptoSwift", "1.8.2"
31
31
 
32
32
  s.pod_target_xcconfig = {