@@ -6,10 +6,19 @@ const STYLE_INNER = {position: 'relative', overflow: 'hidden', width: '100%', mi
6
6
const STYLE_ITEM = { position : 'absolute' , left : 0 , width : '100%' } ;
7
7
const DIRECTION_VERTICAL = 'vertical' ;
8
8
const DIRECTION_HORIZONTAL = 'horizontal' ;
9
+
9
10
const scrollProp = {
10
11
[ DIRECTION_VERTICAL ] : 'scrollTop' ,
11
12
[ DIRECTION_HORIZONTAL ] : 'scrollLeft' ,
12
13
} ;
14
+ const sizeProp = {
15
+ [ DIRECTION_VERTICAL ] : 'height' ,
16
+ [ DIRECTION_HORIZONTAL ] : 'width' ,
17
+ } ;
18
+ const positionProp = {
19
+ [ DIRECTION_VERTICAL ] : 'top' ,
20
+ [ DIRECTION_HORIZONTAL ] : 'left' ,
21
+ } ;
13
22
14
23
export default class VirtualList extends PureComponent {
15
24
static defaultProps = {
@@ -98,7 +107,7 @@ export default class VirtualList extends PureComponent {
98
107
99
108
if ( typeof itemSize === 'function' ) { return itemSize ( index ) ; }
100
109
101
- return ( Array . isArray ( itemSize ) ) ? itemSize [ index ] : itemSize ;
110
+ return Array . isArray ( itemSize ) ? itemSize [ index ] : itemSize ;
102
111
}
103
112
104
113
setOffset ( offset ) {
@@ -116,20 +125,20 @@ export default class VirtualList extends PureComponent {
116
125
}
117
126
118
127
getOffsetForIndex ( index , scrollToAlignment = this . props . scrollToAlignment ) {
119
- const { height } = this . props ;
128
+ const { scrollDirection } = this . props ;
120
129
121
130
return this . sizeAndPositionManager . getUpdatedOffsetForIndex ( {
122
131
align : scrollToAlignment ,
123
- containerSize : height ,
132
+ containerSize : this . props [ sizeProp [ scrollDirection ] ] ,
124
133
currentOffset : this . state && this . state . offset || 0 ,
125
134
targetIndex : index ,
126
135
} ) ;
127
136
}
128
137
129
138
getRowsForOffset ( offset ) {
130
- const { height , overscanCount, itemCount } = this . props ;
139
+ const { itemCount , overscanCount, scrollDirection } = this . props ;
131
140
let { start, stop} = this . sizeAndPositionManager . getVisibleRange ( {
132
- containerSize : height ,
141
+ containerSize : this . props [ sizeProp [ scrollDirection ] ] ,
133
142
offset,
134
143
} ) ;
135
144
@@ -145,12 +154,13 @@ export default class VirtualList extends PureComponent {
145
154
const style = this . _styleCache [ index ] ;
146
155
if ( style ) { return style ; }
147
156
157
+ const { scrollDirection} = this . props ;
148
158
const { size, offset} = this . sizeAndPositionManager . getSizeAndPositionForIndex ( index ) ;
149
159
150
160
return this . _styleCache [ index ] = {
151
161
...STYLE_ITEM ,
152
- height : size ,
153
- top : offset ,
162
+ [ sizeProp [ scrollDirection ] ] : size ,
163
+ [ positionProp [ scrollDirection ] ] : offset ,
154
164
} ;
155
165
}
156
166
cache = { } ;
@@ -183,7 +193,7 @@ export default class VirtualList extends PureComponent {
183
193
184
194
return (
185
195
< div ref = { this . _getRef } { ...props } onScroll = { this . handleScroll } style = { { ...STYLE_WRAPPER , ...style , height, width} } >
186
- < div style = { { ...STYLE_INNER , height : this . sizeAndPositionManager . getTotalSize ( ) } } >
196
+ < div style = { { ...STYLE_INNER , [ sizeProp [ scrollDirection ] ] : this . sizeAndPositionManager . getTotalSize ( ) } } >
187
197
{ rows }
188
198
</ div >
189
199
</ div >
0 commit comments