From 30d4877c2be9315f37613142a2cd23718e84cea0 Mon Sep 17 00:00:00 2001 From: bill Date: Tue, 10 Oct 2023 18:22:01 +0800 Subject: [PATCH 1/2] support directly open album on iOS --- index.d.ts | 20 ++++++++++++------- .../QBImagePicker/QBAlbumsViewController.h | 2 +- .../QBImagePicker/QBAlbumsViewController.m | 17 ++++++++++++++++ .../QBImagePicker/QBImagePickerController.h | 1 + .../QBImagePicker/QBImagePickerController.m | 6 ++++++ 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index d3e1fd469..45b3b78f4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -49,6 +49,12 @@ declare module "react-native-image-crop-picker" { | 'LongExposure'; export interface CommonOptions { + /** + * Enable direct open Album on iOS only. + * + * @default false + */ + directAlbum?: boolean; /** * Enable or disable multiple image selection. * @@ -278,13 +284,13 @@ declare module "react-native-image-crop-picker" { */ cropperChooseColor?: string; - /** - * Enable or disable cropper rotate buttons. - * - * @platform iOS only - * @default false - */ - cropperRotateButtonsHidden?: boolean + /** + * Enable or disable cropper rotate buttons. + * + * @platform iOS only + * @default false + */ + cropperRotateButtonsHidden?: boolean /** * Whether to show the 3x3 grid on top of the image during cropping. diff --git a/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.h b/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.h index 43610b440..30c257ebc 100644 --- a/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.h +++ b/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.h @@ -13,5 +13,5 @@ @interface QBAlbumsViewController : UITableViewController @property (nonatomic, weak) QBImagePickerController *imagePickerController; - +@property (nonatomic, assign) BOOL directOpenAlbum; @end diff --git a/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m b/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m index dec556cac..e01941e55 100644 --- a/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m +++ b/ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m @@ -69,6 +69,10 @@ - (void)viewDidLoad // Register observer [[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self]; + // Support Direct openAlbum + if(self.directOpenAlbum){ + [self directPushViewAlbumController]; + } } - (void)viewWillAppear:(BOOL)animated @@ -96,6 +100,19 @@ - (void)dealloc [[PHPhotoLibrary sharedPhotoLibrary] unregisterChangeObserver:self]; } +#pragma mark - Navigation +-(void)directPushViewAlbumController { + NSBundle *assetBundle = [NSBundle bundleForClass:[QBImagePickerController class]]; + NSString *bundlePath = [assetBundle pathForResource:@"QBImagePicker" ofType:@"bundle"]; + if (bundlePath) { + assetBundle = [NSBundle bundleWithPath:bundlePath]; + } + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"QBImagePicker" bundle: assetBundle]; + QBAssetsViewController *assetsViewController = [storyboard instantiateViewControllerWithIdentifier:@"QBAssetsViewController"]; + assetsViewController.imagePickerController = self.imagePickerController; + assetsViewController.assetCollection = self.assetCollections[0]; + [self.navigationController pushViewController:assetsViewController animated:NO]; +} #pragma mark - Storyboard diff --git a/ios/QBImagePicker/QBImagePicker/QBImagePickerController.h b/ios/QBImagePicker/QBImagePicker/QBImagePickerController.h index 6289eef8d..7701c3d29 100644 --- a/ios/QBImagePicker/QBImagePicker/QBImagePickerController.h +++ b/ios/QBImagePicker/QBImagePicker/QBImagePickerController.h @@ -49,4 +49,5 @@ typedef NS_ENUM(NSUInteger, QBImagePickerMediaType) { @property (nonatomic, assign) NSUInteger numberOfColumnsInPortrait; @property (nonatomic, assign) NSUInteger numberOfColumnsInLandscape; +@property (nonatomic, assign) BOOL directOpenAlbum; @end diff --git a/ios/QBImagePicker/QBImagePicker/QBImagePickerController.m b/ios/QBImagePicker/QBImagePicker/QBImagePickerController.m index 99577c54a..f0ed118e6 100644 --- a/ios/QBImagePicker/QBImagePicker/QBImagePickerController.m +++ b/ios/QBImagePicker/QBImagePicker/QBImagePickerController.m @@ -74,4 +74,10 @@ - (void)setUpAlbumsViewController self.albumsNavigationController = navigationController; } +-(void)setDirectOpenAlbum:(BOOL)directOpenAlbum{ + QBAlbumsViewController *albumsViewController = (QBAlbumsViewController *)self.albumsNavigationController.topViewController; + albumsViewController.directOpenAlbum = directOpenAlbum; + +} + @end From 99f4a84b73b2017ef6a26f6a613e96b15073a2cc Mon Sep 17 00:00:00 2001 From: bill Date: Tue, 10 Oct 2023 18:26:32 +0800 Subject: [PATCH 2/2] support directly open album on iOS add missing file --- ios/src/ImageCropPicker.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ios/src/ImageCropPicker.m b/ios/src/ImageCropPicker.m index 9f20973f1..21dc3f6c0 100644 --- a/ios/src/ImageCropPicker.m +++ b/ios/src/ImageCropPicker.m @@ -50,6 +50,7 @@ - (instancetype)init if (self = [super init]) { self.defaultOptions = @{ @"multiple": @NO, + @"directAlbum": @NO, @"cropping": @NO, @"cropperCircleOverlay": @NO, @"writeTempFile": @YES, @@ -296,6 +297,7 @@ - (BOOL)cleanTmpDirectory { [QBImagePickerController new]; imagePickerController.delegate = self; imagePickerController.allowsMultipleSelection = [[self.options objectForKey:@"multiple"] boolValue]; + imagePickerController.directOpenAlbum = [[self.options objectForKey:@"directAlbum"] boolValue]; imagePickerController.minimumNumberOfSelection = abs([[self.options objectForKey:@"minFiles"] intValue]); imagePickerController.maximumNumberOfSelection = abs([[self.options objectForKey:@"maxFiles"] intValue]); imagePickerController.showsNumberOfSelectedAssets = [[self.options objectForKey:@"showsSelectedCount"] boolValue];