@connectedbits/react-native-image-picker 2.4.16-rc1 → 2.4.16-rc3

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.
File without changes
@@ -0,0 +1,2 @@
1
+ #Fri Dec 15 08:26:19 EST 2023
2
+ gradle.version=5.4.1
File without changes
@@ -0,0 +1,3 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="CompilerConfiguration">
4
+ <bytecodeTargetLevel target="1.8" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="GradleMigrationSettings" migrationVersion="1" />
4
+ <component name="GradleSettings">
5
+ <option name="linkedExternalProjectsSettings">
6
+ <GradleProjectSettings>
7
+ <option name="testRunner" value="GRADLE" />
8
+ <option name="distributionType" value="DEFAULT_WRAPPED" />
9
+ <option name="externalProjectPath" value="$PROJECT_DIR$" />
10
+ <option name="modules">
11
+ <set>
12
+ <option value="$PROJECT_DIR$" />
13
+ </set>
14
+ </option>
15
+ </GradleProjectSettings>
16
+ </option>
17
+ </component>
18
+ </project>
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="RemoteRepositoriesConfiguration">
4
+ <remote-repository>
5
+ <option name="id" value="central" />
6
+ <option name="name" value="Maven Central repository" />
7
+ <option name="url" value="https://repo1.maven.org/maven2" />
8
+ </remote-repository>
9
+ <remote-repository>
10
+ <option name="id" value="jboss.community" />
11
+ <option name="name" value="JBoss Community repository" />
12
+ <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
13
+ </remote-repository>
14
+ <remote-repository>
15
+ <option name="id" value="maven" />
16
+ <option name="name" value="maven" />
17
+ <option name="url" value="file:$PROJECT_DIR$/../node_modules/react-native/android/" />
18
+ </remote-repository>
19
+ <remote-repository>
20
+ <option name="id" value="maven2" />
21
+ <option name="name" value="maven2" />
22
+ <option name="url" value="file:$PROJECT_DIR$/../node_modules/jsc-android/dist/" />
23
+ </remote-repository>
24
+ <remote-repository>
25
+ <option name="id" value="MavenLocal" />
26
+ <option name="name" value="MavenLocal" />
27
+ <option name="url" value="file:$USER_HOME$/.m2/repository/" />
28
+ </remote-repository>
29
+ <remote-repository>
30
+ <option name="id" value="BintrayJCenter" />
31
+ <option name="name" value="BintrayJCenter" />
32
+ <option name="url" value="https://jcenter.bintray.com/" />
33
+ </remote-repository>
34
+ <remote-repository>
35
+ <option name="id" value="Google" />
36
+ <option name="name" value="Google" />
37
+ <option name="url" value="https://dl.google.com/dl/android/maven2/" />
38
+ </remote-repository>
39
+ </component>
40
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="KtfmtSettings">
4
+ <option name="enabled" value="false" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,9 @@
1
+ <project version="4">
2
+ <component name="ExternalStorageConfigurationManager" enabled="true" />
3
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="zulu-1.8" project-jdk-type="JavaSDK">
4
+ <output url="file://$PROJECT_DIR$/build/classes" />
5
+ </component>
6
+ <component name="ProjectType">
7
+ <option name="id" value="Android" />
8
+ </component>
9
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
+ </component>
6
+ </project>
@@ -11,6 +11,7 @@ import android.graphics.Bitmap;
11
11
  import android.graphics.BitmapFactory;
12
12
  import android.net.Uri;
13
13
  import android.os.Build;
14
+ import android.os.Handler;
14
15
  import android.provider.MediaStore;
15
16
  import android.provider.Settings;
16
17
  import androidx.annotation.NonNull;
@@ -151,62 +152,67 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
151
152
 
152
153
  @ReactMethod
