support contentInset of the gallery view on iOS

This commit is contained in:
Artal Druk 2017-03-26 12:50:18 +03:00
parent bcbae4b15f
commit 06615d060a
2 changed files with 13 additions and 5 deletions

View File

@ -152,6 +152,7 @@ selection | Object | See Selection section
getUrlOnTapImage | Boolean| iOS only - On image tap return the image internal (tmp folder) uri (intead of `Photos.framework` asset id) getUrlOnTapImage | Boolean| iOS only - On image tap return the image internal (tmp folder) uri (intead of `Photos.framework` asset id)
customButtonStyle | Object | See Custom Button section customButtonStyle | Object | See Custom Button section
onCustomButtonPress | Function | Callback when custom button tapped onCustomButtonPress | Function | Callback when custom button tapped
contentInset (iOS) | Object | The amount by which the gellery view content is inset from its edges (similar to `ScrollView` contentInset)
#### Custom Button #### Custom Button
Attribute | Values | Description Attribute | Values | Description

View File

@ -55,6 +55,7 @@
@property (nonatomic, strong) UIColor *imageStrokeColor; @property (nonatomic, strong) UIColor *imageStrokeColor;
@property (nonatomic, strong) NSNumber *disableSelectionIcons; @property (nonatomic, strong) NSNumber *disableSelectionIcons;
@property (nonatomic, strong) NSDictionary *selection; @property (nonatomic, strong) NSDictionary *selection;
@property (nonatomic) UIEdgeInsets contentInset;
//custom button props //custom button props
@property (nonatomic, strong) NSDictionary *customButtonStyle; @property (nonatomic, strong) NSDictionary *customButtonStyle;
@ -82,6 +83,8 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
self.imageRequestOptions = [[PHImageRequestOptions alloc] init]; self.imageRequestOptions = [[PHImageRequestOptions alloc] init];
self.imageRequestOptions.synchronous = YES; self.imageRequestOptions.synchronous = YES;
self.contentInset = UIEdgeInsetsZero;
} }
return self; return self;
@ -117,17 +120,17 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
-(void)reactSetFrame:(CGRect)frame { -(void)reactSetFrame:(CGRect)frame {
[super reactSetFrame:frame]; [super reactSetFrame:frame];
//NSLog(@"### reactSetFrame #####");
if (CGRectIsEmpty(frame)) return; if (CGRectIsEmpty(frame)) return;
if (!self.collectionView) { if (!self.collectionView) {
//NSLog(@"### collection view create new#####");
UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc] init]; UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.itemSize = self.cellSize; flowLayout.itemSize = self.cellSize;
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:flowLayout]; self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:flowLayout];
self.collectionView.contentInset = self.contentInset;
self.collectionView.scrollIndicatorInsets = self.contentInset;
self.collectionView.delegate = self; self.collectionView.delegate = self;
self.collectionView.dataSource = self; self.collectionView.dataSource = self;
@ -135,10 +138,8 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
[self.collectionView registerClass:[CKGalleryCustomCollectionViewCell class] forCellWithReuseIdentifier:CustomCellReuseIdentifier]; [self.collectionView registerClass:[CKGalleryCustomCollectionViewCell class] forCellWithReuseIdentifier:CustomCellReuseIdentifier];
[self addSubview:self.collectionView]; [self addSubview:self.collectionView];
self.collectionView.backgroundColor = [UIColor whiteColor]; self.collectionView.backgroundColor = [UIColor whiteColor];
} }
else { else {
//NSLog(@"### collection view using exists #####");
self.collectionView.frame = self.bounds; self.collectionView.frame = self.bounds;
} }
} }
@ -199,6 +200,12 @@ static NSString * const CustomCellReuseIdentifier = @"CustomCell";
[CKGalleryCollectionViewCell setSelection:selection]; [CKGalleryCollectionViewCell setSelection:selection];
} }
-(void)setContentInset:(UIEdgeInsets)contentInset {
if(self.collectionView) {
self.collectionView.contentInset = contentInset;
}
_contentInset = contentInset;
}
-(void)setFileTypeSupport:(NSDictionary *)supported { -(void)setFileTypeSupport:(NSDictionary *)supported {
_fileTypeSupport = supported; _fileTypeSupport = supported;
@ -497,7 +504,7 @@ RCT_EXPORT_VIEW_PROPERTY(onCustomButtonPress, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(getUrlOnTapImage, NSNumber); RCT_EXPORT_VIEW_PROPERTY(getUrlOnTapImage, NSNumber);
RCT_EXPORT_VIEW_PROPERTY(autoSyncSelection, NSNumber); RCT_EXPORT_VIEW_PROPERTY(autoSyncSelection, NSNumber);
RCT_EXPORT_VIEW_PROPERTY(selection, NSDictionary); RCT_EXPORT_VIEW_PROPERTY(selection, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets);
RCT_EXPORT_METHOD(getSelectedImages:(RCTPromiseResolveBlock)resolve RCT_EXPORT_METHOD(getSelectedImages:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) { reject:(RCTPromiseRejectBlock)reject) {