@@ -28,6 +28,7 @@ export default class ScrollableTabView extends React.Component {
2828 firstIndex : PropTypes . number ,
2929 mappingProps : PropTypes . object ,
3030 header : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
31+ stickyHeader : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
3132 badges : PropTypes . array ,
3233 tabsStyle : PropTypes . object ,
3334 tabWrapStyle : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
@@ -69,6 +70,7 @@ export default class ScrollableTabView extends React.Component {
6970 firstIndex : null ,
7071 mappingProps : { } ,
7172 header : null ,
73+ stickyHeader : null ,
7274 badges : [ ] ,
7375 tabsStyle : { } ,
7476 tabWrapStyle : { } ,
@@ -118,7 +120,7 @@ export default class ScrollableTabView extends React.Component {
118120 this . _initial ( ) ;
119121 }
120122
121- componentWillReceiveProps ( newProps ) {
123+ UNSAFE_componentWillReceiveProps ( newProps ) {
122124 this . _initial ( newProps , true ) ;
123125 }
124126
@@ -141,6 +143,7 @@ export default class ScrollableTabView extends React.Component {
141143 this . layoutHeight = {
142144 container : 0 ,
143145 header : 0 ,
146+ stickyHeader : 0 ,
144147 tabs : 0 ,
145148 screen : 0
146149 } ;
@@ -285,6 +288,7 @@ export default class ScrollableTabView extends React.Component {
285288 _scrollTo = y => {
286289 if ( typeof y == 'number' ) {
287290 this . section &&
291+ this . section . scrollToLocation &&
288292 this . section . scrollToLocation ( {
289293 itemIndex : 0 ,
290294 viewOffset : 0 - y
@@ -331,7 +335,7 @@ export default class ScrollableTabView extends React.Component {
331335 _renderSticky ( ) {
332336 const stacks = this . props . stacks [ this . state . checkedIndex ] ;
333337 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__ ) {
335339 // 用于自动同步 Screen 数据流改变后仅会 render 自身 Screen 的问题,用于自动同步 screenContext 给吸顶组件
336340 if ( this . props . syncToSticky && ! ref . __isOverride__ ) {
337341 const originalDidUpdate = ref . componentDidUpdate ,
@@ -496,6 +500,7 @@ export default class ScrollableTabView extends React.Component {
496500 return (
497501 < View style = { { flex : 1 } } >
498502 { this . _renderHeader ( fixedHeader ) }
503+ { this . _renderStickyHeader ( ) }
499504 { this . _renderTabs ( ) }
500505 { this . _renderSticky ( ) }
501506 </ View >
@@ -524,7 +529,7 @@ export default class ScrollableTabView extends React.Component {
524529 if ( ! this . stacks [ index ] ) return ;
525530 const { enableCachePage, toHeaderOnTab, toTabsOnTab, onTabviewChanged } = this . props ;
526531 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' ] ) ) ;
528533 if ( ! isCarouselScroll && toTabsOnTab ) return this . _scrollTo ( 0 ) ;
529534 return void 0 ;
530535 }
@@ -556,12 +561,12 @@ export default class ScrollableTabView extends React.Component {
556561 }
557562
558563 _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'] ) ;
560565 return this . layoutHeight [ 'screen' ] ;
561566 }
562567
563568 _getMaximumScreenHeight ( ) {
564- return this . layoutHeight [ 'container' ] - this . layoutHeight [ 'tabs' ] ;
569+ return this . layoutHeight [ 'container' ] - this . layoutHeight [ 'stickyHeader' ] - this . layoutHeight [ ' tabs'] ;
565570 }
566571
567572 _renderItem ( { item, index } ) {
@@ -632,6 +637,23 @@ export default class ScrollableTabView extends React.Component {
632637 ) ;
633638 } ;
634639
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+
635657 _renderTitle = ( ) => {
636658 const { title, titleArgs } = this . props ;
637659 if ( ! title ) return null ;
@@ -720,6 +742,7 @@ export default class ScrollableTabView extends React.Component {
720742 < AnimatedCarousel
721743 ref = { c => ( this . tabview = c ) }
722744 pagingEnabled = { true }
745+ inactiveSlideOpacity = { 1 }
723746 inactiveSlideScale = { 1 }
724747 data = { this . stacks }
725748 renderItem = { this . _renderItem }
0 commit comments