Skip to content

Commit abe67f3

Browse files
committed
fix ios padding
1 parent c5dbaea commit abe67f3

File tree

5 files changed

+23
-93
lines changed

5 files changed

+23
-93
lines changed

demo/app/main-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:gv="nativescript-grid-view" loaded="pageLoaded">
22
<GridLayout>
3-
<gv:GridView items="{{ items }}" verticalSpacing="5" horizontalSpacing="5" colWidth="100" rowHeight="75" padding="5"
3+
<gv:GridView items="{{ items }}" verticalSpacing="5" horizontalSpacing="5" colWidth="100" rowHeight="75" style="padding: 5;"
44
itemTap="gridViewItemTap" itemLoading="gridViewItemLoading" loadMoreItems="gridViewLoadMoreItems">
55
<gv:GridView.itemTemplate>
66
<GridLayout backgroundColor="#33ffff">

demo/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
"nativescript": {
33
"id": "net.tangrainc.gridviewsample",
44
"tns-ios": {
5-
"version": "2.4.0"
5+
"version": "2.5.0"
66
},
77
"tns-android": {
8-
"version": "2.4.1"
8+
"version": "2.5.0"
99
}
1010
},
1111
"scripts": {
12-
"android": "npm uninstall nativescript-grid-view && tns deploy android",
13-
"ios": "npm uninstall nativescript-grid-view && tns deploy ios"
12+
"android": "npm uninstall nativescript-grid-view && tns run android",
13+
"ios": "npm uninstall nativescript-grid-view && tns run ios --emulator"
1414
},
1515
"dependencies": {
16-
"tns-core-modules": "2.4.4",
17-
"nativescript-grid-view": "file:../bin/dist"
16+
"nativescript-grid-view": "file:../bin/dist",
17+
"tns-core-modules": "^2.5.0"
1818
},
1919
"devDependencies": {
2020
"babel-traverse": "6.21.0",
@@ -24,4 +24,4 @@
2424
"nativescript-dev-typescript": "0.3.5",
2525
"typescript": "2.1.4"
2626
}
27-
}
27+
}

