Commit d8ea109f authored by 少言's avatar 少言

0.1.4

parent 5841717f
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
### 功能特点 ### 功能特点
* 支持 iOS、Android 两端 * 支持 iOS、Android 两端
* 支持单选、多选,类型包括图片、GIF * 支持单选、多选
* 可自定义裁剪区域大小,支持圆形裁剪 * 可自定义裁剪区域大小,支持圆形裁剪
* 可设置压缩质量 * 可设置压缩质量
* 支持返回图片 base64 编码 * 支持返回图片 base64 编码
......
...@@ -259,7 +259,7 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule { ...@@ -259,7 +259,7 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
byte[] encode = Base64.encode(bytes,Base64.DEFAULT); byte[] encode = Base64.encode(bytes,Base64.DEFAULT);
String encodeString = new String(encode); String encodeString = new String(encode);
return encodeString; return "data:image/jpeg;base64," + encodeString;
} }
/** /**
...@@ -286,4 +286,4 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule { ...@@ -286,4 +286,4 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
this.mPickerPromise.reject(SY_SELECT_IMAGE_FAILED_CODE, "取消"); this.mPickerPromise.reject(SY_SELECT_IMAGE_FAILED_CODE, "取消");
} }
} }
} }
\ No newline at end of file
...@@ -99,7 +99,7 @@ RCT_EXPORT_METHOD(deleteCache) { ...@@ -99,7 +99,7 @@ RCT_EXPORT_METHOD(deleteCache) {
} }
} }
} }
__block TZImagePickerController *weakPicker = imagePickerVc; __block TZImagePickerController *weakPicker = imagePickerVc;
[imagePickerVc setDidFinishPickingPhotosWithInfosHandle:^(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto,NSArray<NSDictionary *> *infos) { [imagePickerVc setDidFinishPickingPhotosWithInfosHandle:^(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto,NSArray<NSDictionary *> *infos) {
NSMutableArray *selectedPhotos = [NSMutableArray array]; NSMutableArray *selectedPhotos = [NSMutableArray array];
...@@ -114,11 +114,11 @@ RCT_EXPORT_METHOD(deleteCache) { ...@@ -114,11 +114,11 @@ RCT_EXPORT_METHOD(deleteCache) {
[self invokeSuccessWithResult:selectedPhotos]; [self invokeSuccessWithResult:selectedPhotos];
[weakPicker hideProgressHUD]; [weakPicker hideProgressHUD];
}]; }];
[imagePickerVc setImagePickerControllerDidCancelHandle:^{ [imagePickerVc setImagePickerControllerDidCancelHandle:^{
[self invokeError]; [self invokeError];
}]; }];
[[self topViewController] presentViewController:imagePickerVc animated:YES completion:nil]; [[self topViewController] presentViewController:imagePickerVc animated:YES completion:nil];
} }
...@@ -191,12 +191,12 @@ RCT_EXPORT_METHOD(deleteCache) { ...@@ -191,12 +191,12 @@ RCT_EXPORT_METHOD(deleteCache) {
[picker dismissViewControllerAnimated:YES completion:nil]; [picker dismissViewControllerAnimated:YES completion:nil];
NSString *type = [info objectForKey:UIImagePickerControllerMediaType]; NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
if ([type isEqualToString:@"public.image"]) { if ([type isEqualToString:@"public.image"]) {
TZImagePickerController *tzImagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil]; TZImagePickerController *tzImagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil];
tzImagePickerVc.sortAscendingByModificationDate = NO; tzImagePickerVc.sortAscendingByModificationDate = NO;
[tzImagePickerVc showProgressHUD]; [tzImagePickerVc showProgressHUD];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// save photo and get asset / 保存图片,获取到asset // save photo and get asset / 保存图片,获取到asset
[[TZImageManager manager] savePhotoWithImage:image location:NULL completion:^(NSError *error){ [[TZImageManager manager] savePhotoWithImage:image location:NULL completion:^(NSError *error){
if (error) { if (error) {
...@@ -206,7 +206,7 @@ RCT_EXPORT_METHOD(deleteCache) { ...@@ -206,7 +206,7 @@ RCT_EXPORT_METHOD(deleteCache) {
[[TZImageManager manager] getCameraRollAlbum:NO allowPickingImage:YES needFetchAssets:YES completion:^(TZAlbumModel *model) { [[TZImageManager manager] getCameraRollAlbum:NO allowPickingImage:YES needFetchAssets:YES completion:^(TZAlbumModel *model) {
[[TZImageManager manager] getAssetsFromFetchResult:model.result allowPickingVideo:NO allowPickingImage:YES completion:^(NSArray<TZAssetModel *> *models) { [[TZImageManager manager] getAssetsFromFetchResult:model.result allowPickingVideo:NO allowPickingImage:YES completion:^(NSArray<TZAssetModel *> *models) {
[tzImagePickerVc hideProgressHUD]; [tzImagePickerVc hideProgressHUD];
TZAssetModel *assetModel = [models firstObject]; TZAssetModel *assetModel = [models firstObject];
BOOL isCrop = [self.cameraOptions sy_boolForKey:@"isCrop"]; BOOL isCrop = [self.cameraOptions sy_boolForKey:@"isCrop"];
BOOL showCropCircle = [self.cameraOptions sy_boolForKey:@"showCropCircle"]; BOOL showCropCircle = [self.cameraOptions sy_boolForKey:@"showCropCircle"];
...@@ -214,7 +214,7 @@ RCT_EXPORT_METHOD(deleteCache) { ...@@ -214,7 +214,7 @@ RCT_EXPORT_METHOD(deleteCache) {
NSInteger CropH = [self.cameraOptions sy_integerForKey:@"CropH"]; NSInteger CropH = [self.cameraOptions sy_integerForKey:@"CropH"];
NSInteger circleCropRadius = [self.cameraOptions sy_integerForKey:@"circleCropRadius"]; NSInteger circleCropRadius = [self.cameraOptions sy_integerForKey:@"circleCropRadius"];
NSInteger quality = [self.cameraOptions sy_integerForKey:@"quality"]; NSInteger quality = [self.cameraOptions sy_integerForKey:@"quality"];
if (isCrop) { if (isCrop) {
TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initCropTypeWithAsset:assetModel.asset photo:image completion:^(UIImage *cropImage, id asset) { TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initCropTypeWithAsset:assetModel.asset photo:image completion:^(UIImage *cropImage, id asset) {
[self invokeSuccessWithResult:@[[self handleImageData:cropImage quality:quality]]]; [self invokeSuccessWithResult:@[[self handleImageData:cropImage quality:quality]]];
...@@ -258,12 +258,12 @@ RCT_EXPORT_METHOD(deleteCache) { ...@@ -258,12 +258,12 @@ RCT_EXPORT_METHOD(deleteCache) {
- (NSDictionary *)handleImageData:(UIImage *) image quality:(NSInteger)quality { - (NSDictionary *)handleImageData:(UIImage *) image quality:(NSInteger)quality {
NSMutableDictionary *photo = [NSMutableDictionary dictionary]; NSMutableDictionary *photo = [NSMutableDictionary dictionary];
NSData *imageData = UIImageJPEGRepresentation(image, quality * 1.0 / 100); NSData *imageData = UIImageJPEGRepresentation(image, quality * 1.0 / 100);
// 剪切图片并放在tmp中 // 剪切图片并放在tmp中
photo[@"width"] = @(image.size.width); photo[@"width"] = @(image.size.width);
photo[@"height"] = @(image.size.height); photo[@"height"] = @(image.size.height);
photo[@"size"] = @(imageData.length); photo[@"size"] = @(imageData.length);
NSString *fileName = [NSString stringWithFormat:@"%@.jpg", [[NSUUID UUID] UUIDString]]; NSString *fileName = [NSString stringWithFormat:@"%@.jpg", [[NSUUID UUID] UUIDString]];
[self createDir]; [self createDir];
NSString *filePath = [NSString stringWithFormat:@"%@ImageCaches/%@", NSTemporaryDirectory(), fileName]; NSString *filePath = [NSString stringWithFormat:@"%@ImageCaches/%@", NSTemporaryDirectory(), fileName];
...@@ -272,9 +272,9 @@ RCT_EXPORT_METHOD(deleteCache) { ...@@ -272,9 +272,9 @@ RCT_EXPORT_METHOD(deleteCache) {
} else { } else {
NSLog(@"保存压缩图片失败%@", filePath); NSLog(@"保存压缩图片失败%@", filePath);
} }
if ([self.cameraOptions sy_boolForKey:@"enableBase64"]) { if ([self.cameraOptions sy_boolForKey:@"enableBase64"]) {
photo[@"base64"] = [imageData base64EncodedStringWithOptions:0]; photo[@"base64"] = [NSString stringWithFormat:@"data:image/jpeg;base64,%@", [imageData base64EncodedStringWithOptions:0]];
} }
return photo; return photo;
} }
......
{ {
"name": "react-native-syan-image-picker", "name": "react-native-syan-image-picker",
"version": "0.1.2", "version": "0.1.4",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment