Commit ccd9496f authored by 少言's avatar 少言

0.1.5

parent f0d34a9d
......@@ -157,6 +157,7 @@ android {
属性名 | 类型 | 是否可选 | 默认值 | 描述
---------------- | ------ | -------- | ----------- | -----------
imageCount | int | 是 | 6 | 最大选择图片数目
isRecordSelected | bool | 是 | false | 记录当前已选中的图片
isCamera | bool | 是 | true | 是否允许用户在内部拍照
isCrop | bool | 是 | false | 是否允许裁剪,imageCount 为1才生效
CropW | int | 是 | screenW * 0.6 | 裁剪宽度,默认屏幕宽度60%
......@@ -245,6 +246,12 @@ handleDeletePhoto = index => {
}
```
### 移除全部选中图片
```javascript
STImagePicke.removeAllPhoto()
```
### 调用相机
相机功能调用 `openCamera` 方法,一样支持 Callback 和 Promise 两种形式,结果参数也保持一致。
......
......@@ -32,5 +32,5 @@ repositories {
dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.0'
compile 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.2'
}
......@@ -99,6 +99,17 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
}
}
/**
* 移除所有选中的图片
*/
@ReactMethod
public void removeAllPhoto() {
if (selectList != null) {
//selectList.clear();
selectList = null;
}
}
/**
* 打开相册选择
*/
......@@ -124,7 +135,7 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
PictureSelector.create(currentActivity)
.openGallery(PictureMimeType.ofImage())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
.maxSelectNum(imageCount)// 最大图片选择数量 int
.minSelectNum(1)// 最小选择数量 int
.minSelectNum(0)// 最小选择数量 int
.imageSpanCount(4)// 每行显示个数 int
.selectionMode(modeValue)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
.previewImage(true)// 是否可预览图片 true or false
......@@ -198,7 +209,8 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
switch (requestCode) {
case PictureConfig.CHOOSE_REQUEST:
List<LocalMedia> tmpSelectList = PictureSelector.obtainMultipleResult(data);
if (!tmpSelectList.isEmpty()) {
boolean isRecordSelected = cameraOptions.getBoolean("isRecordSelected");
if (!tmpSelectList.isEmpty() && isRecordSelected) {
selectList = tmpSelectList;
}
......
......@@ -11,6 +11,7 @@ const { width } = Dimensions.get('window');
*/
const defaultOptions = {
imageCount: 6, // 最大选择图片数目,默认6
isRecordSelected: false, // 是否已选图片
isCamera: true, // 是否允许用户在内部拍照,默认true
isCrop: false, // 是否允许裁剪,默认false, imageCount 为1才生效
CropW: ~~(width * 0.6), // 裁剪宽度,默认屏幕宽度60%
......@@ -111,5 +112,12 @@ export default {
*/
removePhotoAtIndex(index) {
RNSyanImagePicker.removePhotoAtIndex(index)
},
/**
* 移除所有选中图片
*/
removeAllPhoto() {
RNSyanImagePicker.removeAllPhoto()
}
};
......@@ -31,22 +31,22 @@
@implementation RNSyanImagePicker
- (instancetype)init {
self = [super init];
if (self) {
_selectedAssets = [NSMutableArray array];
}
return self;
self = [super init];
if (self) {
_selectedAssets = [NSMutableArray array];
}
return self;
}
- (void)dealloc {
_selectedAssets = nil;
_selectedAssets = nil;
}
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(showImagePicker:(NSDictionary *)options
callback:(RCTResponseSenderBlock)callback) {
self.cameraOptions = options;
self.cameraOptions = options;
self.callback = callback;
self.resolveBlock = nil;
self.rejectBlock = nil;
......@@ -57,7 +57,7 @@ RCT_REMAP_METHOD(asyncShowImagePicker,
options:(NSDictionary *)options
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
self.cameraOptions = options;
self.cameraOptions = options;
self.resolveBlock = resolve;
self.rejectBlock = reject;
self.callback = nil;
......@@ -78,9 +78,15 @@ RCT_EXPORT_METHOD(deleteCache) {
}
RCT_EXPORT_METHOD(removePhotoAtIndex:(NSInteger)index) {
if (self.selectedAssets && self.selectedAssets.count > index) {
[self.selectedAssets removeObjectAtIndex:index];
}
if (self.selectedAssets && self.selectedAssets.count > index) {
[self.selectedAssets removeObjectAtIndex:index];
}
}
RCT_EXPORT_METHOD(removeAllPhoto) {
if (self.selectedAssets) {
[self.selectedAssets removeAllObjects];
}
}
- (void)openImagePicker {
......@@ -91,6 +97,7 @@ RCT_EXPORT_METHOD(removePhotoAtIndex:(NSInteger)index) {
BOOL isCrop = [self.cameraOptions sy_boolForKey:@"isCrop"];
BOOL isGif = [self.cameraOptions sy_boolForKey:@"isGif"];
BOOL showCropCircle = [self.cameraOptions sy_boolForKey:@"showCropCircle"];
BOOL isRecordSelected = [self.cameraOptions sy_boolForKey:@"isRecordSelected"];
NSInteger CropW = [self.cameraOptions sy_integerForKey:@"CropW"];
NSInteger CropH = [self.cameraOptions sy_integerForKey:@"CropH"];
NSInteger circleCropRadius = [self.cameraOptions sy_integerForKey:@"circleCropRadius"];
......@@ -103,8 +110,12 @@ RCT_EXPORT_METHOD(removePhotoAtIndex:(NSInteger)index) {
imagePickerVc.allowTakePicture = isCamera; // 允许用户在内部拍照
imagePickerVc.allowPickingVideo = NO; // 不允许视频
imagePickerVc.allowPickingOriginalPhoto = NO; // 允许原图
imagePickerVc.alwaysEnableDoneBtn = YES;
imagePickerVc.allowCrop = isCrop; // 裁剪
imagePickerVc.selectedAssets = self.selectedAssets; // 当前已选中的图片
if (isRecordSelected) {
imagePickerVc.selectedAssets = self.selectedAssets; // 当前已选中的图片
}
if (imageCount == 1) {
// 单选模式
......@@ -125,22 +136,26 @@ RCT_EXPORT_METHOD(removePhotoAtIndex:(NSInteger)index) {
__block TZImagePickerController *weakPicker = imagePickerVc;
[imagePickerVc setDidFinishPickingPhotosWithInfosHandle:^(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto,NSArray<NSDictionary *> *infos) {
self.selectedAssets = [NSMutableArray arrayWithArray:assets];
NSMutableArray *selectedPhotos = [NSMutableArray array];
[weakPicker showProgressHUD];
if (imageCount == 1 && isCrop) {
[selectedPhotos addObject:[self handleImageData:photos[0] quality:quality]];
} else {
[infos enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[selectedPhotos addObject:[self handleImageData:photos[idx] quality:quality]];
}];
}
if (isRecordSelected) {
self.selectedAssets = [NSMutableArray arrayWithArray:assets];
}
NSMutableArray *selectedPhotos = [NSMutableArray array];
[weakPicker showProgressHUD];
if (imageCount == 1 && isCrop) {
[selectedPhotos addObject:[self handleImageData:photos[0] quality:quality]];
} else {
[infos enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[selectedPhotos addObject:[self handleImageData:photos[idx] quality:quality]];
}];
}
[self invokeSuccessWithResult:selectedPhotos];
[weakPicker hideProgressHUD];
}];
__block TZImagePickerController *weakPickerVc = imagePickerVc;
[imagePickerVc setImagePickerControllerDidCancelHandle:^{
[self invokeError];
[weakPickerVc hideProgressHUD];
}];
[[self topViewController] presentViewController:imagePickerVc animated:YES completion:nil];
......@@ -281,12 +296,12 @@ RCT_EXPORT_METHOD(removePhotoAtIndex:(NSInteger)index) {
- (NSDictionary *)handleImageData:(UIImage *) image quality:(NSInteger)quality {
NSMutableDictionary *photo = [NSMutableDictionary dictionary];
NSData *imageData = UIImageJPEGRepresentation(image, quality * 1.0 / 100);
NSData *imageData = UIImageJPEGRepresentation(image, quality * 1.0 / 100);
// 剪切图片并放在tmp中
photo[@"width"] = @(image.size.width);
photo[@"height"] = @(image.size.height);
photo[@"size"] = @(imageData.length);
photo[@"size"] = @(imageData.length);
NSString *fileName = [NSString stringWithFormat:@"%@.jpg", [[NSUUID UUID] UUIDString]];
[self createDir];
......@@ -297,9 +312,9 @@ RCT_EXPORT_METHOD(removePhotoAtIndex:(NSInteger)index) {
NSLog(@"保存压缩图片失败%@", filePath);
}
if ([self.cameraOptions sy_boolForKey:@"enableBase64"]) {
photo[@"base64"] = [NSString stringWithFormat:@"data:image/jpeg;base64,%@", [imageData base64EncodedStringWithOptions:0]];
}
if ([self.cameraOptions sy_boolForKey:@"enableBase64"]) {
photo[@"base64"] = [NSString stringWithFormat:@"data:image/jpeg;base64,%@", [imageData base64EncodedStringWithOptions:0]];
}
return photo;
}
......
"OK" = "Xác nhận";
"Back" = "Quay lại";
"Done" = "Hoàn thành";
"Sorry" = "Xin lỗi";
"Cancel" = "Hủy";
"Setting" = "Cài đặt";
"Photos" = "Hình";
"Videos" = "Clip";
"Preview" = "Xem trước";
"Full image" = "Hình gốc";
"Processing..." = "Đang xử lý...";
"Can not use camera" = "Máy chụp hình không khả dụng";
"Synchronizing photos from iCloud" = "Đang đồng bộ hình ảnh từ ICloud";
"Can not choose both video and photo" = "Trong lúc chọn hình ảnh không cùng lúc chọn video";
"Can not choose both photo and GIF" = "Trong lúc chọn hình ảnh không cùng lúc chọn hình GIF";
"Select the video when in multi state, we will handle the video as a photo" = "Chọn hình ảnh cùng video, video sẽ bị mặc nhận thành hình ảnh và gửi đi.";
"Can not jump to the privacy settings page, please go to the settings page by self, thank you" = "Không thể chuyển tự động qua trang cài đặt riêng tư, bạn hãy thoát ra cà điều chỉnh lại, cám ơn bạn.";
"Select a maximum of %zd photos" = "Bạn chỉ được chọn nhiều nhất %zd tấm hình";
"Select a minimum of %zd photos" = "Chọn ít nhất %zd tấm hình";
"Allow %@ to access your album in \"Settings -> Privacy -> Photos\"" = "Vui lòng tại mục iPhone \" Cài đặt – quyền riêng tư - Ảnh\" mở quyền cho phép %@ truy cập ảnh.";
"Please allow %@ to access your camera in \"Settings -> Privacy -> Camera\"" = "Vui lòng tại mục iPhone \" Cài đặt – quyền riêng tư - Ảnh\" mở quyền cho phép %@ truy cập máy ảnh";
{
"name": "react-native-syan-image-picker",
"version": "0.1.4",
"description": "",
"version": "0.1.5",
"description": "React-Native 多图片选择 支持裁剪 压缩",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
......
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