@@ -20,14 +20,15 @@ import * as utils from "utils/utils";
2020import {
2121 GridViewBase ,
2222 colWidthProperty ,
23+ orientationProperty ,
2324 paddingBottomProperty ,
2425 paddingLeftProperty ,
2526 paddingRightProperty ,
2627 paddingTopProperty ,
2728 rowHeightProperty ,
2829} from "./grid-view-common" ;
2930
30- import { GridItemEventData } from "." ;
31+ import { GridItemEventData , Orientation } from "." ;
3132
3233export * from "./grid-view-common" ;
3334
@@ -43,8 +44,11 @@ export class GridView extends GridViewBase {
4344 recyclerView . setAdapter ( adapter ) ;
4445 ( recyclerView as any ) . adapter = adapter ;
4546
47+ const orientation = this . _getLayoutManagarOrientation ( ) ;
48+
4649 const layoutManager = new android . support . v7 . widget . GridLayoutManager ( this . _context , 1 ) ;
4750 recyclerView . setLayoutManager ( layoutManager ) ;
51+ layoutManager . setOrientation ( orientation ) ;
4852 ( recyclerView as any ) . layoutManager = layoutManager ;
4953
5054 const scrollListener = new GridViewScrollListener ( new WeakRef ( this ) ) ;
@@ -120,6 +124,23 @@ export class GridView extends GridViewBase {
120124 this . _setPadding ( { left : this . effectivePaddingLeft } ) ;
121125 }
122126
127+ public [ orientationProperty . getDefault ] ( ) : Orientation {
128+ const layoutManager = this . nativeView . getLayoutManager ( ) as android . support . v7 . widget . GridLayoutManager ;
129+ if ( layoutManager . getOrientation ( ) === android . support . v7 . widget . LinearLayoutManager . HORIZONTAL ) {
130+ return "horizontal" ;
131+ }
132+
133+ return "vertical" ;
134+ }
135+ public [ orientationProperty . setNative ] ( value : Orientation ) {
136+ const layoutManager = this . nativeView . getLayoutManager ( ) as android . support . v7 . widget . GridLayoutManager ;
137+ if ( value === "horizontal" ) {
138+ layoutManager . setOrientation ( android . support . v7 . widget . LinearLayoutManager . HORIZONTAL ) ;
139+ } else {
140+ layoutManager . setOrientation ( android . support . v7 . widget . LinearLayoutManager . VERTICAL ) ;
141+ }
142+ }
143+
123144 public eachChildView ( callback : ( child : View ) => boolean ) : void {
124145 this . _realizedItems . forEach ( ( view , key ) => {
125146 callback ( view ) ;
@@ -137,9 +158,16 @@ export class GridView extends GridViewBase {
137158 }
138159
139160 const layoutManager = this . nativeView . getLayoutManager ( ) as android . support . v7 . widget . GridLayoutManager ;
140- const spanCount = Math . max ( Math . floor ( this . _innerWidth / this . _effectiveColWidth ) , 1 ) || 1 ;
161+ let spanCount : number ;
162+
163+ if ( this . orientation === "horizontal" ) {
164+ spanCount = Math . max ( Math . floor ( this . _innerHeight / this . _effectiveRowHeight ) , 1 ) || 1 ;
165+ } else {
166+ spanCount = Math . max ( Math . floor ( this . _innerWidth / this . _effectiveColWidth ) , 1 ) || 1 ;
167+ }
141168
142169 layoutManager . setSpanCount ( spanCount ) ;
170+
143171 this . nativeView . getAdapter ( ) . notifyDataSetChanged ( ) ;
144172 }
145173
@@ -163,6 +191,15 @@ export class GridView extends GridViewBase {
163191 const newValue = Object . assign ( padding , newPadding ) ;
164192 nativeView . setPadding ( newValue . left , newValue . top , newValue . right , newValue . bottom ) ;
165193 }
194+
195+ private _getLayoutManagarOrientation ( ) {
196+ let orientation = android . support . v7 . widget . LinearLayoutManager . VERTICAL ;
197+ if ( this . orientation === "horizontal" ) {
198+ orientation = android . support . v7 . widget . LinearLayoutManager . HORIZONTAL ;
199+ }
200+
201+ return orientation ;
202+ }
166203}
167204
168205class GridViewScrollListener extends android . support . v7 . widget . RecyclerView . OnScrollListener {
@@ -258,8 +295,12 @@ class GridViewAdapter extends android.support.v7.widget.RecyclerView.Adapter {
258295 index,
259296 view : vh . view
260297 } ) ;
261-
262- vh . view . height = utils . layout . toDeviceIndependentPixels ( owner . _effectiveRowHeight ) ;
298+
299+ if ( owner . orientation === "horizontal" ) {
300+ vh . view . width = utils . layout . toDeviceIndependentPixels ( owner . _effectiveColWidth ) ;
301+ } else {
302+ vh . view . height = utils . layout . toDeviceIndependentPixels ( owner . _effectiveRowHeight ) ;
303+ }
263304
264305 owner . _prepareItem ( vh . view , index ) ;
265306 }
0 commit comments