grid-view.ios.ts

Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -217,89 +217,19 @@ export class GridView extends common.GridView {
217217

218218
//#region Styling
219219
export class GridViewStyler implements style.Styler {
220-
private static setSectionInset(gridView: GridView, padding: common.Padding) {
221-
let flowLayout = <UICollectionViewFlowLayout>gridView.ios.collectionViewLayout;
222-
let currentInset = flowLayout.sectionInset;
223-
224-
flowLayout.sectionInset = {
225-
top: padding.top !== undefined ? padding.top : currentInset.top,
226-
right: padding.right !== undefined ? padding.right : currentInset.right,
227-
bottom: padding.bottom !== undefined ? padding.bottom : currentInset.bottom,
228-
left: padding.left !== undefined ? padding.left : currentInset.left
229-
};
230-
}
231-
232-
//#region Padding Top Property
233-
private static setPaddingTop(gridView: GridView, newValue: number) {
234-
GridViewStyler.setSectionInset(gridView, { top: newValue });
220+
private static setNativePaddingsProperty(view: GridView, newValue: any) {
221+
(<UICollectionViewFlowLayout>view.ios.collectionViewLayout).sectionInset =
222+
UIEdgeInsetsFromString(`{${newValue.top},${newValue.left},${newValue.bottom},${newValue.right}}`);
235223
}
236-
private static resetPaddingTop(gridView: GridView, nativeValue: number) {
237-
GridViewStyler.setPaddingTop(gridView, nativeValue);
238-
}
239-
private static getNativePaddingTopValue(gridView: GridView): any {
240-
return (<UICollectionViewFlowLayout>gridView.ios.collectionViewLayout).sectionInset.top;
241-
}
242-
//#endregion
243224

244-
//#region Padding Right Property
245-
private static setPaddingRight(gridView: GridView, newValue: number) {
246-
GridViewStyler.setSectionInset(gridView, { right: newValue });
247-
}
248-
private static resetPaddingRight(gridView: GridView, nativeValue: number) {
249-
GridViewStyler.setPaddingRight(gridView, nativeValue);
250-
}
251-
private static getNativePaddingRightValue(gridView: GridView): any {
252-
return (<UICollectionViewFlowLayout>gridView.ios.collectionViewLayout).sectionInset.right;
253-
}
254-
//#endregion
255-
256-
//#region Padding Bottom Property
257-
private static setPaddingBottom(gridView: GridView, newValue: number) {
258-
GridViewStyler.setSectionInset(gridView, { bottom: newValue });
259-
}
260-
private static resetPaddingBottom(gridView: GridView, nativeValue: number) {
261-
GridViewStyler.setPaddingBottom(gridView, nativeValue);
262-
}
263-
private static getNativePaddingBottomValue(gridView: GridView): any {
264-
return (<UICollectionViewFlowLayout>gridView.ios.collectionViewLayout).sectionInset.bottom;
225+
private static resetNativePaddingsProperty(view: GridView, nativeValue: any) {
226+
(<UICollectionViewFlowLayout>view.ios.collectionViewLayout).sectionInset = UIEdgeInsetsFromString("{0,0,0,0}");
265227
}
266-
//#endregion
267-
268-
//#region Padding Left Property
269-
private static setPaddingLeft(gridView: GridView, newValue: number) {
270-
GridViewStyler.setSectionInset(gridView, { left: newValue });
271-
}
272-
private static resetPaddingLeft(gridView: GridView, nativeValue: number) {
273-
GridViewStyler.setPaddingLeft(gridView, nativeValue);
274-
}
275-
private static getNativePaddingLeftValue(gridView: GridView): any {
276-
return (<UICollectionViewFlowLayout>gridView.ios.collectionViewLayout).sectionInset.left;
277-
}
278-
//#endregion
279228

280229
public static registerHandlers() {
281-
style.registerHandler(style.paddingTopProperty,
282-
new style.StylePropertyChangedHandler(GridViewStyler.setPaddingTop,
283-
GridViewStyler.resetPaddingTop,
284-
GridViewStyler.getNativePaddingTopValue),
285-
"GridView");
286-
287-
style.registerHandler(style.paddingRightProperty,
288-
new style.StylePropertyChangedHandler(GridViewStyler.setPaddingRight,
289-
GridViewStyler.resetPaddingRight,
290-
GridViewStyler.getNativePaddingRightValue),
291-
"GridView");
292-
293-
style.registerHandler(style.paddingBottomProperty,
294-
new style.StylePropertyChangedHandler(GridViewStyler.setPaddingBottom,
295-
GridViewStyler.resetPaddingBottom,
296-
GridViewStyler.getNativePaddingBottomValue),
297-
"GridView");
298-
299-
style.registerHandler(style.paddingLeftProperty,
300-
new style.StylePropertyChangedHandler(GridViewStyler.setPaddingLeft,
301-
GridViewStyler.resetPaddingLeft,
302-
GridViewStyler.getNativePaddingLeftValue),
230+
style.registerHandler(style.nativePaddingsProperty,
231+
new style.StylePropertyChangedHandler(GridViewStyler.setNativePaddingsProperty,
232+
GridViewStyler.resetNativePaddingsProperty),
303233
"GridView");
304234
}
305235

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "nativescript-grid-view",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "A NativeScript GridView widget.",
55
"main": "grid-view",
66
"typings": "grid-view.d.ts",
77
"nativescript": {
88
"platforms": {
9-
"ios": "2.3.0",
10-
"android": "2.3.0"
9+
"ios": "2.5.0",
10+
"android": "2.5.0"
1111
}
1212
},
1313

@@ -28,8 +28,8 @@
2828
"devDependencies": {
2929
"typescript": "2.1.4",
3030
"tslint": "4.2.0",
31-
"tns-core-modules-declarations": "2.3.1",
32-
"tns-platform-declarations": "2.3.0",
31+
"tns-core-modules-declarations": "2.5.0",
32+
"tns-platform-declarations": "2.5.2",
3333

3434
"grunt": "0.4.5",
3535
"grunt-tslint": "4.0.0",

references.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
/// <reference path="node_modules/tns-core-modules-declarations/tns-core-modules.d.ts" />
88
/// <reference path="node_modules/tns-core-modules-declarations/lib.dom.d.ts" />
99

10-
/// <reference path="node_modules/tns-platform-declarations/tns-core-modules/android17.d.ts" />
11-
/// <reference path="node_modules/tns-platform-declarations/tns-core-modules/ios/ios.d.ts" />
10+
/// <reference path="node_modules/tns-platform-declarations/android/android17.d.ts" />
11+
/// <reference path="node_modules/tns-platform-declarations/ios/ios.d.ts" />

0 commit comments

Comments
 (0)