@@ -39,6 +39,7 @@ const ScrollableTabView = React.createClass({
39
39
scrollWithoutAnimation : PropTypes . bool ,
40
40
locked : PropTypes . bool ,
41
41
prerenderingSiblingsNumber : PropTypes . number ,
42
+ collapsableBar : PropTypes . node ,
42
43
} ,
43
44
44
45
getDefaultProps ( ) {
@@ -179,12 +180,20 @@ const ScrollableTabView = React.createClass({
179
180
_composeScenes ( ) {
180
181
return this . _children ( ) . map ( ( child , idx ) => {
181
182
let key = this . _makeSceneKey ( child , idx ) ;
183
+ let element ;
184
+
185
+ if ( ! ! this . props . collapsableBar ) {
186
+ element = this . state . currentPage === idx ? child : null ;
187
+ } else {
188
+ element = this . _keyExists ( this . state . sceneKeys , key ) ? child : < View tabLabel = { child . props . tabLabel } /> ;
189
+ }
190
+
182
191
return < SceneComponent
183
192
key = { child . key }
184
- shouldUpdated = { this . _shouldRenderSceneKey ( idx , this . state . currentPage ) }
185
- style = { { width : this . state . containerWidth , } }
193
+ shouldUpdated = { ! ! this . props . collapsableBar || this . _shouldRenderSceneKey ( idx , this . state . currentPage ) }
194
+ style = { { width : this . state . containerWidth , } }
186
195
>
187
- { this . _keyExists ( this . state . sceneKeys , key ) ? child : < View tabLabel = { child . props . tabLabel } /> }
196
+ { element }
188
197
</ SceneComponent > ;
189
198
} ) ;
190
199
} ,
@@ -216,6 +225,10 @@ const ScrollableTabView = React.createClass({
216
225
ref : this . _children ( ) [ currentPage ] ,
217
226
from : prevPage ,
218
227
} ) ;
228
+
229
+ if ( this . contentScrollDistance >= this . collapsableBarHeight ) {
230
+ this . contentView . scrollTo ( { x : 0 , y : this . collapsableBarHeight , animated : false , } ) ;
231
+ }
219
232
} ,
220
233
221
234
_handleLayout ( e ) {
@@ -233,6 +246,16 @@ const ScrollableTabView = React.createClass({
233
246
return React . Children . map ( children , ( child ) => child ) ;
234
247
} ,
235
248
249
+ renderCollapsableBar ( ) {
250
+ if ( ! this . props . collapsableBar ) {
251
+ return null ;
252
+ }
253
+
254
+ return React . cloneElement ( this . props . collapsableBar , {
255
+ onLayout : event => { this . collapsableBarHeight = event . nativeEvent . layout . height ; } ,
256
+ } ) ;
257
+ } ,
258
+
236
259
render ( ) {
237
260
let overlayTabs = ( this . props . tabBarPosition === 'overlayTop' || this . props . tabBarPosition === 'overlayBottom' ) ;
238
261
let tabBarProps = {
@@ -267,12 +290,18 @@ const ScrollableTabView = React.createClass({
267
290
[ this . props . tabBarPosition === 'overlayTop' ? 'top' : 'bottom' ] : 0 ,
268
291
} ;
269
292
}
270
-
271
- return < View style = { [ styles . container , this . props . style , ] } onLayout = { this . _handleLayout } >
293
+ const ContainerView = this . props . collapsableBar ? ScrollView : View ;
294
+
295
+ return < ContainerView style = { [ styles . container , this . props . style , ] }
296
+ onLayout = { this . _handleLayout }
297
+ ref = { contentView => { this . contentView = contentView ; } }
298
+ onMomentumScrollEnd = { event => { this . contentScrollDistance = event . nativeEvent . contentOffset . y ; } }
299
+ stickyHeaderIndices = { this . props . collapsableBar ? [ 1 , ] : [ ] } >
300
+ { this . renderCollapsableBar ( ) }
272
301
{ this . props . tabBarPosition === 'top' && this . renderTabBar ( tabBarProps ) }
273
302
{ this . renderScrollableContent ( ) }
274
303
{ ( this . props . tabBarPosition === 'bottom' || overlayTabs ) && this . renderTabBar ( tabBarProps ) }
275
- </ View > ;
304
+ </ ContainerView > ;
276
305
} ,
277
306
} ) ;
278
307
0 commit comments