Skip to content

Commit acd4365

Browse files
committed
fix #51
1 parent 3db81a0 commit acd4365

File tree

4 files changed

+73
-65
lines changed

4 files changed

+73
-65
lines changed

demo-ng/package-lock.json

+30-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo-ng/package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"nativescript": {
33
"id": "com.tangrainc.nggridviewsample",
4-
"tns-android": {
4+
"tns-ios": {
55
"version": "5.1.0"
66
},
7-
"tns-ios": {
7+
"tns-android": {
88
"version": "5.1.0"
99
}
1010
},
@@ -18,16 +18,16 @@
1818
"build-ios-bundle": "npm run ns-bundle --ios --build-app"
1919
},
2020
"dependencies": {
21-
"@angular/animations": "~7.1.0",
22-
"@angular/common": "~7.1.0",
23-
"@angular/compiler": "~7.1.0",
24-
"@angular/core": "~7.1.0",
25-
"@angular/forms": "~7.1.0",
26-
"@angular/http": "~7.1.0",
27-
"@angular/platform-browser": "~7.1.0",
28-
"@angular/platform-browser-dynamic": "~7.1.0",
29-
"@angular/router": "~7.1.0",
30-
"nativescript-angular": "^7.1.0",
21+
"@angular/animations": "~7.2.0",
22+
"@angular/common": "~7.2.0",
23+
"@angular/compiler": "~7.2.0",
24+
"@angular/core": "~7.2.0",
25+
"@angular/forms": "~7.2.0",
26+
"@angular/http": "~7.2.0",
27+
"@angular/platform-browser": "~7.2.0",
28+
"@angular/platform-browser-dynamic": "~7.2.0",
29+
"@angular/router": "~7.2.0",
30+
"nativescript-angular": "^7.2.3",
3131
"nativescript-grid-view": "file:../bin/dist",
3232
"nativescript-theme-core": "^1.0.4",
3333
"reflect-metadata": "~0.1.8",

grid-view.android.ts

+30-22
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
***************************************************************************** */
1616

17-
import { ContentView } from "ui/content-view";
1817
import { KeyedTemplate, Length, View } from "ui/core/view";
18+
import { GridLayout } from "ui/layouts/grid-layout";
1919
import * as utils from "utils/utils";
2020

2121
import {
@@ -24,7 +24,7 @@ import {
2424
itemTemplatesProperty,
2525
orientationProperty,
2626
paddingBottomProperty,
27-
paddingLeftProperty,
27+
paddingLeftProperty,
2828
paddingRightProperty,
2929
paddingTopProperty,
3030
rowHeightProperty,
@@ -34,6 +34,9 @@ import { GridItemEventData, Orientation, ScrollEventData } from ".";
3434

3535
export * from "./grid-view-common";
3636

37+
// Used to designate a view as as a DUMMY created view (to cope with angular view generation)
38+
const DUMMY = "DUMMY";
39+
3740
export class GridView extends GridViewBase {
3841
public nativeView: android.support.v7.widget.RecyclerView;
3942
public _realizedItems = new Map<android.view.View, View>();
@@ -83,7 +86,7 @@ export class GridView extends GridViewBase {
8386
});
8487
this._realizedItems.clear();
8588

86-
const nativeView = this.nativeView as any;
89+
const nativeView = this.nativeView as any;
8790
this.nativeView.removeOnScrollListener(nativeView.scrollListener);
8891

8992
nativeView.scrollListener = null;
@@ -180,10 +183,10 @@ export class GridView extends GridViewBase {
180183
let spanCount: number;
181184

182185
if (this.orientation === "horizontal") {
183-
spanCount = Math.max(Math.floor(this._innerHeight / this._effectiveRowHeight), 1) || 1;
186+
spanCount = Math.max(Math.floor(this._innerHeight / this._effectiveRowHeight), 1) || 1;
184187
}
185188
else {
186-
spanCount = Math.max(Math.floor(this._innerWidth / this._effectiveColWidth), 1) || 1;
189+
spanCount = Math.max(Math.floor(this._innerWidth / this._effectiveColWidth), 1) || 1;
187190
}
188191

189192
layoutManager.setSpanCount(spanCount);
@@ -199,12 +202,12 @@ export class GridView extends GridViewBase {
199202
this.nativeView.scrollToPosition(index);
200203
}
201204
}
202-
205+
203206
private _setPadding(newPadding: { top?: number, right?: number, bottom?: number, left?: number }) {
204207
const nativeView: android.view.View = this.nativeView as any;
205208
const padding = {
206209
top: nativeView.getPaddingTop(),
207-
right: nativeView.getPaddingRight(),
210+
right: nativeView.getPaddingRight(),
208211
bottom: nativeView.getPaddingBottom(),
209212
left: nativeView.getPaddingLeft()
210213
};
@@ -224,7 +227,7 @@ export class GridView extends GridViewBase {
224227
}
225228

226229
// Snapshot friendly GridViewScrollListener
227-
interface GridViewScrollListener extends android.support.v7.widget.RecyclerView.OnScrollListener {
230+
interface GridViewScrollListener extends android.support.v7.widget.RecyclerView.OnScrollListener {
228231
// tslint:disable-next-line:no-misused-new
229232
new(owner: WeakRef<GridView>): GridViewScrollListener;
230233
}
@@ -266,7 +269,7 @@ function initGridViewScrollListener() {
266269
});
267270
}
268271
}
269-
272+
270273
}
271274

272275
public onScrollStateChanged(view: android.support.v7.widget.RecyclerView, newState: number) {
@@ -275,7 +278,7 @@ function initGridViewScrollListener() {
275278
}
276279

277280
GridViewScrollListener = GridViewScrollListenerImpl as any;
278-
}
281+
}
279282
// END snapshot friendly GridViewScrollListener
280283

281284
// Snapshot friendly GridViewAdapter
@@ -319,13 +322,13 @@ function initGridViewAdapter() {
319322
ios: undefined,
320323
});
321324
}
322-
325+
323326
}
324327

325328
class GridViewAdapterImpl extends android.support.v7.widget.RecyclerView.Adapter {
326329
constructor(private owner: WeakRef<GridView>) {
327330
super();
328-
331+
329332
return global.__native(this);
330333
}
331334

@@ -357,7 +360,7 @@ function initGridViewAdapter() {
357360
const owner = this.owner.get();
358361
const template = owner._getItemTemplate(index);
359362
const itemViewType = owner._itemTemplatesInternal.indexOf(template);
360-
363+
361364
return itemViewType;
362365
}
363366

@@ -367,7 +370,8 @@ function initGridViewAdapter() {
367370
let view = template.createView();
368371

369372
if (!view) {
370-
view = new ContentView();
373+
view = new GridLayout();
374+
view[DUMMY] = true;
371375
}
372376

373377
owner._addView(view);
@@ -383,29 +387,33 @@ function initGridViewAdapter() {
383387
eventName: GridViewBase.itemLoadingEvent,
384388
object: owner,
385389
index,
386-
view: vh.view,
390+
// This is needed as the angular view generation with a single template is done in the event handler
391+
// for this event (????). That;s why if we created above an empty StackLayout, we must send `null`
392+
// sp that the angular handler initializes the correct view.
393+
view: vh.view[DUMMY] ? null : vh.view,
387394
android: vh,
388395
ios: undefined,
389396
};
390397
owner.notify(args);
391398

392-
if (vh.view !== args.view && vh.view instanceof ContentView) {
393-
vh.view.content = args.view;
399+
if (vh.view[DUMMY]) {
400+
(vh.view as GridLayout).addChild(args.view);
401+
vh.view[DUMMY] = undefined;
394402
}
395-
403+
396404
if (owner.orientation === "horizontal") {
397405
vh.view.width = utils.layout.toDeviceIndependentPixels(owner._effectiveColWidth);
398406
}
399407
else {
400408
vh.view.height = utils.layout.toDeviceIndependentPixels(owner._effectiveRowHeight);
401409
}
402-
410+
403411
owner._prepareItem(vh.view, index);
404412
}
405413
}
406414

407415
GridViewAdapter = GridViewAdapterImpl as any;
408-
}
416+
}
409417
// END Snapshot friendly GridViewAdapter
410418

411419
// Snapshot friendly GridViewRecyclerView
@@ -435,9 +443,9 @@ function initGridViewRecyclerView() {
435443
}
436444
super.onLayout(changed, l, t, r, b);
437445
}
438-
446+
439447
}
440448

441449
GridViewRecyclerView = GridViewRecyclerViewImpl as any;
442-
}
450+
}
443451
// END Snapshot friendly GridViewRecyclerView

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-grid-view",
3-
"version": "5.0.0",
3+
"version": "5.1.0",
44
"description": "A NativeScript GridView widget.",
55
"main": "grid-view",
66
"typings": "grid-view.d.ts",

0 commit comments

Comments
 (0)