From 751702ceaa1c98802fffd355a3aaa0e3b5d3f64e Mon Sep 17 00:00:00 2001 From: Amit Davidi Date: Mon, 20 Mar 2017 15:29:17 +0200 Subject: [PATCH] Add convenience/code-share-enabling native-event decoding method to API --- src/CameraKitGallery.android.js | 18 +++++++++++++++--- src/CameraKitGallery.ios.js | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/CameraKitGallery.android.js b/src/CameraKitGallery.android.js index 9fe7d0f..2029643 100644 --- a/src/CameraKitGallery.android.js +++ b/src/CameraKitGallery.android.js @@ -7,9 +7,19 @@ async function getAlbumsWithThumbnails() { return albums; } +async function getImageUriForId(imageId) { + // Return what getImagesForIds() typically returns in the 'uri' field. + return `file://${imageId}`; +} + async function getImagesForIds(imagesUris = []) { - const images = await NativeGalleryModule.getImagesForUris(imagesUris); - return images; + return await NativeGalleryModule.getImagesForUris(imagesUris); +} + +async function getImageForTapEvent(nativeEvent) { + const selectedImageId = nativeEvent.selected; + const imageUri = selectedImageId && await getImageUriForId(selectedImageId); + return {selectedImageId, imageUri}; } async function checkDevicePhotosAuthorizationStatus() { @@ -26,5 +36,7 @@ export default { checkDevicePhotosAuthorizationStatus, requestDevicePhotosAuthorization, getAlbumsWithThumbnails, - getImagesForIds + getImageUriForId, + getImagesForIds, + getImageForTapEvent } diff --git a/src/CameraKitGallery.ios.js b/src/CameraKitGallery.ios.js index 18865f1..65c82e5 100644 --- a/src/CameraKitGallery.ios.js +++ b/src/CameraKitGallery.ios.js @@ -9,11 +9,32 @@ async function getAlbumsWithThumbnails() { return albums; } +async function getImageUriForId(imageId) { + const images = await CKGallery.getImagesForIds(imagesId); + if (!images) { + return; + } + return images.uri; +} + async function getImagesForIds(imagesId = []) { const images = await CKGallery.getImagesForIds(imagesId); return images; } +async function getImageForTapEvent(nativeEvent) { + let selectedImageId; + let imageUri; + if (nativeEvent.selectedId) { + selectedImageId = nativeEvent.selectedId; + imageUri = nativeEvent.selected; + } else { + selectedImageId = nativeEvent.selected; + imageUri = await getImageUriForId(selectedImageId); + } + return {selectedImageId, imageUri}; +} + async function checkDevicePhotosAuthorizationStatus() { const isAuthorized = await CKGallery.checkDevicePhotosAuthorizationStatus(); return isAuthorized; @@ -26,7 +47,9 @@ async function requestDevicePhotosAuthorization() { export default { getAlbumsWithThumbnails, + getImageUriForId, getImagesForIds, + getImageForTapEvent, checkDevicePhotosAuthorizationStatus, requestDevicePhotosAuthorization }