@@ -5,6 +5,7 @@ import Carousel from '@itenl/react-native-snap-carousel';
55import HocComponent from './HocComponent' ;
66import _throttle from 'lodash.throttle' ;
77import packagejson from '../package.json' ;
8+ import { initScreen , triggerOnce , refreshMap , onRefresh , triggerRefresh , onEndReached , triggerEndReached } from './useRefreshEndReached' ;
89const deviceWidth = Dimensions . get ( 'window' ) . width ;
910
1011const AnimatedSectionList = Animated . createAnimatedComponent ( SectionList ) ;
@@ -231,9 +232,14 @@ export default class ScrollableTabView extends React.Component {
231232 return (
232233 props . stacks &&
233234 props . stacks . map ( ( item , index ) => {
234- if ( item . screen && ! item . screen . __HOCNAME__ ) {
235- this . _makeStacksID ( item ) ;
236- item . screen = HocComponent ( item . screen , this . _setCurrentRef ( index , item . __id__ ) , index ) ;
235+ if ( item . screen ) {
236+ if ( this . isClassCompoent ( item . screen ) && ! item . screen . __HOCNAME__ ) {
237+ this . _makeStacksID ( item ) ;
238+ item . screen = HocComponent ( item . screen , this . _setCurrentRef ( index , item . __id__ ) ) ;
239+ } else {
240+ this . _makeStacksID ( item ) ;
241+ triggerOnce ( item . screen , this . _setCurrentRef ( index , item . __id__ ) ) ;
242+ }
237243 }
238244 return item ;
239245 } )
@@ -287,12 +293,11 @@ export default class ScrollableTabView extends React.Component {
287293 */
288294 _scrollTo = y => {
289295 if ( typeof y == 'number' ) {
290- this . section &&
291- this . section . scrollToLocation &&
292- this . section . scrollToLocation ( {
293- itemIndex : 0 ,
294- viewOffset : 0 - y
295- } ) ;
296+ this . section ?. scrollToLocation ( {
297+ itemIndex : 0 ,
298+ viewOffset : 0 - y ,
299+ sectionIndex : 0
300+ } ) ;
296301 }
297302 } ;
298303
@@ -320,14 +325,24 @@ export default class ScrollableTabView extends React.Component {
320325 this . setState ( { } ) ;
321326 } ;
322327
323- _getProps ( props ) {
328+ _getProps ( props , screen ) {
324329 return Object . assign (
325330 {
326331 refresh : this . _refresh ,
327332 scrollTo : this . _scrollTo ,
328333 toTabView : this . toTabView ,
329334 layoutHeight : this . layoutHeight
330335 } ,
336+ ! ! screen && {
337+ initScreen : ( ) => initScreen ( screen ) ,
338+ onRefresh : callback => {
339+ if ( ! screen . onRefresh ) {
340+ screen . onRefresh = ( ) => callback ( this . _toggledRefreshing ) ;
341+ }
342+ onRefresh ( screen , callback ) ;
343+ } ,
344+ onEndReached : callback => onEndReached ( screen , callback )
345+ } ,
331346 props || { }
332347 ) ;
333348 }
@@ -337,7 +352,7 @@ export default class ScrollableTabView extends React.Component {
337352 const ref = this . getCurrentRef ( ) ;
338353 if ( stacks && stacks . sticky && typeof stacks . sticky == 'function' && ref && stacks . __id__ === ref . __id__ ) {
339354 // 用于自动同步 Screen 数据流改变后仅会 render 自身 Screen 的问题,用于自动同步 screenContext 给吸顶组件
340- if ( this . props . syncToSticky && ! ref . __isOverride__ ) {
355+ if ( this . props . syncToSticky && ! ref . __isOverride__ && this . isClassCompoent ( ref . constructor ) ) {
341356 const originalDidUpdate = ref . componentDidUpdate ,
342357 context = this ;
343358 ref . componentDidUpdate = function ( ) {
@@ -437,7 +452,7 @@ export default class ScrollableTabView extends React.Component {
437452 return < Animated . View style = { [ styles . tabUnderlineStyle , _tabUnderlineStyle , interpolateAnimated ] } > </ Animated . View > ;
438453 }
439454
440- _displayConsole ( message , level = CONSOLE_LEVEL . WARN ) {
455+ _displayConsole ( message , level = CONSOLE_LEVEL . LOG ) {
441456 const { errorToThrow } = this . props ;
442457 const pluginName = packagejson . name ;
443458 const msg = `${ pluginName } : ${ message || ' --- ' } ` ;
@@ -569,6 +584,10 @@ export default class ScrollableTabView extends React.Component {
569584 return this . layoutHeight [ 'container' ] - this . layoutHeight [ 'stickyHeader' ] - this . layoutHeight [ 'tabs' ] ;
570585 }
571586
587+ isClassCompoent ( component ) {
588+ return ! ! ( component . prototype && component . prototype . isReactComponent ) ;
589+ }
590+
572591 _renderItem ( { item, index } ) {
573592 const { enableCachePage, fillScreen, fixedTabs, mappingProps } = this . props ;
574593 const screenHeight = this . _getScreenHeight ( ) ;
@@ -585,7 +604,7 @@ export default class ScrollableTabView extends React.Component {
585604 ! enableCachePage && this . state . checkedIndex == index && { minHeight : screenHeight }
586605 ] }
587606 >
588- < item . screen { ...this . _getProps ( mappingProps ) } { ...( item . toProps || { } ) } />
607+ < item . screen { ...this . _getProps ( mappingProps , ! this . isClassCompoent ( item . screen ) && item . screen ) } { ...( item . toProps || { } ) } />
589608 </ View >
590609 )
591610 ) ;
@@ -595,7 +614,7 @@ export default class ScrollableTabView extends React.Component {
595614 const next = ( ) => {
596615 const ref = this . getCurrentRef ( ) ;
597616 ! ref && this . _displayConsole ( `The Screen Ref is lost when calling onEndReached. Please confirm whether the Stack is working properly.(index: ${ this . state . checkedIndex } )` ) ;
598- if ( ref && ref . onEndReached && typeof ref . onEndReached === 'function' ) ref . onEndReached ( ) ;
617+ ! ! ref && this . isClassCompoent ( ref . constructor ) ? ref && ref . onEndReached && typeof ref . onEndReached === 'function' && ref . onEndReached ( ) : triggerEndReached ( ref ) ;
599618 } ;
600619 if ( this . state . checkedIndex != null ) {
601620 const { onBeforeEndReached } = this . props ;
@@ -613,7 +632,11 @@ export default class ScrollableTabView extends React.Component {
613632 const next = ( ) => {
614633 const ref = this . getCurrentRef ( ) ;
615634 ! ref && this . _displayConsole ( `The Screen Ref is lost when calling onRefresh. Please confirm whether the Stack is working properly.(index: ${ this . state . checkedIndex } )` ) ;
616- ref ? ref . onRefresh && typeof ref . onRefresh === 'function' && ref . onRefresh ( this . _toggledRefreshing ) : this . _toggledRefreshing ( false ) ;
635+ if ( ref ) {
636+ this . isClassCompoent ( ref . constructor ) ? ref . onRefresh && typeof ref . onRefresh === 'function' && ref . onRefresh ( this . _toggledRefreshing ) : triggerRefresh ( ref , this . _toggledRefreshing ) ;
637+ } else {
638+ this . _toggledRefreshing ( false ) ;
639+ }
617640 } ;
618641 const { onBeforeRefresh } = this . props ;
619642 onBeforeRefresh && typeof onBeforeRefresh === 'function' ? onBeforeRefresh ( next , this . _toggledRefreshing ) : next ( ) ;
@@ -676,7 +699,8 @@ export default class ScrollableTabView extends React.Component {
676699
677700 _refreshControl ( ) {
678701 const ref = this . getCurrentRef ( ) ;
679- return < RefreshControl enabled = { ! ! ( ref && ref . onRefresh ) } refreshing = { this . state . isRefreshing } onRefresh = { this . _onRefresh } /> ;
702+ const enabled = ! ! ( ref && ref . onRefresh ) || refreshMap . has ( ref ) ;
703+ return < RefreshControl enabled = { enabled } refreshing = { this . state . isRefreshing } onRefresh = { this . _onRefresh } /> ;
680704 }
681705
682706 _onScroll2Vertical ( event ) {
@@ -740,7 +764,6 @@ export default class ScrollableTabView extends React.Component {
740764 renderItem = { ( ) => {
741765 return (
742766 < AnimatedCarousel
743- ref = { c => ( this . tabview = c ) }
744767 pagingEnabled = { true }
745768 inactiveSlideOpacity = { 1 }
746769 inactiveSlideScale = { 1 }
@@ -749,7 +772,6 @@ export default class ScrollableTabView extends React.Component {
749772 sliderWidth = { deviceWidth }
750773 itemWidth = { deviceWidth }
751774 onScrollIndexChanged = { this . _throttleCallback }
752- initialScrollIndex = { this . state . checkedIndex }
753775 firstItem = { this . state . checkedIndex }
754776 onScroll = { this . _onScrollHandler2Horizontal }
755777 { ...carouselProps }
0 commit comments