@@ -32,103 +32,6 @@ export * from "./grid-view-common";
3232
3333const CELLIDENTIFIER = "gridcell" ;
3434
35- class GridViewCell extends UICollectionViewCell {
36- public static new ( ) : GridViewCell {
37- return super . new ( ) as GridViewCell ;
38- }
39- public static class ( ) : any {
40- return GridViewCell ;
41- }
42-
43- public owner : WeakRef < View > ;
44-
45- get view ( ) : View {
46- return this . owner ? this . owner . get ( ) : null ;
47- }
48- }
49-
50- class GridViewDataSource extends NSObject implements UICollectionViewDataSource {
51- public static ObjCProtocols = [ UICollectionViewDataSource ] ;
52-
53- public static initWithOwner ( owner : WeakRef < GridView > ) : GridViewDataSource {
54- const dataSource = GridViewDataSource . new ( ) as GridViewDataSource ;
55- dataSource . _owner = owner ;
56- return dataSource ;
57- }
58-
59- private _owner : WeakRef < GridView > ;
60-
61- public numberOfSectionsInCollectionView ( collectionView : UICollectionView ) {
62- return 1 ;
63- }
64-
65- public collectionViewNumberOfItemsInSection ( collectionView : UICollectionView , section : number ) {
66- const owner = this . _owner . get ( ) ;
67- return owner . items ? owner . items . length : 0 ;
68- }
69-
70- public collectionViewCellForItemAtIndexPath ( collectionView : UICollectionView , indexPath : NSIndexPath ) : UICollectionViewCell {
71- const owner = this . _owner . get ( ) ;
72- const cell : any = collectionView . dequeueReusableCellWithReuseIdentifierForIndexPath ( CELLIDENTIFIER , indexPath ) || GridViewCell . new ( ) ;
73-
74- owner . _prepareCell ( cell , indexPath ) ;
75-
76- const cellView : View = cell . view ;
77- if ( cellView ) {
78- View . layoutChild ( owner , cellView , 0 , 0 , owner . _effectiveColWidth , owner . _effectiveRowHeight ) ;
79- }
80-
81- return cell ;
82- }
83- }
84-
85- class UICollectionViewDelegateImpl extends NSObject implements UICollectionViewDelegate , UICollectionViewDelegateFlowLayout {
86- public static ObjCProtocols = [ UICollectionViewDelegate , UICollectionViewDelegateFlowLayout ] ;
87-
88- public static initWithOwner ( owner : WeakRef < GridView > ) : UICollectionViewDelegateImpl {
89- const delegate = UICollectionViewDelegateImpl . new ( ) as UICollectionViewDelegateImpl ;
90- delegate . _owner = owner ;
91- return delegate ;
92- }
93-
94- private _owner : WeakRef < GridView > ;
95-
96- public collectionViewWillDisplayCellForItemAtIndexPath ( collectionView : UICollectionView , cell : UICollectionViewCell , indexPath : NSIndexPath ) {
97- const owner = this . _owner . get ( ) ;
98-
99- if ( indexPath . row === owner . items . length - 1 ) {
100- owner . notify ( {
101- eventName : GridViewBase . loadMoreItemsEvent ,
102- object : owner
103- } as EventData ) ;
104- }
105-
106- if ( cell . preservesSuperviewLayoutMargins ) {
107- cell . preservesSuperviewLayoutMargins = false ;
108- }
109-
110- if ( cell . layoutMargins ) {
111- cell . layoutMargins = UIEdgeInsetsZero ;
112- }
113- }
114-
115- public collectionViewDidSelectItemAtIndexPath ( collectionView : UICollectionView , indexPath : NSIndexPath ) {
116- const cell = collectionView . cellForItemAtIndexPath ( indexPath ) ;
117- const owner = this . _owner . get ( ) ;
118-
119- owner . notify ( {
120- eventName : GridViewBase . itemTapEvent ,
121- object : owner ,
122- index : indexPath . row ,
123- view : ( cell as GridViewCell ) . view
124- } as GridItemEventData ) ;
125-
126- cell . highlighted = false ;
127-
128- return indexPath ;
129- }
130- }
131-
13235export class GridView extends GridViewBase {
13336 private _layout : UICollectionViewFlowLayout ;
13437 private _dataSource : GridViewDataSource ;
@@ -320,4 +223,99 @@ export class GridView extends GridViewBase {
320223 this . _layout . sectionInset =
321224 UIEdgeInsetsFromString ( `{${ newValue . top } ,${ newValue . left } ,${ newValue . bottom } ,${ newValue . right } }` ) ;
322225 }
226+ }
227+
228+ class GridViewCell extends UICollectionViewCell {
229+ public static new ( ) : GridViewCell {
230+ return super . new ( ) as GridViewCell ;
231+ }
232+ public static class ( ) : any {
233+ return GridViewCell ;
234+ }
235+
236+ public owner : WeakRef < View > ;
237+
238+ get view ( ) : View {
239+ return this . owner ? this . owner . get ( ) : null ;
240+ }
241+ }
242+
243+ @ObjCClass ( UICollectionViewDataSource )
244+ class GridViewDataSource extends NSObject implements UICollectionViewDataSource {
245+ public static initWithOwner ( owner : WeakRef < GridView > ) : GridViewDataSource {
246+ const dataSource = GridViewDataSource . new ( ) as GridViewDataSource ;
247+ dataSource . _owner = owner ;
248+ return dataSource ;
249+ }
250+
251+ private _owner : WeakRef < GridView > ;
252+
253+ public numberOfSectionsInCollectionView ( collectionView : UICollectionView ) {
254+ return 1 ;
255+ }
256+
257+ public collectionViewNumberOfItemsInSection ( collectionView : UICollectionView , section : number ) {
258+ const owner = this . _owner . get ( ) ;
259+ return owner . items ? owner . items . length : 0 ;
260+ }
261+
262+ public collectionViewCellForItemAtIndexPath ( collectionView : UICollectionView , indexPath : NSIndexPath ) : UICollectionViewCell {
263+ const owner = this . _owner . get ( ) ;
264+ const cell : any = collectionView . dequeueReusableCellWithReuseIdentifierForIndexPath ( CELLIDENTIFIER , indexPath ) || GridViewCell . new ( ) ;
265+
266+ owner . _prepareCell ( cell , indexPath ) ;
267+
268+ const cellView : View = cell . view ;
269+ if ( cellView ) {
270+ View . layoutChild ( owner , cellView , 0 , 0 , owner . _effectiveColWidth , owner . _effectiveRowHeight ) ;
271+ }
272+
273+ return cell ;
274+ }
275+ }
276+
277+ @ObjCClass ( UICollectionViewDelegate , UICollectionViewDelegateFlowLayout )
278+ class UICollectionViewDelegateImpl extends NSObject implements UICollectionViewDelegate , UICollectionViewDelegateFlowLayout {
279+ public static initWithOwner ( owner : WeakRef < GridView > ) : UICollectionViewDelegateImpl {
280+ const delegate = UICollectionViewDelegateImpl . new ( ) as UICollectionViewDelegateImpl ;
281+ delegate . _owner = owner ;
282+ return delegate ;
283+ }
284+
285+ private _owner : WeakRef < GridView > ;
286+
287+ public collectionViewWillDisplayCellForItemAtIndexPath ( collectionView : UICollectionView , cell : UICollectionViewCell , indexPath : NSIndexPath ) {
288+ const owner = this . _owner . get ( ) ;
289+
290+ if ( indexPath . row === owner . items . length - 1 ) {
291+ owner . notify ( {
292+ eventName : GridViewBase . loadMoreItemsEvent ,
293+ object : owner
294+ } as EventData ) ;
295+ }
296+
297+ if ( cell . preservesSuperviewLayoutMargins ) {
298+ cell . preservesSuperviewLayoutMargins = false ;
299+ }
300+
301+ if ( cell . layoutMargins ) {
302+ cell . layoutMargins = UIEdgeInsetsZero ;
303+ }
304+ }
305+
306+ public collectionViewDidSelectItemAtIndexPath ( collectionView : UICollectionView , indexPath : NSIndexPath ) {
307+ const cell = collectionView . cellForItemAtIndexPath ( indexPath ) ;
308+ const owner = this . _owner . get ( ) ;
309+
310+ owner . notify ( {
311+ eventName : GridViewBase . itemTapEvent ,
312+ object : owner ,
313+ index : indexPath . row ,
314+ view : ( cell as GridViewCell ) . view
315+ } as GridItemEventData ) ;
316+
317+ cell . highlighted = false ;
318+
319+ return indexPath ;
320+ }
323321}
0 commit comments