Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support direactly open Album on iOS #1983

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
@interface QBAlbumsViewController : UITableViewController

@property (nonatomic, weak) QBImagePickerController *imagePickerController;

@property (nonatomic, assign) BOOL directOpenAlbum;
@end
17 changes: 17 additions & 0 deletions ios/QBImagePicker/QBImagePicker/QBAlbumsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ - (void)viewDidLoad

// Register observer
[[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self];
// Support Direct openAlbum
if(self.directOpenAlbum){
[self directPushViewAlbumController];
}
}

- (void)viewWillAppear:(BOOL)animated
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions ios/QBImagePicker/QBImagePicker/QBImagePickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions ios/QBImagePicker/QBImagePicker/QBImagePickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ - (void)setUpAlbumsViewController
self.albumsNavigationController = navigationController;
}

-(void)setDirectOpenAlbum:(BOOL)directOpenAlbum{
QBAlbumsViewController *albumsViewController = (QBAlbumsViewController *)self.albumsNavigationController.topViewController;
albumsViewController.directOpenAlbum = directOpenAlbum;

}

@end
2 changes: 2 additions & 0 deletions ios/src/ImageCropPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ - (instancetype)init
if (self = [super init]) {
self.defaultOptions = @{
@"multiple": @NO,
@"directAlbum": @NO,
@"cropping": @NO,
@"cropperCircleOverlay": @NO,
@"writeTempFile": @YES,
Expand Down Expand Up @@ -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];
Expand Down