From 604bc5bd2e61bf6b9136598fa8305d927c5f1e70 Mon Sep 17 00:00:00 2001 From: Artal Druk Date: Sun, 28 May 2017 14:42:34 +0300 Subject: [PATCH] provide image width and height on tap events --- .../RNCameraKit/gallery/GalleryAdapter.java | 22 +++++++++++++------ .../RNCameraKit/gallery/TapImageEvent.java | 4 +++- .../CKGalleryViewManager.m | 9 ++++++-- src/CameraKitGallery.android.js | 2 +- src/CameraKitGallery.ios.js | 2 +- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/android/src/main/java/com/wix/RNCameraKit/gallery/GalleryAdapter.java b/android/src/main/java/com/wix/RNCameraKit/gallery/GalleryAdapter.java index da7642c..c297ecf 100644 --- a/android/src/main/java/com/wix/RNCameraKit/gallery/GalleryAdapter.java +++ b/android/src/main/java/com/wix/RNCameraKit/gallery/GalleryAdapter.java @@ -41,18 +41,24 @@ public class GalleryAdapter extends RecyclerView.Adapter { private final int targetTag; private WritableMap event; - TapImageEvent(int targetTag, String uri) { + TapImageEvent(int targetTag, String uri, Integer width, Integer height) { this.targetTag = targetTag; event = Arguments.createMap(); event.putString("selected", uri); event.putString("id", "onTapImage"); + event.putInt("width", width); + event.putInt("height", height); init(0); } diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m b/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m index 7b35cfd..8b5135f 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m +++ b/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m @@ -444,6 +444,9 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell"; -(void)onSelectChanged:(PHAsset*)asset { if (self.onTapImage) { + NSMutableDictionary *imageTapInfo = [@{@"width": [NSNumber numberWithUnsignedInteger:asset.pixelWidth], + @"height": [NSNumber numberWithUnsignedInteger:asset.pixelHeight]} mutableCopy]; + BOOL shouldReturnUrl = self.getUrlOnTapImage ? [self.getUrlOnTapImage boolValue] : NO; if (shouldReturnUrl) { PHImageRequestOptions *imageRequestOptions = [[PHImageRequestOptions alloc] init]; @@ -451,7 +454,8 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell"; NSDictionary *info = [CKGalleryViewManager infoForAsset:asset imageRequestOptions:imageRequestOptions imageQuality:self.imageQualityOnTap]; NSString *uriString = info[@"uri"]; if (uriString) { - self.onTapImage(@{@"selected": uriString, @"selectedId": asset.localIdentifier}); + [imageTapInfo addEntriesFromDictionary:@{@"selected": uriString, @"selectedId": asset.localIdentifier}]; + self.onTapImage(imageTapInfo); } else { self.onTapImage(@{@"Error": @"Could not get image uri"}); @@ -459,7 +463,8 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell"; } else { - self.onTapImage(@{@"selected":asset.localIdentifier}); + [imageTapInfo addEntriesFromDictionary:@{@"selected":asset.localIdentifier}]; + self.onTapImage(imageTapInfo); } } } diff --git a/src/CameraKitGallery.android.js b/src/CameraKitGallery.android.js index 2029643..d7fcf7e 100644 --- a/src/CameraKitGallery.android.js +++ b/src/CameraKitGallery.android.js @@ -19,7 +19,7 @@ async function getImagesForIds(imagesUris = []) { async function getImageForTapEvent(nativeEvent) { const selectedImageId = nativeEvent.selected; const imageUri = selectedImageId && await getImageUriForId(selectedImageId); - return {selectedImageId, imageUri}; + return {selectedImageId, imageUri, width: nativeEvent.width, height: nativeEvent.height}; } async function checkDevicePhotosAuthorizationStatus() { diff --git a/src/CameraKitGallery.ios.js b/src/CameraKitGallery.ios.js index ae182e8..2619051 100644 --- a/src/CameraKitGallery.ios.js +++ b/src/CameraKitGallery.ios.js @@ -35,7 +35,7 @@ async function getImageForTapEvent(nativeEvent) { selectedImageId = nativeEvent.selected; imageUri = await getImageUriForId(selectedImageId); } - return {selectedImageId, imageUri}; + return {selectedImageId, imageUri, width: nativeEvent.width, height: nativeEvent.height}; }