@connectedbits/react-native-image-picker 2.4.16-rc2 → 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.
@@ -152,23 +152,22 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
152
152
 
153
153
  @ReactMethod
154
154
  public void showImagePicker(final ReadableMap options, final Callback callback) {
155
+ final ImagePickerModule self = this;
156
+ final Activity currentActivity = getCurrentActivity();
155
157
  Handler handler = new Handler(this.reactContext.getMainLooper());
158
+ this.callback = callback;
159
+ this.options = options;
160
+ if (currentActivity == null)
161
+ {
162
+ responseHelper.invokeError(callback, "can't find current Activity");
163
+ return;
164
+ }
165
+ imageConfig = new ImageConfig(0, 0, 100, 0, false);
156
166
  handler.post(new Runnable() {
157
167
  @Override
158
168
  public void run() {
159
- Activity currentActivity = getCurrentActivity();
160
-
161
- if (currentActivity == null)
162
- {
163
- responseHelper.invokeError(callback, "can't find current Activity");
164
- return;
165
- }
166
-
167
- this.callback = callback;
168
- this.options = options;
169
- imageConfig = new ImageConfig(0, 0, 100, 0, false);
170
169
 
171
- final AlertDialog dialog = UI.chooseDialog(this, options, new UI.OnAction()
170
+ final AlertDialog dialog = UI.chooseDialog(self, options, new UI.OnAction()
172
171
  {
173
172
  @Override
174
173
  public void onTakePhoto(@NonNull final ImagePickerModule module)
@@ -233,34 +232,35 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
233
232
  @ReactMethod
234
233
  public void launchCamera(final ReadableMap options, final Callback callback)
235
234
  {
236
- Handler handler = new Handler(this.reactContext.getMainLooper());
237
- handler.post(new Runnable() {
238
- @Override
239
- public void run() {
240
- permissionRequestCallback = callback;
235
+ final ImagePickerModule self = this;
236
+ Handler handler = new Handler(this.getContext().getMainLooper());
237
+ permissionRequestCallback = callback;
241
238
 
242
- if (!isCameraAvailable())
243
- {
244
- responseHelper.invokeError(callback, "Camera not available");
245
- return;
246
- }
239
+ if (!isCameraAvailable())
240
+ {
241
+ responseHelper.invokeError(callback, "Camera not available");
242
+ return;
243
+ }
247
244
 
248
- final Activity currentActivity = getCurrentActivity();
249
- if (currentActivity == null)
250
- {
251
- responseHelper.invokeError(callback, "can't find current Activity");
252
- return;
253
- }
245
+ final Activity currentActivity = getCurrentActivity();
246
+ if (currentActivity == null)
247
+ {
248
+ responseHelper.invokeError(callback, "can't find current Activity");
249
+ return;
250
+ }
254
251
 
255
- this.callback = callback;
256
- this.options = options;
252
+ this.callback = callback;
253
+ this.options = options;
257
254
 
255
+ handler.post(new Runnable() {
256
+ @Override
257
+ public void run() {
258
258
  if (!permissionsCheck(currentActivity, callback, REQUEST_PERMISSIONS_FOR_CAMERA))
259
259
  {
260
260
  return;
261
261
  }
262
262
 
263
- parseOptions(this.options);
263
+ parseOptions(options);
264
264
 
265
265
  int requestCode;
266
266
  Intent cameraIntent;
@@ -280,10 +280,10 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
280
280
  requestCode = REQUEST_LAUNCH_IMAGE_CAPTURE;
281
281
  cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
282
282
 
283
- final File original = createNewFile(reactContext, this.options, false);
283
+ final File original = createNewFile(self.getContext(), options, false);
284
284
 
285
285
  if (original != null) {
286
- cameraCaptureURI = RealPathUtil.compatUriFromFile(reactContext, original);
286
+ cameraCaptureURI = RealPathUtil.compatUriFromFile(self.getContext(), original);
287
287
  }else {
288
288
  responseHelper.invokeError(callback, "Couldn't get file path for photo");
289
289
  return;
@@ -300,10 +300,10 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
300
300
  // grantUriPermission also needed for KITKAT,
301
301
  // see https://code.google.com/p/android/issues/detail?id=76683
302
302
  if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
303
- List<ResolveInfo> resInfoList = reactContext.getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
303
+ List<ResolveInfo> resInfoList = self.getContext().getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
304
304
  for (ResolveInfo resolveInfo : resInfoList) {
305
305
  String packageName = resolveInfo.activityInfo.packageName;
306
- reactContext.grantUriPermission(packageName, cameraCaptureURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
306
+ self.getContext().grantUriPermission(packageName, cameraCaptureURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
307
307
  }
308
308
  }
309
309
 
@@ -328,27 +328,27 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
328
328
  @ReactMethod
329
329
  public void launchImageLibrary(final ReadableMap options, final Callback callback)
330
330
  {
331
- Handler handler = new Handler(this.reactContext.getMainLooper());
332
- handler.post(new Runnable() {
333
- @Override
334
- public void run(){
335
- permissionRequestCallback = callback;
331
+ permissionRequestCallback = callback;
336
332
 
337
- final Activity currentActivity = getCurrentActivity();
338
- if (currentActivity == null) {
339
- responseHelper.invokeError(callback, "can't find current Activity");
340
- return;
341
- }
333
+ final Activity currentActivity = getCurrentActivity();
334
+ if (currentActivity == null) {
335
+ responseHelper.invokeError(callback, "can't find current Activity");
336
+ return;
337
+ }
342
338
 
343
- this.callback = callback;
344
- this.options = options;
339
+ this.callback = callback;
340
+ this.options = options;
345
341
 
342
+ Handler handler = new Handler(this.getContext().getMainLooper());
343
+ handler.post(new Runnable() {
344
+ @Override
345
+ public void run(){
346
346
  if (!permissionsCheck(currentActivity, callback, REQUEST_PERMISSIONS_FOR_LIBRARY))
347
347
  {
348
348
  return;
349
349
  }
350
350
 
351
- parseOptions(this.options);
351
+ parseOptions(options);
352
352
 
353
353
  int requestCode;
354
354
  Intent libraryIntent;
@@ -395,12 +395,13 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
395
395
  }
396
396
 
397
397
  @Override
398
- public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
399
- Handler handler = new Handler(this.reactContext.getMainLooper());
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());
400
401
  handler.post(new Runnable() {
401
402
  @Override
402
403
  public void run() {
403
- if (passResult(requestCode))
404
+ if (self.passResult(requestCode))
404
405
  {
405
406
  return;
406
407
  }
@@ -447,7 +448,7 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
447
448
 
448
449
  ReadExifResult result = null;
449
450
  try {
450
- InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
451
+ InputStream imageInputStream = self.getContext().getContentResolver().openInputStream(uri);
451
452
  if(imageInputStream != null){
452
453
  result = readExifInterface(imageInputStream, responseHelper);
453
454
  }
@@ -472,7 +473,7 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
472
473
  options.inJustDecodeBounds = true;
473
474
  Bitmap imageBitmap = null;
474
475
  try {
475
- InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
476
+ InputStream imageInputStream = self.getContext().getContentResolver().openInputStream(uri);
476
477
  imageBitmap = BitmapFactory.decodeStream(imageInputStream, null, options);
477
478
  } catch(FileNotFoundException ex){
478
479
  responseHelper.invokeError(callback, "Could not find file");
@@ -492,7 +493,7 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
492
493
  responseHelper.putInt("height", initialHeight);
493
494
 
494
495
  try {
495
- InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
496
+ InputStream imageInputStream = self.getContext().getContentResolver().openInputStream(uri);
496
497
  updatedResultResponse(imageInputStream);
497
498
  } catch(FileNotFoundException ex){
498
499
  responseHelper.invokeError(callback, "Could not find file");
@@ -505,7 +506,7 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
505
506
  Bitmap resizedImage = null;
506
507
  ImageConfig rotatedImageConfig = imageConfig.withRotation(result.currentRotation);
507
508
  try {
508
- InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
509
+ InputStream imageInputStream = self.getContext().getContentResolver().openInputStream(uri);
509
510
  resizedImage = getResizedImage(imageInputStream, rotatedImageConfig, initialWidth, initialHeight);
510
511
  } catch(FileNotFoundException ex){
511
512
  responseHelper.invokeError(callback, "Could not find file");
@@ -537,8 +538,8 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
537
538
 
538
539
 
539
540
  responseHelper.invokeResponse(callback);
540
- callback = null;
541
- this.options = null;
541
+ self.callback = null;
542
+ self.options = null;
542
543
  }
543
544
  });
544
545
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connectedbits/react-native-image-picker",
3
- "version": "2.4.16-rc2",
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",