@@ -28,6 +28,7 @@ export default class ScrollableTabView extends React.Component {
28
28
firstIndex : PropTypes . number ,
29
29
mappingProps : PropTypes . object ,
30
30
header : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
31
+ stickyHeader : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
31
32
badges : PropTypes . array ,
32
33
tabsStyle : PropTypes . object ,
33
34
tabWrapStyle : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
@@ -69,6 +70,7 @@ export default class ScrollableTabView extends React.Component {
69
70
firstIndex : null ,
70
71
mappingProps : { } ,
71
72
header : null ,
73
+ stickyHeader : null ,
72
74
badges : [ ] ,
73
75
tabsStyle : { } ,
74
76
tabWrapStyle : { } ,
@@ -118,7 +120,7 @@ export default class ScrollableTabView extends React.Component {
118
120
this . _initial ( ) ;
119
121
}
120
122
121
- componentWillReceiveProps ( newProps ) {
123
+ UNSAFE_componentWillReceiveProps ( newProps ) {
122
124
this . _initial ( newProps , true ) ;
123
125
}
124
126
@@ -141,6 +143,7 @@ export default class ScrollableTabView extends React.Component {
141
143
this . layoutHeight = {
142
144
container : 0 ,
143
145
header : 0 ,
146
+ stickyHeader : 0 ,
144
147
tabs : 0 ,
145
148
screen : 0
146
149
} ;
@@ -285,6 +288,7 @@ export default class ScrollableTabView extends React.Component {
285
288
_scrollTo = y => {
286
289
if ( typeof y == 'number' ) {
287
290
this . section &&
291
+ this . section . scrollToLocation &&
288
292
this . section . scrollToLocation ( {
289
293
itemIndex : 0 ,
290
294
viewOffset : 0 - y
@@ -331,7 +335,7 @@ export default class ScrollableTabView extends React.Component {
331
335
_renderSticky ( ) {
332
336
const stacks = this . props . stacks [ this . state . checkedIndex ] ;
333
337
const ref = this . getCurrentRef ( ) ;
334
- if ( stacks && stacks . sticky && typeof stacks . sticky == 'function' && ref ) {
338
+ if ( stacks && stacks . sticky && typeof stacks . sticky == 'function' && ref && stacks . __id__ === ref . __id__ ) {
335
339
// 用于自动同步 Screen 数据流改变后仅会 render 自身 Screen 的问题,用于自动同步 screenContext 给吸顶组件
336
340
if ( this . props . syncToSticky && ! ref . __isOverride__ ) {
337
341
const originalDidUpdate = ref . componentDidUpdate ,
@@ -496,6 +500,7 @@ export default class ScrollableTabView extends React.Component {
496
500
return (
497
501
< View style = { { flex : 1 } } >
498
502
{ this . _renderHeader ( fixedHeader ) }
503
+ { this . _renderStickyHeader ( ) }
499
504
{ this . _renderTabs ( ) }
500
505
{ this . _renderSticky ( ) }
501
506
</ View >
@@ -524,7 +529,7 @@ export default class ScrollableTabView extends React.Component {
524
529
if ( ! this . stacks [ index ] ) return ;
525
530
const { enableCachePage, toHeaderOnTab, toTabsOnTab, onTabviewChanged } = this . props ;
526
531
if ( index == this . state . checkedIndex ) {
527
- if ( ! isCarouselScroll && toHeaderOnTab ) return this . _scrollTo ( - this . layoutHeight [ 'header' ] ) ;
532
+ if ( ! isCarouselScroll && toHeaderOnTab ) return this . _scrollTo ( - ( this . layoutHeight [ 'header' ] + this . layoutHeight [ 'stickyHeader' ] ) ) ;
528
533
if ( ! isCarouselScroll && toTabsOnTab ) return this . _scrollTo ( 0 ) ;
529
534
return void 0 ;
530
535
}
@@ -556,12 +561,12 @@ export default class ScrollableTabView extends React.Component {
556
561
}
557
562
558
563
_getScreenHeight ( ) {
559
- this . layoutHeight [ 'screen' ] = this . layoutHeight [ 'container' ] - ( this . layoutHeight [ 'header' ] + this . layoutHeight [ 'tabs' ] ) ;
564
+ this . layoutHeight [ 'screen' ] = this . layoutHeight [ 'container' ] - ( this . layoutHeight [ 'header' ] + this . layoutHeight [ 'stickyHeader' ] + this . layoutHeight [ ' tabs'] ) ;
560
565
return this . layoutHeight [ 'screen' ] ;
561
566
}
562
567
563
568
_getMaximumScreenHeight ( ) {
564
- return this . layoutHeight [ 'container' ] - this . layoutHeight [ 'tabs' ] ;
569
+ return this . layoutHeight [ 'container' ] - this . layoutHeight [ 'stickyHeader' ] - this . layoutHeight [ ' tabs'] ;
565
570
}
566
571
567
572
_renderItem ( { item, index } ) {
@@ -632,6 +637,23 @@ export default class ScrollableTabView extends React.Component {
632
637
) ;
633
638
} ;
634
639
640
+ _renderStickyHeader = ( ) => {
641
+ const { stickyHeader } = this . props ;
642
+ return (
643
+ stickyHeader && (
644
+ < View
645
+ onLayout = { ( { nativeEvent } ) => {
646
+ const { height } = nativeEvent . layout ;
647
+ this . layoutHeight [ 'stickyHeader' ] = height ;
648
+ if ( height !== 0 ) this . _refresh ( ) ;
649
+ } }
650
+ >
651
+ { typeof stickyHeader === 'function' ? stickyHeader ( ) : stickyHeader }
652
+ </ View >
653
+ )
654
+ ) ;
655
+ } ;
656
+
635
657
_renderTitle = ( ) => {
636
658
const { title, titleArgs } = this . props ;
637
659
if ( ! title ) return null ;
@@ -720,6 +742,7 @@ export default class ScrollableTabView extends React.Component {
720
742
< AnimatedCarousel
721
743
ref = { c => ( this . tabview = c ) }
722
744
pagingEnabled = { true }
745
+ inactiveSlideOpacity = { 1 }
723
746
inactiveSlideScale = { 1 }
724
747
data = { this . stacks }
725
748
renderItem = { this . _renderItem }
0 commit comments