iOS: Fix layout in flowlayout or list
This commit is contained in:
parent
1dc167a43c
commit
0df882f28c
@ -45,8 +45,8 @@ @interface DoricFlowLayout : UICollectionViewLayout
|
||||
@property(nonatomic, readonly) CGFloat rowSpace;
|
||||
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, NSNumber *> *columnHeightInfo;
|
||||
@property(nonatomic, weak) id <DoricFlowLayoutDelegate> delegate;
|
||||
@property(nonatomic, copy) NSArray<UICollectionViewLayoutAttributes*> *layoutAttributes;
|
||||
@property(nonatomic, copy) NSArray<NSValue*> *unionRects;
|
||||
@property(nonatomic, copy) NSArray<UICollectionViewLayoutAttributes *> *layoutAttributes;
|
||||
@property(nonatomic, copy) NSArray<NSValue *> *unionRects;
|
||||
@property(nonatomic, strong) NSArray *swapDisabled;
|
||||
@end
|
||||
|
||||
@ -90,7 +90,7 @@ - (void)prepareLayout {
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
minYOfColumn = @(0);
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0] ;
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
|
||||
|
||||
UICollectionViewLayoutAttributes *attrs = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
|
||||
|
||||
@ -134,7 +134,7 @@ - (void)prepareLayout {
|
||||
NSMutableArray *mutableCopy = [NSMutableArray array];
|
||||
long idx = 0;
|
||||
NSInteger itemCounts = count;
|
||||
while(idx < itemCounts){
|
||||
while (idx < itemCounts) {
|
||||
CGRect rect1 = self.layoutAttributes[idx].frame;
|
||||
idx = MIN(idx + count, itemCounts) - 1;
|
||||
CGRect rect2 = self.layoutAttributes[idx].frame;
|
||||
@ -147,7 +147,7 @@ - (void)prepareLayout {
|
||||
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
|
||||
NSInteger begin = 0;
|
||||
NSInteger end = self.unionRects.count;
|
||||
NSMutableArray<UICollectionViewLayoutAttributes*> *attrs = [NSMutableArray array];
|
||||
NSMutableArray<UICollectionViewLayoutAttributes *> *attrs = [NSMutableArray array];
|
||||
|
||||
for (int i = 0; i < end; i++) {
|
||||
if (CGRectIntersectsRect(rect, [self.unionRects[i] CGRectValue])) {
|
||||
@ -486,12 +486,9 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
|
||||
if (props[@"fullSpan"]) {
|
||||
fullSpan = [props[@"fullSpan"] boolValue];
|
||||
}
|
||||
if (fullSpan) {
|
||||
node.view.width = collectionView.width;
|
||||
} else {
|
||||
node.view.width = (collectionView.width - (self.columnCount - 1) * self.columnSpace) / self.columnCount;
|
||||
}
|
||||
[node.view.doricLayout apply];
|
||||
CGFloat width = fullSpan ? collectionView.width : (collectionView.width - (self.columnCount - 1) * self.columnSpace) / self.columnCount;
|
||||
CGFloat height = node.view.doricLayout.heightSpec == DoricLayoutFit ? CGFLOAT_MAX : collectionView.height;
|
||||
[node.view.doricLayout apply:CGSizeMake(width, height)];
|
||||
[node requestLayout];
|
||||
[self callItem:position size:node.view.frame.size];
|
||||
return cell;
|
||||
|
@ -266,7 +266,8 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
|
||||
DoricHorizontalListItemNode *node = cell.doricHorizontalListItemNode;
|
||||
node.viewId = model[@"id"];
|
||||
[node blend:props];
|
||||
[node.view.doricLayout apply:CGSizeMake(collectionView.width, collectionView.height)];
|
||||
CGFloat width = node.view.doricLayout.widthSpec == DoricLayoutFit ? CGFLOAT_MAX : collectionView.width;
|
||||
[node.view.doricLayout apply:CGSizeMake(width, collectionView.height)];
|
||||
[node requestLayout];
|
||||
[self callItem:position width:node.view.width];
|
||||
return cell;
|
||||
|
@ -40,7 +40,7 @@ @interface DoricTableView : UITableView
|
||||
@implementation DoricTableView
|
||||
- (CGSize)sizeThatFits:(CGSize)size {
|
||||
CGSize result = [super sizeThatFits:size];
|
||||
if(self.doricLayout.widthSpec == DoricLayoutFit && self.contentSize.width>0){
|
||||
if (self.doricLayout.widthSpec == DoricLayoutFit && self.contentSize.width > 0) {
|
||||
return CGSizeMake(self.contentSize.width, result.height);
|
||||
}
|
||||
return result;
|
||||
@ -268,7 +268,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
|
||||
DoricListItemNode *node = cell.doricListItemNode;
|
||||
node.viewId = model[@"id"];
|
||||
[node blend:props];
|
||||
[node.view.doricLayout apply:CGSizeMake(tableView.width, tableView.height)];
|
||||
CGFloat height = node.view.doricLayout.heightSpec == DoricLayoutFit ? CGFLOAT_MAX : tableView.height;
|
||||
[node.view.doricLayout apply:CGSizeMake(tableView.width, height)];
|
||||
[node requestLayout];
|
||||
[self callItem:position height:node.view.height];
|
||||
return cell;
|
||||
|
Reference in New Issue
Block a user