Skip to content

Commit ad504d7

Browse files
committed
fix: for collectionview with iosOverflowSafeArea
We cant use the same technique as layoutView is called too soon when view is not added to the visual tree => no window => no compuation of iosOverflowSafeArea. It could be the way to go also without iosOverflowSafeArea. But it needs testing
1 parent ba0d698 commit ad504d7

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/collectionview.ios.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Property,
1010
ProxyViewContainer,
1111
Trace,
12+
Utils,
1213
View,
1314
paddingBottomProperty,
1415
paddingLeftProperty,
@@ -25,6 +26,7 @@ export * from './collectionview-common';
2526
const infinity = layout.makeMeasureSpec(0, layout.UNSPECIFIED);
2627

2728

29+
2830
export enum ContentInsetAdjustmentBehavior {
2931
Always = UIScrollViewContentInsetAdjustmentBehavior.Always,
3032
Automatic = UIScrollViewContentInsetAdjustmentBehavior.Automatic,
@@ -39,7 +41,7 @@ function parseContentInsetAdjustmentBehavior(value: string | number) {
3941
return ContentInsetAdjustmentBehavior.Always;
4042
case 'never':
4143
return ContentInsetAdjustmentBehavior.Never;
42-
case 'ccrollableAxes':
44+
case 'scrollableAxes':
4345
return ContentInsetAdjustmentBehavior.ScrollableAxes;
4446
default:
4547
case 'automatic':
@@ -466,7 +468,15 @@ export class CollectionView extends CollectionViewBase {
466468

467469
if (view && !view.parent) {
468470
this._addView(view);
469-
cell.contentView.addSubview(view.nativeViewProtected);
471+
if (this.iosOverflowSafeArea) {
472+
const innerView = UICellView.new() as UICellView;
473+
innerView.view = new WeakRef(view);
474+
innerView.addSubview(view.nativeViewProtected);
475+
cell.contentView.addSubview(innerView);
476+
} else {
477+
cell.contentView.addSubview(view.nativeViewProtected);
478+
}
479+
470480
}
471481
if (needsLayout) {
472482
view.requestLayout();
@@ -543,10 +553,9 @@ export class CollectionView extends CollectionViewBase {
543553
}
544554
layoutCell(index: number, cell: CollectionViewCell, cellView: View): any {
545555
const cellSize = this.getCellSize(index);
546-
cellView.iosOverflowSafeAreaEnabled = false;
547556
View.layoutChild(this, cellView, 0, 0, cellSize[0], cellSize[1]);
548557
if (Trace.isEnabled()) {
549-
CLog(CLogTypes.log, 'layoutCell', index, cellView.getMeasuredWidth(), cellView.getMeasuredHeight());
558+
CLog(CLogTypes.log, 'layoutCell', index, cellView, cellView.getMeasuredWidth(), cellView.getMeasuredHeight());
550559
}
551560
}
552561

@@ -619,7 +628,7 @@ export class CollectionView extends CollectionViewBase {
619628
this._prepareCell(cell, indexPath, templateType);
620629

621630
const cellView: View = cell.view;
622-
if (cellView && cellView['isLayoutRequired']) {
631+
if (!this.iosOverflowSafeArea && cellView && cellView['isLayoutRequired']) {
623632
this.layoutCell(indexPath.row, cell, cellView);
624633
}
625634
return cell;
@@ -729,12 +738,25 @@ interface ViewItemIndex {
729738
}
730739

731740
type ItemView = View & ViewItemIndex;
741+
742+
@NativeClass
743+
class UICellView extends UIView {
744+
view: WeakRef<View>;
745+
layoutSubviews() {
746+
const view = this.view && this.view.get();
747+
if (!view) {
748+
return;
749+
}
750+
this.frame = this.superview.bounds;
751+
const size = this.bounds.size;
752+
View.layoutChild(null, view, 0, 0, Utils.layout.toDevicePixels(size.width), Utils.layout.toDevicePixels(size.height));
753+
}
754+
}
755+
732756
@NativeClass
733757
class CollectionViewCell extends UICollectionViewCell {
734758
owner: WeakRef<ItemView>;
735-
// static class() {
736-
// return CollectionViewCell.class();
737-
// }
759+
738760
get view(): ItemView {
739761
return this.owner ? this.owner.get() : null;
740762
}

0 commit comments

Comments
 (0)