153
154
  public void showImagePicker(final ReadableMap options, final Callback callback) {
154
- Activity currentActivity = getCurrentActivity();
155
-
155
+ final ImagePickerModule self = this;
156
+ final Activity currentActivity = getCurrentActivity();
157
+ Handler handler = new Handler(this.reactContext.getMainLooper());
158
+ this.callback = callback;
159
+ this.options = options;
156
160
  if (currentActivity == null)
157
161
  {
158
162
  responseHelper.invokeError(callback, "can't find current Activity");
159
163
  return;
160
164
  }
161
-
162
- this.callback = callback;
163
- this.options = options;
164
165
  imageConfig = new ImageConfig(0, 0, 100, 0, false);
165
-
166
- final AlertDialog dialog = UI.chooseDialog(this, options, new UI.OnAction()
167
- {
166
+ handler.post(new Runnable() {
168
167
  @Override
169
- public void onTakePhoto(@NonNull final ImagePickerModule module)
170
- {
171
- if (module == null)
172
- {
173
- return;
174
- }
175
- module.launchCamera();
176
- }
168
+ public void run() {
177
169
 
178
- @Override
179
- public void onUseLibrary(@NonNull final ImagePickerModule module)
180
- {
181
- if (module == null)
170
+ final AlertDialog dialog = UI.chooseDialog(self, options, new UI.OnAction()
182
171
  {
183
- return;
184
- }
185
- module.launchImageLibrary();
186
- }
172
+ @Override
173
+ public void onTakePhoto(@NonNull final ImagePickerModule module)
174
+ {
175
+ if (module == null)
176
+ {
177
+ return;
178
+ }
179
+ module.launchCamera();
180
+ }
187
181
 
188
- @Override
189
- public void onCancel(@NonNull final ImagePickerModule module)
190
- {
191
- if (module == null)
192
- {
193
- return;
194
- }
195
- module.doOnCancel();
196
- }
182
+ @Override
183
+ public void onUseLibrary(@NonNull final ImagePickerModule module)
184
+ {
185
+ if (module == null)
186
+ {
187
+ return;
188
+ }
189
+ module.launchImageLibrary();
190
+ }
197
191
 
198
- @Override
199
- public void onCustomButton(@NonNull final ImagePickerModule module,
200
- @NonNull final String action)
201
- {
202
- if (module == null)
203
- {
204
- return;
205
- }
206
- module.invokeCustomButton(action);
192
+ @Override
193
+ public void onCancel(@NonNull final ImagePickerModule module)
194
+ {
195
+ if (module == null)
196
+ {
197
+ return;
198
+ }
199
+ module.doOnCancel();
200
+ }
201
+
202
+ @Override
203
+ public void onCustomButton(@NonNull final ImagePickerModule module,
204
+ @NonNull final String action)
205
+ {
206
+ if (module == null)
207
+ {
208
+ return;
209
+ }
210
+ module.invokeCustomButton(action);
211
+ }
212
+ });
213
+ dialog.show();
207
214
  }
208
215
  });
209
- dialog.show();
210
216
  }
211
217
 
212
218
  public void doOnCancel()
@@ -226,6 +232,8 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
226
232
  @ReactMethod
227
233
  public void launchCamera(final ReadableMap options, final Callback callback)
228
234
  {
235
+ final ImagePickerModule self = this;
236
+ Handler handler = new Handler(this.getContext().getMainLooper());
229
237
  permissionRequestCallback = callback;
230
238
 
231
239
  if (!isCameraAvailable())
@@ -244,67 +252,72 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
244
252
  this.callback = callback;
245
253
  this.options = options;
246
254
 
247
- if (!permissionsCheck(currentActivity, callback, REQUEST_PERMISSIONS_FOR_CAMERA))
248
- {
249
- return;
250
- }
251
-
252
- parseOptions(this.options);
253
-
254
- int requestCode;
255
- Intent cameraIntent;
256
-
257
- if (pickVideo)
258
- {
259
- requestCode = REQUEST_LAUNCH_VIDEO_CAPTURE;
260
- cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
261
- cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, videoQuality);
262
- if (videoDurationLimit > 0)
263
- {
264
- cameraIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, videoDurationLimit);
265
- }
266
- }
267
- else
268
- {
269
- requestCode = REQUEST_LAUNCH_IMAGE_CAPTURE;
270
- cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
271
-
272
- final File original = createNewFile(reactContext, this.options, false);
273
-
274
- if (original != null) {
275
- cameraCaptureURI = RealPathUtil.compatUriFromFile(reactContext, original);
276
- }else {
277
- responseHelper.invokeError(callback, "Couldn't get file path for photo");
278
- return;
279
- }
280
- if (cameraCaptureURI == null)
281
- {
282
- responseHelper.invokeError(callback, "Couldn't get file path for photo");
283
- return;
284
- }
285
- cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraCaptureURI);
286
- }
287
-
288
- // Workaround for Android bug.
289
- // grantUriPermission also needed for KITKAT,
290
- // see https://code.google.com/p/android/issues/detail?id=76683
291
- if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
292
- List<ResolveInfo> resInfoList = reactContext.getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
293
- for (ResolveInfo resolveInfo : resInfoList) {
294
- String packageName = resolveInfo.activityInfo.packageName;
295
- reactContext.grantUriPermission(packageName, cameraCaptureURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
296
- }
297
- }
298
-
299
- try
300
- {
301
- currentActivity.startActivityForResult(cameraIntent, requestCode);
302
- }
303
- catch (ActivityNotFoundException e)
304
- {
305
- e.printStackTrace();
306
- responseHelper.invokeError(callback, "Cannot launch camera, unable to start");
307
- }
255
+ handler.post(new Runnable() {
256
+ @Override
257
+ public void run() {
258
+ if (!permissionsCheck(currentActivity, callback, REQUEST_PERMISSIONS_FOR_CAMERA))
259
+ {
260
+ return;
261
+ }
262
+
263
+ parseOptions(options);
264
+
265
+ int requestCode;
266
+ Intent cameraIntent;
267
+
268
+ if (pickVideo)
269
+ {
270
+ requestCode = REQUEST_LAUNCH_VIDEO_CAPTURE;
271
+ cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
272
+ cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, videoQuality);
273
+ if (videoDurationLimit > 0)
274
+ {
275
+ cameraIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, videoDurationLimit);
276
+ }
277
+ }
278
+ else
279
+ {
280
+ requestCode = REQUEST_LAUNCH_IMAGE_CAPTURE;
281
+ cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
282
+
283
+ final File original = createNewFile(self.getContext(), options, false);
284
+
285
+ if (original != null) {
286
+ cameraCaptureURI = RealPathUtil.compatUriFromFile(self.getContext(), original);
287
+ }else {
288
+ responseHelper.invokeError(callback, "Couldn't get file path for photo");
289
+ return;
290
+ }
291
+ if (cameraCaptureURI == null)
292
+ {
293
+ responseHelper.invokeError(callback, "Couldn't get file path for photo");
294
+ return;
295
+ }
296
+ cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraCaptureURI);
297
+ }
298
+
299
+ // Workaround for Android bug.
300
+ // grantUriPermission also needed for KITKAT,
301
+ // see https://code.google.com/p/android/issues/detail?id=76683
302
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
303
+ List<ResolveInfo> resInfoList = self.getContext().getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
304
+ for (ResolveInfo resolveInfo : resInfoList) {
305
+ String packageName = resolveInfo.activityInfo.packageName;
306
+ self.getContext().grantUriPermission(packageName, cameraCaptureURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
307
+ }
308
+ }
309
+
310
+ try
311
+ {
312
+ currentActivity.startActivityForResult(cameraIntent, requestCode);
313
+ }
314
+ catch (ActivityNotFoundException e)
315
+ {
316
+ e.printStackTrace();
317
+ responseHelper.invokeError(callback, "Cannot launch camera, unable to start");
318
+ }
319
+ }
320
+ });
308
321
  }
