44[ ![ npm downloads] ( https://img.shields.io/npm/dt/nativescript-grid-view.svg )] ( https://www.npmjs.com/package/nativescript-grid-view )
55[ ![ npm] ( https://img.shields.io/npm/v/nativescript-grid-view.svg )] ( https://www.npmjs.com/package/nativescript-grid-view )
66
7- A NativeScript GridView widget. The GridView displays data in separate cells, each cell representing one data item. For iOS wraps up [ UICollectionView] ( https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/ ) and for Android wraps up [ GridView ] ( http ://developer.android.com/guide/topics/ui/layout/gridview .html)
7+ A NativeScript GridView widget. The GridView displays data in separate cells, each cell representing one data item. For iOS wraps up [ UICollectionView] ( https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/ ) and for Android wraps up [ RecyclerView ] ( https ://developer.android.com/reference/android/support/v7/widget/RecyclerView .html)
88
99## Screenshot
1010![ Screenshot of Android] ( https://raw.githubusercontent.com/PeterStaev/NativeScript-Grid-View/master/docs/screenshot.png )
@@ -55,43 +55,23 @@ String value used when hooking to itemTapEvent event.
5555* ** loadMoreItemsEvent** - * String*
5656String value used when hooking to itemTapEvent event.
5757
58- * ** itemsProperty** - * [ Property] ( http://docs.nativescript.org/ApiReference/ui/core/dependency-observable/Property.html ) *
59- Represents the observable property backing the items property of each GridView instance.
60-
61- * ** itemTemplateProperty** - * [ Property] ( http://docs.nativescript.org/ApiReference/ui/core/dependency-observable/Property.html ) *
62- Represents the item template property of each GridView instance.
63-
64- * ** colWidthProperty** - * [ Property] ( http://docs.nativescript.org/ApiReference/ui/core/dependency-observable/Property.html ) *
65- Represents the column width property for each column in the GridView instance.
66-
67- * ** rowHeightProperty** - * [ Property] ( http://docs.nativescript.org/ApiReference/ui/core/dependency-observable/Property.html ) *
68- Represents the row height property for each row in the GridView instance.
69-
70- * ** verticalSpacingProperty** - * [ Property] ( http://docs.nativescript.org/ApiReference/ui/core/dependency-observable/Property.html ) *
71- Represents the vertical spacing property between each item in the GridView instance.
72-
73- * ** horizontalSpacingProperty** - * [ Property] ( http://docs.nativescript.org/ApiReference/ui/core/dependency-observable/Property.html ) *
74- Represents the horizontal spacing property between each item in the GridView instance.
75- Note that this is the minimum space to be left horizontally between items. It might grow depending on screen and item size.
76-
77-
7858### Instance Properties
7959* ** ios** - * [ UICollectionView] ( https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/ ) *
8060Gets the native iOS view that represents the user interface for this component. Valid only when running on iOS.
8161
82- * ** android** - * [ android.widget.GridView ] ( http ://developer.android.com/guide/topics/ui/layout/gridview .html) *
62+ * ** android** - * [ android.support.v7. widget.RecyclerView ] ( https ://developer.android.com/reference/android/support/v7/widget/RecyclerView .html) *
8363Gets the native android widget that represents the user interface for this component. Valid only when running on Android OS.
8464
85- * ** items** - * Object *
65+ * ** items** - * Array | ItemsSource *
8666Gets or sets the items collection of the GridView. The items property can be set to an array or an object defining length and getItem(index) method.
8767
8868* ** itemTemplate** - * String*
8969Gets or sets the item template of the GridView.
9070
91- * ** rowHeight** - * Number *
71+ * ** rowHeight** - * PercentLength *
9272Gets or sets the height for every row in the GridView.
9373
94- * ** colWidth** - * Number *
74+ * ** colWidth** - * PercentLength *
9575Gets or sets the width for every column in the GridView.
9676
9777### Instance Methods
@@ -103,10 +83,9 @@ Forces the GridView to reload all its items.
10383<!-- test-page.xml -->
10484<Page xmlns =" http://schemas.nativescript.org/tns.xsd" xmlns : gv =" nativescript-grid-view" loaded =" pageLoaded" >
10585 <GridLayout >
106- <gv : GridView items =" {{ items }}" verticalSpacing =" 5" horizontalSpacing =" 5" colWidth =" 100" rowHeight =" 75" padding =" 5"
107- itemTap =" gridViewItemTap" itemLoading =" gridViewItemLoading" loadMoreItems =" gridViewLoadMoreItems" >
86+ <gv : GridView items =" {{ items }}" colWidth =" 24%" rowHeight =" 15%" padding =" 5" itemTap =" gridViewItemTap" itemLoading =" gridViewItemLoading" loadMoreItems =" gridViewLoadMoreItems" >
10887 <gv : GridView .itemTemplate>
109- <GridLayout backgroundColor =" #33ffff" >
88+ <GridLayout backgroundColor =" #33ffff" style = " margin: 5 " >
11089 <Label text =" {{ value }}" verticalAlignment =" center" />
11190 </GridLayout >
11291 </gv : GridView .itemTemplate>
@@ -117,41 +96,61 @@ Forces the GridView to reload all its items.
11796
11897``` TypeScript
11998// test-page.ts
120- /// <reference path = " ../node_modules/nativescript-grid-view/grid-view.d.ts" />
121- import observable = require (" data/observable" );
122- import observableArray = require (" data/observable-array" );
123- import pages = require (" ui/page" );
124- import gridView = require (" nativescript-grid-view" );
99+ import { EventData , Observable } from " data/observable" ;
100+ import { ObservableArray } from " data/observable-array" ;
101+ import { Page } from " ui/page" ;
125102
126- var viewModel : observable . Observable ;
103+ import { GridItemEventData } from " nativescript-grid-view " ;
127104
128- export function pageLoaded(args : observable .EventData )
129- {
130- var page = <pages .Page >args .object ;
131- var items = new observableArray .ObservableArray ();
105+ let viewModel: Observable ;
132106
133- for (var loop = 0 ; loop < 200 ; loop ++ )
134- {
107+ export function pageLoaded(args : EventData ) {
108+ const page = args .object as Page ;
109+ const items = new ObservableArray ();
110+
111+ for (let loop = 0 ; loop < 200 ; loop ++ ) {
135112 items .push ({ value: " test " + loop .toString () });
136113 }
137- viewModel = new observable . Observable ();
114+ viewModel = new Observable ();
138115 viewModel .set (" items" , items );
139116
140117 page .bindingContext = viewModel ;
141118}
142119
143- export function gridViewItemTap(args : gridView .GridItemEventData )
144- {
120+ export function gridViewItemTap(args : GridItemEventData ) {
145121 console .log (" tap index " + args .index .toString ());
146122}
147123
148- export function gridViewItemLoading(args : gridView .GridItemEventData )
149- {
150- console .log (" item loading " + args .index .toString ())
124+ export function gridViewItemLoading(args : GridItemEventData ) {
125+ console .log (" item loading " + args .index .toString ());
151126}
152127
153- export function gridViewLoadMoreItems(args : observable .EventData )
154- {
128+ export function gridViewLoadMoreItems(args : EventData ) {
155129 console .log (" load more items" );
156130}
157131```
132+
133+ ## Working with Webpack+Uglify
134+ In case you are uing webpack and also are minifying/uglifying your code, there are some specific names that should be excluded from the uglification for the widget to work properly. The GridView widget exports those and you need to add them to the mangle exclude option of the uglifyjs plugin in the ` webpack.common.js ` file:
135+ ``` js
136+ var gridViewMangleExcludes = require (" nativescript-grid-view/uglify-mangle-excludes" ).default ;
137+ // ......
138+ module .exports = function (platform , destinationApp ) {
139+ // ......
140+ if (process .env .npm_config_uglify ) {
141+ plugins .push (new webpack.LoaderOptionsPlugin ({
142+ minimize: true
143+ }));
144+
145+ // Work around an Android issue by setting compress = false
146+ var compress = platform !== " android" ;
147+ plugins .push (new webpack.optimize.UglifyJsPlugin ({
148+ mangle: {
149+ except: nsWebpack .uglifyMangleExcludes .concat (gridViewMangleExcludes),
150+ },
151+ compress: compress,
152+ }));
153+ }
154+ // ......
155+ }
156+ ```
0 commit comments