Skip to content

Commit a6360d7

Browse files
committed
Merge branch 'core3'
2 parents abe67f3 + 4955cb1 commit a6360d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2806
-846
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ obj
5252
!gruntfile.js
5353
node_modules
5454
*.tmp.*
55-
platforms
56-
demo/lib
55+
demo/platforms
56+
demo/lib
57+
!webpack.*.js

.vscode/tasks.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"taskName": "build",
1212
"args": [],
1313
"isBuildCommand": true,
14-
"problemMatcher": ["$tsc"]
14+
"problemMatcher": ["$tsc", {
15+
"base": "$tslint5",
16+
"fileLocation": "relative"
17+
}]
1518
}
1619
]
1720
}

README.md

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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*
5656
String 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/)*
8060
Gets 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)*
8363
Gets 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*
8666
Gets 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*
8969
Gets or sets the item template of the GridView.
9070

91-
* **rowHeight** - *Number*
71+
* **rowHeight** - *PercentLength*
9272
Gets or sets the height for every row in the GridView.
9373

94-
* **colWidth** - *Number*
74+
* **colWidth** - *PercentLength*
9575
Gets 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+
```

demo/.vscode/launch.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch on iOS",
6+
"type": "nativescript",
7+
"request": "launch",
8+
"platform": "ios",
9+
"appRoot": "${workspaceRoot}",
10+
"sourceMaps": true,
11+
"watch": true
12+
},
13+
{
14+
"name": "Attach on iOS",
15+
"type": "nativescript",
16+
"request": "attach",
17+
"platform": "ios",
18+
"appRoot": "${workspaceRoot}",
19+
"sourceMaps": true,
20+
"watch": false
21+
},
22+
{
23+
"name": "Launch on Android",
24+
"type": "nativescript",
25+
"request": "launch",
26+
"platform": "android",
27+
"appRoot": "${workspaceRoot}",
28+
"sourceMaps": true,
29+
"watch": true
30+
},
31+
{
32+
"name": "Attach on Android",
33+
"type": "nativescript",
34+
"request": "attach",
35+
"platform": "android",
36+
"appRoot": "${workspaceRoot}",
37+
"sourceMaps": true,
38+
"watch": false
39+
}
40+
]
41+
}

demo/app/App_Resources/Android/AndroidManifest.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@
2222
android:name="com.tns.NativeScriptApplication"
2323
android:allowBackup="true"
2424
android:icon="@drawable/icon"
25-
android:label="@string/app_name"
26-
android:theme="@style/AppTheme" >
25+
android:label="GridView"
26+
android:theme="@style/AppTheme">
27+
2728
<activity
2829
android:name="com.tns.NativeScriptActivity"
29-
android:label="@string/title_activity_kimera"
30-
android:configChanges="keyboardHidden|orientation|screenSize">
30+
android:configChanges="keyboardHidden|orientation|screenSize"
31+
android:theme="@style/LaunchScreenTheme">
3132

32-
<intent-filter>
33-
<action android:name="android.intent.action.MAIN" />
33+
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
3434

35+
<intent-filter>
36+
<action android:name="android.intent.action.MAIN" />
3537
<category android:name="android.intent.category.LAUNCHER" />
3638
</intent-filter>
3739
</activity>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Add your native dependencies here:
2+
3+
// Uncomment to add recyclerview-v7 dependency
4+
//dependencies {
5+
// compile 'com.android.support:recyclerview-v7:+'
6+
//}
7+
8+
android {
9+
defaultConfig {
10+
generatedDensities = []
11+
applicationId = "com.tangrainc.gridviewsample"
12+
}
13+
aaptOptions {
14+
additionalParameters "--no-version-vectors"
15+
}
16+
}
3.42 KB
Loading

demo/app/App_Resources/Android/drawable-hdpi/icon.png

100644100755
File mode changed.
32.4 KB
Loading
1.31 KB
Loading

0 commit comments

Comments
 (0)