Skip to content

Commit edcbd66

Browse files
committed
android core 3 impl
1 parent f41866a commit edcbd66

40 files changed

+2261
-539
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ obj
5252
!gruntfile.js
5353
node_modules
5454
*.tmp.*
55-
platforms
55+
demo/platforms
5656
demo/lib

README.md

Lines changed: 47 additions & 28 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)
@@ -79,19 +79,19 @@ Note that this is the minimum space to be left horizontally between items. It mi
7979
* **ios** - *[UICollectionView](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/)*
8080
Gets the native iOS view that represents the user interface for this component. Valid only when running on iOS.
8181

82-
* **android** - *[android.widget.GridView](http://developer.android.com/guide/topics/ui/layout/gridview.html)*
82+
* **android** - *[android.support.v7.widget.RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html)*
8383
Gets the native android widget that represents the user interface for this component. Valid only when running on Android OS.
8484

85-
* **items** - *Object*
85+
* **items** - *Array | ItemsSource*
8686
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.
8787

8888
* **itemTemplate** - *String*
8989
Gets or sets the item template of the GridView.
9090

91-
* **rowHeight** - *Number*
91+
* **rowHeight** - *PercentLength*
9292
Gets or sets the height for every row in the GridView.
9393

94-
* **colWidth** - *Number*
94+
* **colWidth** - *PercentLength*
9595
Gets or sets the width for every column in the GridView.
9696

9797
### Instance Methods
@@ -103,10 +103,9 @@ Forces the GridView to reload all its items.
103103
<!-- test-page.xml -->
104104
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:gv="nativescript-grid-view" loaded="pageLoaded">
105105
<GridLayout>
106-
<gv:GridView items="{{ items }}" verticalSpacing="5" horizontalSpacing="5" colWidth="100" rowHeight="75" padding="5"
107-
itemTap="gridViewItemTap" itemLoading="gridViewItemLoading" loadMoreItems="gridViewLoadMoreItems">
106+
<gv:GridView items="{{ items }}" colWidth="25%" rowHeight="15%" padding="5" itemTap="gridViewItemTap" itemLoading="gridViewItemLoading" loadMoreItems="gridViewLoadMoreItems">
108107
<gv:GridView.itemTemplate>
109-
<GridLayout backgroundColor="#33ffff">
108+
<GridLayout backgroundColor="#33ffff" style="margin: 5">
110109
<Label text="{{ value }}" verticalAlignment="center"/>
111110
</GridLayout>
112111
</gv:GridView.itemTemplate>
@@ -117,41 +116,61 @@ Forces the GridView to reload all its items.
117116

118117
```TypeScript
119118
// 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");
119+
import { EventData, Observable } from "data/observable";
120+
import { ObservableArray } from "data/observable-array";
121+
import { Page } from "ui/page";
125122

126-
var viewModel: observable.Observable;
123+
import { GridItemEventData } from "nativescript-grid-view";
127124

128-
export function pageLoaded(args: observable.EventData)
129-
{
130-
var page = <pages.Page>args.object;
131-
var items = new observableArray.ObservableArray();
125+
let viewModel: Observable;
132126

133-
for (var loop = 0; loop < 200; loop++)
134-
{
127+
export function pageLoaded(args: EventData) {
128+
const page = args.object as Page;
129+
const items = new ObservableArray();
130+
131+
for (let loop = 0; loop < 200; loop++) {
135132
items.push({ value: "test " + loop.toString() });
136133
}
137-
viewModel = new observable.Observable();
134+
viewModel = new Observable();
138135
viewModel.set("items", items);
139136

140137
page.bindingContext = viewModel;
141138
}
142139

143-
export function gridViewItemTap(args: gridView.GridItemEventData)
144-
{
140+
export function gridViewItemTap(args: GridItemEventData) {
145141
console.log("tap index " + args.index.toString());
146142
}
147143

148-
export function gridViewItemLoading(args: gridView.GridItemEventData)
149-
{
150-
console.log("item loading " + args.index.toString())
144+
export function gridViewItemLoading(args: GridItemEventData) {
145+
console.log("item loading " + args.index.toString());
151146
}
152147

153-
export function gridViewLoadMoreItems(args: observable.EventData)
154-
{
148+
export function gridViewLoadMoreItems(args: EventData) {
155149
console.log("load more items");
156150
}
157151
```
152+
153+
## Working with Webpack+Uglify
154+
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:
155+
```js
156+
var gridViewMangleExcludes = require("nativescript-grid-view/uglify-mangle-excludes").default;
157+
//......
158+
module.exports = function (platform, destinationApp) {
159+
//......
160+
if (process.env.npm_config_uglify) {
161+
plugins.push(new webpack.LoaderOptionsPlugin({
162+
minimize: true
163+
}));
164+
165+
//Work around an Android issue by setting compress = false
166+
var compress = platform !== "android";
167+
plugins.push(new webpack.optimize.UglifyJsPlugin({
168+
mangle: {
169+
except: nsWebpack.uglifyMangleExcludes.concat(gridViewMangleExcludes),
170+
},
171+
compress: compress,
172+
}));
173+
}
174+
//......
175+
}
176+
```

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

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

100644100755
File mode changed.
9.95 KB
Loading

0 commit comments

Comments
 (0)