provide image width and height on tap events
This commit is contained in:
parent
6b1add2696
commit
604bc5bd2e
|
@ -41,18 +41,24 @@ public class GalleryAdapter extends RecyclerView.Adapter<GalleryAdapter.AbsViewH
|
||||||
private static final String[] PROJECTION = new String[]{
|
private static final String[] PROJECTION = new String[]{
|
||||||
MediaStore.Images.Media.DATA,
|
MediaStore.Images.Media.DATA,
|
||||||
MediaStore.Images.Media._ID,
|
MediaStore.Images.Media._ID,
|
||||||
MediaStore.Images.Media.MIME_TYPE
|
MediaStore.Images.Media.MIME_TYPE,
|
||||||
|
MediaStore.Images.Media.WIDTH,
|
||||||
|
MediaStore.Images.Media.HEIGHT
|
||||||
};
|
};
|
||||||
|
|
||||||
private class Image {
|
private class Image {
|
||||||
String uri;
|
String uri;
|
||||||
Integer id;
|
Integer id;
|
||||||
String mimeType;
|
String mimeType;
|
||||||
|
Integer width;
|
||||||
|
Integer height;
|
||||||
|
|
||||||
public Image(String uri, Integer id, String mimeType) {
|
public Image(String uri, Integer id, String mimeType, Integer width, Integer height) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.mimeType = mimeType;
|
this.mimeType = mimeType;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +104,7 @@ public class GalleryAdapter extends RecyclerView.Adapter<GalleryAdapter.AbsViewH
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onTapImage(image.uri);
|
onTapImage(image.uri, image.width, image.height);
|
||||||
v.setSelected(!isSelected);
|
v.setSelected(!isSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,13 +287,15 @@ public class GalleryAdapter extends RecyclerView.Adapter<GalleryAdapter.AbsViewH
|
||||||
int dataIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
int dataIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||||
int idIndex = cursor.getColumnIndex(MediaStore.Images.Media._ID);
|
int idIndex = cursor.getColumnIndex(MediaStore.Images.Media._ID);
|
||||||
int mimeIndex = cursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE);
|
int mimeIndex = cursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE);
|
||||||
|
int widthIndex = cursor.getColumnIndex(MediaStore.Images.Media.WIDTH);
|
||||||
|
int heightIndex = cursor.getColumnIndex(MediaStore.Images.Media.HEIGHT);
|
||||||
do {
|
do {
|
||||||
images.add(new Image(cursor.getString(dataIndex), cursor.getInt(idIndex), cursor.getString(mimeIndex)));
|
images.add(new Image(cursor.getString(dataIndex), cursor.getInt(idIndex), cursor.getString(mimeIndex), cursor.getInt(widthIndex), cursor.getInt(heightIndex)));
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldShowCustomButton()) {
|
if (shouldShowCustomButton()) {
|
||||||
images.add(new Image(null, -1, ""));
|
images.add(new Image(null, -1, "", 0, 0));
|
||||||
}
|
}
|
||||||
Collections.reverse(images);
|
Collections.reverse(images);
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
@ -353,9 +361,9 @@ public class GalleryAdapter extends RecyclerView.Adapter<GalleryAdapter.AbsViewH
|
||||||
return customButtonImage != null;
|
return customButtonImage != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTapImage(String uri) {
|
public void onTapImage(String uri, Integer width, Integer height) {
|
||||||
final ReactContext reactContext = ((ReactContext) view.getContext());
|
final ReactContext reactContext = ((ReactContext) view.getContext());
|
||||||
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(new TapImageEvent(getRootViewId(), uri));
|
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(new TapImageEvent(getRootViewId(), uri, width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTapCustomButton() {
|
public void onTapCustomButton() {
|
||||||
|
|
|
@ -10,11 +10,13 @@ public class TapImageEvent extends Event<TapImageEvent> {
|
||||||
private final int targetTag;
|
private final int targetTag;
|
||||||
private WritableMap event;
|
private WritableMap event;
|
||||||
|
|
||||||
TapImageEvent(int targetTag, String uri) {
|
TapImageEvent(int targetTag, String uri, Integer width, Integer height) {
|
||||||
this.targetTag = targetTag;
|
this.targetTag = targetTag;
|
||||||
event = Arguments.createMap();
|
event = Arguments.createMap();
|
||||||
event.putString("selected", uri);
|
event.putString("selected", uri);
|
||||||
event.putString("id", "onTapImage");
|
event.putString("id", "onTapImage");
|
||||||
|
event.putInt("width", width);
|
||||||
|
event.putInt("height", height);
|
||||||
init(0);
|
init(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,6 +444,9 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||||
-(void)onSelectChanged:(PHAsset*)asset {
|
-(void)onSelectChanged:(PHAsset*)asset {
|
||||||
if (self.onTapImage) {
|
if (self.onTapImage) {
|
||||||
|
|
||||||
|
NSMutableDictionary *imageTapInfo = [@{@"width": [NSNumber numberWithUnsignedInteger:asset.pixelWidth],
|
||||||
|
@"height": [NSNumber numberWithUnsignedInteger:asset.pixelHeight]} mutableCopy];
|
||||||
|
|
||||||
BOOL shouldReturnUrl = self.getUrlOnTapImage ? [self.getUrlOnTapImage boolValue] : NO;
|
BOOL shouldReturnUrl = self.getUrlOnTapImage ? [self.getUrlOnTapImage boolValue] : NO;
|
||||||
if (shouldReturnUrl) {
|
if (shouldReturnUrl) {
|
||||||
PHImageRequestOptions *imageRequestOptions = [[PHImageRequestOptions alloc] init];
|
PHImageRequestOptions *imageRequestOptions = [[PHImageRequestOptions alloc] init];
|
||||||
|
@ -451,7 +454,8 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||||
NSDictionary *info = [CKGalleryViewManager infoForAsset:asset imageRequestOptions:imageRequestOptions imageQuality:self.imageQualityOnTap];
|
NSDictionary *info = [CKGalleryViewManager infoForAsset:asset imageRequestOptions:imageRequestOptions imageQuality:self.imageQualityOnTap];
|
||||||
NSString *uriString = info[@"uri"];
|
NSString *uriString = info[@"uri"];
|
||||||
if (uriString) {
|
if (uriString) {
|
||||||
self.onTapImage(@{@"selected": uriString, @"selectedId": asset.localIdentifier});
|
[imageTapInfo addEntriesFromDictionary:@{@"selected": uriString, @"selectedId": asset.localIdentifier}];
|
||||||
|
self.onTapImage(imageTapInfo);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.onTapImage(@{@"Error": @"Could not get image uri"});
|
self.onTapImage(@{@"Error": @"Could not get image uri"});
|
||||||
|
@ -459,7 +463,8 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.onTapImage(@{@"selected":asset.localIdentifier});
|
[imageTapInfo addEntriesFromDictionary:@{@"selected":asset.localIdentifier}];
|
||||||
|
self.onTapImage(imageTapInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ async function getImagesForIds(imagesUris = []) {
|
||||||
async function getImageForTapEvent(nativeEvent) {
|
async function getImageForTapEvent(nativeEvent) {
|
||||||
const selectedImageId = nativeEvent.selected;
|
const selectedImageId = nativeEvent.selected;
|
||||||
const imageUri = selectedImageId && await getImageUriForId(selectedImageId);
|
const imageUri = selectedImageId && await getImageUriForId(selectedImageId);
|
||||||
return {selectedImageId, imageUri};
|
return {selectedImageId, imageUri, width: nativeEvent.width, height: nativeEvent.height};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkDevicePhotosAuthorizationStatus() {
|
async function checkDevicePhotosAuthorizationStatus() {
|
||||||
|
|
|
@ -35,7 +35,7 @@ async function getImageForTapEvent(nativeEvent) {
|
||||||
selectedImageId = nativeEvent.selected;
|
selectedImageId = nativeEvent.selected;
|
||||||
imageUri = await getImageUriForId(selectedImageId);
|
imageUri = await getImageUriForId(selectedImageId);
|
||||||
}
|
}
|
||||||
return {selectedImageId, imageUri};
|
return {selectedImageId, imageUri, width: nativeEvent.width, height: nativeEvent.height};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue