@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
***************************************************************************** */
16
16
17
- import { ContentView } from "ui/content-view" ;
18
17
import { KeyedTemplate , Length , View } from "ui/core/view" ;
18
+ import { GridLayout } from "ui/layouts/grid-layout" ;
19
19
import * as utils from "utils/utils" ;
20
20
21
21
import {
@@ -24,7 +24,7 @@ import {
24
24
itemTemplatesProperty ,
25
25
orientationProperty ,
26
26
paddingBottomProperty ,
27
- paddingLeftProperty ,
27
+ paddingLeftProperty ,
28
28
paddingRightProperty ,
29
29
paddingTopProperty ,
30
30
rowHeightProperty ,
@@ -34,6 +34,9 @@ import { GridItemEventData, Orientation, ScrollEventData } from ".";
34
34
35
35
export * from "./grid-view-common" ;
36
36
37
+ // Used to designate a view as as a DUMMY created view (to cope with angular view generation)
38
+ const DUMMY = "DUMMY" ;
39
+
37
40
export class GridView extends GridViewBase {
38
41
public nativeView : android . support . v7 . widget . RecyclerView ;
39
42
public _realizedItems = new Map < android . view . View , View > ( ) ;
@@ -83,7 +86,7 @@ export class GridView extends GridViewBase {
83
86
} ) ;
84
87
this . _realizedItems . clear ( ) ;
85
88
86
- const nativeView = this . nativeView as any ;
89
+ const nativeView = this . nativeView as any ;
87
90
this . nativeView . removeOnScrollListener ( nativeView . scrollListener ) ;
88
91
89
92
nativeView . scrollListener = null ;
@@ -180,10 +183,10 @@ export class GridView extends GridViewBase {
180
183
let spanCount : number ;
181
184
182
185
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 ;
184
187
}
185
188
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 ;
187
190
}
188
191
189
192
layoutManager . setSpanCount ( spanCount ) ;
@@ -199,12 +202,12 @@ export class GridView extends GridViewBase {
199
202
this . nativeView . scrollToPosition ( index ) ;
200
203
}
201
204
}
202
-
205
+
203
206
private _setPadding ( newPadding : { top ?: number , right ?: number , bottom ?: number , left ?: number } ) {
204
207
const nativeView : android . view . View = this . nativeView as any ;
205
208
const padding = {
206
209
top : nativeView . getPaddingTop ( ) ,
207
- right : nativeView . getPaddingRight ( ) ,
210
+ right : nativeView . getPaddingRight ( ) ,
208
211
bottom : nativeView . getPaddingBottom ( ) ,
209
212
left : nativeView . getPaddingLeft ( )
210
213
} ;
@@ -224,7 +227,7 @@ export class GridView extends GridViewBase {
224
227
}
225
228
226
229
// Snapshot friendly GridViewScrollListener
227
- interface GridViewScrollListener extends android . support . v7 . widget . RecyclerView . OnScrollListener {
230
+ interface GridViewScrollListener extends android . support . v7 . widget . RecyclerView . OnScrollListener {
228
231
// tslint:disable-next-line:no-misused-new
229
232
new ( owner : WeakRef < GridView > ) : GridViewScrollListener ;
230
233
}
@@ -266,7 +269,7 @@ function initGridViewScrollListener() {
266
269
} ) ;
267
270
}
268
271
}
269
-
272
+
270
273
}
271
274
272
275
public onScrollStateChanged ( view : android . support . v7 . widget . RecyclerView , newState : number ) {
@@ -275,7 +278,7 @@ function initGridViewScrollListener() {
275
278
}
276
279
277
280
GridViewScrollListener = GridViewScrollListenerImpl as any ;
278
- }
281
+ }
279
282
// END snapshot friendly GridViewScrollListener
280
283
281
284
// Snapshot friendly GridViewAdapter
@@ -319,13 +322,13 @@ function initGridViewAdapter() {
319
322
ios : undefined ,
320
323
} ) ;
321
324
}
322
-
325
+
323
326
}
324
327
325
328
class GridViewAdapterImpl extends android . support . v7 . widget . RecyclerView . Adapter {
326
329
constructor ( private owner : WeakRef < GridView > ) {
327
330
super ( ) ;
328
-
331
+
329
332
return global . __native ( this ) ;
330
333
}
331
334
@@ -357,7 +360,7 @@ function initGridViewAdapter() {
357
360
const owner = this . owner . get ( ) ;
358
361
const template = owner . _getItemTemplate ( index ) ;
359
362
const itemViewType = owner . _itemTemplatesInternal . indexOf ( template ) ;
360
-
363
+
361
364
return itemViewType ;
362
365
}
363
366
@@ -367,7 +370,8 @@ function initGridViewAdapter() {
367
370
let view = template . createView ( ) ;
368
371
369
372
if ( ! view ) {
370
- view = new ContentView ( ) ;
373
+ view = new GridLayout ( ) ;
374
+ view [ DUMMY ] = true ;
371
375
}
372
376
373
377
owner . _addView ( view ) ;
@@ -383,29 +387,33 @@ function initGridViewAdapter() {
383
387
eventName : GridViewBase . itemLoadingEvent ,
384
388
object : owner ,
385
389
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 ,
387
394
android : vh ,
388
395
ios : undefined ,
389
396
} ;
390
397
owner . notify ( args ) ;
391
398
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 ;
394
402
}
395
-
403
+
396
404
if ( owner . orientation === "horizontal" ) {
397
405
vh . view . width = utils . layout . toDeviceIndependentPixels ( owner . _effectiveColWidth ) ;
398
406
}
399
407
else {
400
408
vh . view . height = utils . layout . toDeviceIndependentPixels ( owner . _effectiveRowHeight ) ;
401
409
}
402
-
410
+
403
411
owner . _prepareItem ( vh . view , index ) ;
404
412
}
405
413
}
406
414
407
415
GridViewAdapter = GridViewAdapterImpl as any ;
408
- }
416
+ }
409
417
// END Snapshot friendly GridViewAdapter
410
418
411
419
// Snapshot friendly GridViewRecyclerView
@@ -435,9 +443,9 @@ function initGridViewRecyclerView() {
435
443
}
436
444
super . onLayout ( changed , l , t , r , b ) ;
437
445
}
438
-
446
+
439
447
}
440
448
441
449
GridViewRecyclerView = GridViewRecyclerViewImpl as any ;
442
- }
450
+ }
443
451
// END Snapshot friendly GridViewRecyclerView
0 commit comments