309
322
 
310
323
  public void launchImageLibrary()
@@ -326,197 +339,209 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
326
339
  this.callback = callback;
327
340
  this.options = options;
328
341
 
329
- if (!permissionsCheck(currentActivity, callback, REQUEST_PERMISSIONS_FOR_LIBRARY))
330
- {
331
- return;
332
- }
342
+ Handler handler = new Handler(this.getContext().getMainLooper());
343
+ handler.post(new Runnable() {
344
+ @Override
345
+ public void run(){
346
+ if (!permissionsCheck(currentActivity, callback, REQUEST_PERMISSIONS_FOR_LIBRARY))
347
+ {
348
+ return;
349
+ }
333
350
 
334
- parseOptions(this.options);
351
+ parseOptions(options);
335
352
 
336
- int requestCode;
337
- Intent libraryIntent;
338
- if (pickVideo)
339
- {
340
- requestCode = REQUEST_LAUNCH_VIDEO_LIBRARY;
341
- libraryIntent = new Intent(Intent.ACTION_GET_CONTENT);
342
- libraryIntent.setType("video/*");
343
- libraryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
344
- libraryIntent.putExtra(Intent.CATEGORY_OPENABLE, true);
345
- }
346
- else
347
- {
348
- requestCode = REQUEST_LAUNCH_IMAGE_LIBRARY;
349
- libraryIntent = new Intent(Intent.ACTION_GET_CONTENT);
350
- libraryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
351
- libraryIntent.putExtra(Intent.CATEGORY_OPENABLE, true);
353
+ int requestCode;
354
+ Intent libraryIntent;
355
+ if (pickVideo)
356
+ {
357
+ requestCode = REQUEST_LAUNCH_VIDEO_LIBRARY;
358
+ libraryIntent = new Intent(Intent.ACTION_GET_CONTENT);
359
+ libraryIntent.setType("video/*");
360
+ libraryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
361
+ libraryIntent.putExtra(Intent.CATEGORY_OPENABLE, true);
362
+ }
363
+ else
364
+ {
365
+ requestCode = REQUEST_LAUNCH_IMAGE_LIBRARY;
366
+ libraryIntent = new Intent(Intent.ACTION_GET_CONTENT);
367
+ libraryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
368
+ libraryIntent.putExtra(Intent.CATEGORY_OPENABLE, true);
369
+
370
+ if (pickBoth)
371
+ {
372
+ libraryIntent.setType("image/* video/*");
373
+ } else {
374
+ libraryIntent.setType("image/*");
375
+ }
376
+ }
352
377
 
353
- if (pickBoth)
354
- {
355
- libraryIntent.setType("image/* video/*");
356
- } else {
357
- libraryIntent.setType("image/*");
358
- }
359
- }
378
+ try
379
+ {
380
+ String chooseWhichLibraryTitle = null;
381
+ if (ReadableMapUtils.hasAndNotEmptyString(options, "chooseWhichLibraryTitle"))
382
+ {
383
+ chooseWhichLibraryTitle = options.getString("chooseWhichLibraryTitle");
384
+ }
360
385
 
361
- try
362
- {
363
- String chooseWhichLibraryTitle = null;
364
- if (ReadableMapUtils.hasAndNotEmptyString(options, "chooseWhichLibraryTitle"))
365
- {
366
- chooseWhichLibraryTitle = options.getString("chooseWhichLibraryTitle");
386
+ currentActivity.startActivityForResult(Intent.createChooser(libraryIntent, chooseWhichLibraryTitle), requestCode);
387
+ }
388
+ catch (ActivityNotFoundException e)
389
+ {
390
+ e.printStackTrace();
391
+ responseHelper.invokeError(callback, "Cannot launch photo library");
392
+ }
367
393
  }
368
-
369
- currentActivity.startActivityForResult(Intent.createChooser(libraryIntent, chooseWhichLibraryTitle), requestCode);
370
- }
371
- catch (ActivityNotFoundException e)
372
- {
373
- e.printStackTrace();
374
- responseHelper.invokeError(callback, "Cannot launch photo library");
375
- }
394
+ });
376
395
  }
