Skip to content

Commit a8a2fe4

Browse files
committed
feat: new contentInsetAdjustmentBehavior for iOS
1 parent 43aff7f commit a8a2fe4

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

src/collectionview-common.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import { CollectionView as CollectionViewDefinition, Orientation } from './colle
2727

2828
export const CollectionViewTraceCategory = 'NativescriptCollectionView';
2929

30+
// iOS only
31+
export enum ContentInsetAdjustmentBehavior {
32+
Always,
33+
Automatic,
34+
Never,
35+
ScrollableAxes
36+
}
3037
declare module '@nativescript/core/ui/core/view-base' {
3138
interface ViewBase {
3239
_recursiveSuspendNativeUpdates(type);
@@ -539,6 +546,6 @@ reverseLayoutProperty.register(CollectionViewBase);
539546
export const loadMoreThresholdProperty = new Property<CollectionViewBase, number>({
540547
name: 'loadMoreThreshold',
541548
defaultValue: 1,
542-
valueConverter: parseInt
549+
valueConverter: v => parseInt(v, 10)
543550
});
544551
loadMoreThresholdProperty.register(CollectionViewBase);

src/collectionview.android.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ export class CollectionView extends CollectionViewBase {
631631
// super.notifyDataSetChanged();
632632
// }
633633

634-
@profile
635634
public getItemViewType(position: number) {
636635
let resultType = 0;
637636
let selectorType: string = 'default';
@@ -653,7 +652,6 @@ export class CollectionView extends CollectionViewBase {
653652
return resultType;
654653
}
655654

656-
@profile
657655
disposeViewHolderViews() {
658656
this._viewHolders.forEach((v) => {
659657
v.view = null;
@@ -662,7 +660,6 @@ export class CollectionView extends CollectionViewBase {
662660
this._viewHolders = new Array();
663661
this._viewHolderChildren.forEach(this._removeViewCore);
664662
}
665-
@profile
666663
getKeyByValue(viewType: number) {
667664
return this.templateStringTypeNumber.get(viewType);
668665
}

src/collectionview.ios.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
KeyedTemplate,
77
Length,
88
Observable,
9+
Property,
910
ProxyViewContainer,
1011
Trace,
1112
View,
@@ -23,6 +24,37 @@ export * from './collectionview-common';
2324

2425
const infinity = layout.makeMeasureSpec(0, layout.UNSPECIFIED);
2526

27+
28+
export enum ContentInsetAdjustmentBehavior {
29+
Always = UIScrollViewContentInsetAdjustmentBehavior.Always,
30+
Automatic = UIScrollViewContentInsetAdjustmentBehavior.Automatic,
31+
Never = UIScrollViewContentInsetAdjustmentBehavior.Never,
32+
ScrollableAxes = UIScrollViewContentInsetAdjustmentBehavior.ScrollableAxes
33+
}
34+
35+
function parseContentInsetAdjustmentBehavior(value: string | number) {
36+
if (typeof value === 'string') {
37+
switch(value) {
38+
case 'always':
39+
return ContentInsetAdjustmentBehavior.Always;
40+
case 'never':
41+
return ContentInsetAdjustmentBehavior.Never;
42+
case 'ccrollableAxes':
43+
return ContentInsetAdjustmentBehavior.ScrollableAxes;
44+
default:
45+
case 'automatic':
46+
return ContentInsetAdjustmentBehavior.Automatic;
47+
}
48+
} else {
49+
return value;
50+
}
51+
}
52+
export const contentInsetAdjustmentBehaviorProperty = new Property<CollectionView, ContentInsetAdjustmentBehavior>({
53+
name: 'contentInsetAdjustmentBehavior',
54+
valueConverter: parseContentInsetAdjustmentBehavior,
55+
defaultValue: ContentInsetAdjustmentBehavior.Automatic
56+
});
57+
2658
export class CollectionView extends CollectionViewBase {
2759
private _layout: UICollectionViewLayout;
2860
private _dataSource: CollectionViewDataSource;
@@ -112,6 +144,10 @@ export class CollectionView extends CollectionViewBase {
112144
return this._map.size;
113145
}
114146

147+
public [contentInsetAdjustmentBehaviorProperty.setNative](value: ContentInsetAdjustmentBehavior) {
148+
this.nativeViewProtected.contentInsetAdjustmentBehavior = value as any;
149+
}
150+
115151
public [paddingTopProperty.setNative](value: Length) {
116152
this._setPadding({ top: layout.toDeviceIndependentPixels(this.effectivePaddingTop) });
117153
}
@@ -505,12 +541,12 @@ export class CollectionView extends CollectionViewBase {
505541
}
506542
return undefined;
507543
}
508-
layoutCell(index: number, cell: any, cellView: View): any {
544+
layoutCell(index: number, cell: CollectionViewCell, cellView: View): any {
509545
const cellSize = this.getCellSize(index);
510546
cellView.iosOverflowSafeAreaEnabled = false;
511547
View.layoutChild(this, cellView, 0, 0, cellSize[0], cellSize[1]);
512548
if (Trace.isEnabled()) {
513-
CLog(CLogTypes.log, 'layoutCell', index, cellSize[0], cellSize[1], cellView.getMeasuredWidth(), cellView.getMeasuredHeight());
549+
CLog(CLogTypes.log, 'layoutCell', index, cellView.getMeasuredWidth(), cellView.getMeasuredHeight());
514550
}
515551
}
516552

@@ -787,3 +823,5 @@ class UICollectionViewDelegateImpl extends NSObject implements UICollectionViewD
787823
}
788824
}
789825
}
826+
827+
contentInsetAdjustmentBehaviorProperty.register(CollectionView);

0 commit comments

Comments
 (0)