377
396
 
378
397
  @Override
379
- public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
380
- //robustness code
381
- if (passResult(requestCode))
382
- {
383
- return;
384
- }
398
+ public void onActivityResult(Activity activity, final int requestCode, final int resultCode, final Intent data) {
399
+ final ImagePickerModule self = this;
400
+ Handler handler = new Handler(this.getContext().getMainLooper());
401
+ handler.post(new Runnable() {
402
+ @Override
403
+ public void run() {
404
+ if (self.passResult(requestCode))
405
+ {
406
+ return;
407
+ }
385
408
 
386
- responseHelper.cleanResponse();
409
+ responseHelper.cleanResponse();
387
410
 
388
- // user cancel
389
- if (resultCode != Activity.RESULT_OK)
390
- {
391
- responseHelper.invokeCancel(callback);
392
- callback = null;
393
- return;
394
- }
411
+ // user cancel
412
+ if (resultCode != Activity.RESULT_OK)
413
+ {
414
+ responseHelper.invokeCancel(callback);
415
+ callback = null;
416
+ return;
417
+ }
395
418
 
396
- Uri uri = null;
397
- switch (requestCode)
398
- {
399
- case REQUEST_LAUNCH_IMAGE_CAPTURE:
400
- uri = cameraCaptureURI;
401
- break;
419
+ Uri uri = null;
420
+ switch (requestCode)
421
+ {
422
+ case REQUEST_LAUNCH_IMAGE_CAPTURE:
423
+ uri = cameraCaptureURI;
424
+ break;
425
+
426
+ case REQUEST_LAUNCH_IMAGE_LIBRARY:
427
+ uri = data.getData();
428
+ if(uri == null){
429
+ responseHelper.putString("error", "Could not read photo");
430
+ responseHelper.invokeResponse(callback);
431
+ callback = null;
432
+ return;
433
+ }
434
+ break;
402
435
 
403
- case REQUEST_LAUNCH_IMAGE_LIBRARY:
404
- uri = data.getData();
405
- if(uri == null){
406
- responseHelper.putString("error", "Could not read photo");
436
+ case REQUEST_LAUNCH_VIDEO_LIBRARY:
437
+ responseHelper.putString("uri", data.getData().toString());
407
438
  responseHelper.invokeResponse(callback);
408
439
  callback = null;
409
440
  return;
410
- }
411
- break;
412
441
 
413
- case REQUEST_LAUNCH_VIDEO_LIBRARY:
414
- responseHelper.putString("uri", data.getData().toString());
415
- responseHelper.invokeResponse(callback);
416
- callback = null;
417
- return;
418
-
419
- case REQUEST_LAUNCH_VIDEO_CAPTURE:
420
- responseHelper.putString("uri", data.getData().toString());
421
- responseHelper.invokeResponse(callback);
422
- callback = null;
423
- return;
424
- }
442
+ case REQUEST_LAUNCH_VIDEO_CAPTURE:
443
+ responseHelper.putString("uri", data.getData().toString());
444
+ responseHelper.invokeResponse(callback);
445
+ callback = null;
446
+ return;
447
+ }
425
448
 
426
- ReadExifResult result = null;
427
- try {
428
- InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
429
- if(imageInputStream != null){
430
- result = readExifInterface(imageInputStream, responseHelper);
431
- }
432
- } catch(IOException ex){
433
- responseHelper.invokeError(callback, ex.getMessage());
434
- callback = null;
435
- return;
436
- }
437
- if (result == null) {
438
- responseHelper.invokeError(callback, "Image could not be read");
439
- callback = null;
440
- return;
441
- }
442
- if (result.error != null)
443
- {
444
- responseHelper.invokeError(callback, result.error.getMessage());
445
- callback = null;
446
- return;
447
- }
449
+ ReadExifResult result = null;
450
+ try {
451
+ InputStream imageInputStream = self.getContext().getContentResolver().openInputStream(uri);
452
+ if(imageInputStream != null){
453
+ result = readExifInterface(imageInputStream, responseHelper);
454
+ }
455
+ } catch(IOException ex){
456
+ responseHelper.invokeError(callback, ex.getMessage());
457
+ callback = null;
458
+ return;
459
+ }
460
+ if (result == null) {
461
+ responseHelper.invokeError(callback, "Image could not be read");
462
+ callback = null;
463
+ return;
464
+ }
465
+ if (result.error != null)
466
+ {
467
+ responseHelper.invokeError(callback, result.error.getMessage());
468
+ callback = null;
469
+ return;
470
+ }
448
471
 
449
- BitmapFactory.Options options = new BitmapFactory.Options();
450
- options.inJustDecodeBounds = true;
451
- Bitmap imageBitmap = null;
452
- try {
453
- InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
454
- imageBitmap = BitmapFactory.decodeStream(imageInputStream, null, options);
455
- } catch(FileNotFoundException ex){
456
- responseHelper.invokeError(callback, "Could not find file");
457
- callback = null;
458
- return;
459
- }
472
+ BitmapFactory.Options options = new BitmapFactory.Options();
473
+ options.inJustDecodeBounds = true;
474
+ Bitmap imageBitmap = null;
475
+ try {
476
+ InputStream imageInputStream = self.getContext().getContentResolver().openInputStream(uri);
477
+ imageBitmap = BitmapFactory.decodeStream(imageInputStream, null, options);
478
+ } catch(FileNotFoundException ex){
479
+ responseHelper.invokeError(callback, "Could not find file");
480
+ callback = null;
481
+ return;
482
+ }
460
483
 
461
484
 
462
- int initialWidth = options.outWidth;
463
- int initialHeight = options.outHeight;
485
+ int initialWidth = options.outWidth;
486
+ int initialHeight = options.outHeight;
464
487
 
465
488
 
466
- // don't create a new file if contraint are respected
467
- if (imageConfig.useOriginal(initialWidth, initialHeight, result.currentRotation))
468
- {
469
- responseHelper.putInt("width", initialWidth);
470
- responseHelper.putInt("height", initialHeight);
471
-
472
- try {
473
- InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
474
- updatedResultResponse(imageInputStream);
475
- } catch(FileNotFoundException ex){
476
- responseHelper.invokeError(callback, "Could not find file");
477
- callback = null;
478
- return;
479
- }
480
- }
481
- else
482
- {
483
- Bitmap resizedImage = null;
484
- ImageConfig rotatedImageConfig = imageConfig.withRotation(result.currentRotation);
485
- try {
486
- InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
487
- resizedImage = getResizedImage(imageInputStream, rotatedImageConfig, initialWidth, initialHeight);
488
- } catch(FileNotFoundException ex){
489
- responseHelper.invokeError(callback, "Could not find file");
490
- callback = null;
491
- return;
492
- }
489
+ // don't create a new file if contraint are respected
490
+ if (imageConfig.useOriginal(initialWidth, initialHeight, result.currentRotation))
491
+ {
492
+ responseHelper.putInt("width", initialWidth);
493
+ responseHelper.putInt("height", initialHeight);
494
+
495
+ try {
496
+ InputStream imageInputStream = self.getContext().getContentResolver().openInputStream(uri);
497
+ updatedResultResponse(imageInputStream);
498
+ } catch(FileNotFoundException ex){
499
+ responseHelper.invokeError(callback, "Could not find file");
500
+ callback = null;
501
+ return;
502
+ }
503
+ }
504
+ else
505
+ {
506
+ Bitmap resizedImage = null;
507
+ ImageConfig rotatedImageConfig = imageConfig.withRotation(result.currentRotation);
508
+ try {
509
+ InputStream imageInputStream = self.getContext().getContentResolver().openInputStream(uri);
510
+ resizedImage = getResizedImage(imageInputStream, rotatedImageConfig, initialWidth, initialHeight);
511
+ } catch(FileNotFoundException ex){
512
+ responseHelper.invokeError(callback, "Could not find file");
513
+ callback = null;
514
+ return;
515
+ }
493
516
 
494
- if (resizedImage == null)
495
- {
496
- responseHelper.putString("error", "Can't resize the image");
497
- }
498
- else
499
- {
500
- responseHelper.putInt("width", resizedImage.getWidth());
501
- responseHelper.putInt("height", resizedImage.getHeight());
502
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
503
- resizedImage.compress(Bitmap.CompressFormat.JPEG, imageConfig.quality, bos);
504
- byte[] bitmapdata = bos.toByteArray();
505
- ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
506
- updatedResultResponse(bs);
507
- resizedImage.recycle();
508
- resizedImage = null;
509
- }
510
- }
511
- if(imageBitmap != null){
512
- imageBitmap.recycle();
513
- imageBitmap = null;
514
- }
517
+ if (resizedImage == null)
518
+ {
519
+ responseHelper.putString("error", "Can't resize the image");
520
+ }
521
+ else
522
+ {
523
+ responseHelper.putInt("width", resizedImage.getWidth());
524
+ responseHelper.putInt("height", resizedImage.getHeight());
525
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
526
+ resizedImage.compress(Bitmap.CompressFormat.JPEG, imageConfig.quality, bos);
527
+ byte[] bitmapdata = bos.toByteArray();
528
+ ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
529
+ updatedResultResponse(bs);
530
+ resizedImage.recycle();
531
+ resizedImage = null;
532
+ }
533
+ }
534
+ if(imageBitmap != null){
535
+ imageBitmap.recycle();
536
+ imageBitmap = null;
537
+ }
515
538
 
516
539
 
517
- responseHelper.invokeResponse(callback);
518
- callback = null;
519
- this.options = null;
540
+ responseHelper.invokeResponse(callback);
541
+ self.callback = null;
542
+ self.options = null;
543
+ }
544
+ });
520
545
  }
521
546
 
522
547
  public void invokeCustomButton(@NonNull final String action)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connectedbits/react-native-image-picker",
3
- "version": "2.4.16-rc1",
3
+ "version": "2.4.16-rc3",
4
4
  "description": "A React Native module that allows you to use native UI to select media from the device library or directly from the camera",
5
5
  "react-native": "src/index.ts",
6
6
  "types": "lib/typescript/index.d.ts",