@@ -59,14 +59,18 @@ const ScrollableTabView = React.createClass({
5959 currentPage : this . props . initialPage ,
6060 scrollValue : new Animated . Value ( this . props . initialPage ) ,
6161 containerWidth : Dimensions . get ( 'window' ) . width ,
62- sceneKeys : this . newSceneKeys ( [ ] , this . props . initialPage ) ,
62+ sceneKeys : this . newSceneKeys ( { currentPage : this . props . initialPage , } ) ,
6363 } ;
6464 } ,
6565
6666 componentWillReceiveProps ( props ) {
6767 if ( props . page >= 0 && props . page !== this . state . currentPage ) {
6868 this . goToPage ( props . page ) ;
6969 }
70+
71+ if ( props . children !== this . props . children ) {
72+ this . updateSceneKeys ( { page : this . state . currentPage , children : props . children , } ) ;
73+ }
7074 } ,
7175
7276 goToPage ( pageNumber ) {
@@ -87,7 +91,7 @@ const ScrollableTabView = React.createClass({
8791 }
8892 }
8993
90- this . updateSceneKeys ( pageNumber ) ;
94+ this . updateSceneKeys ( { page : pageNumber , } ) ;
9195 } ,
9296
9397 renderTabBar ( props ) {
@@ -100,16 +104,16 @@ const ScrollableTabView = React.createClass({
100104 }
101105 } ,
102106
103- updateSceneKeys ( page , callback ) {
104- let newKeys = this . newSceneKeys ( this . state . sceneKeys , page ) ;
107+ updateSceneKeys ( { page, children = this . props . children , callback = ( ) => { } , } ) {
108+ let newKeys = this . newSceneKeys ( { previousKeys : this . state . sceneKeys , currentPage : page , children , } ) ;
105109 this . setState ( { currentPage : page , sceneKeys : newKeys , } , callback ) ;
106110 } ,
107111
108- newSceneKeys ( sceneKeys = [ ] , currentPage ) {
112+ newSceneKeys ( { previousKeys = [ ] , currentPage = 0 , children = this . props . children , } ) {
109113 let newKeys = [ ] ;
110- this . _children ( ) . forEach ( ( child , idx ) => {
114+ this . _children ( children ) . forEach ( ( child , idx ) => {
111115 let key = this . _makeSceneKey ( child , idx ) ;
112- if ( this . _keyExists ( sceneKeys , key ) || currentPage === idx ) {
116+ if ( this . _keyExists ( previousKeys , key ) || currentPage === idx ) {
113117 newKeys . push ( key ) ;
114118 }
115119 } ) ;
@@ -202,9 +206,10 @@ const ScrollableTabView = React.createClass({
202206 localCurrentPage = currentPage . nativeEvent . position ;
203207 }
204208
205- this . updateSceneKeys ( localCurrentPage , ( ) => {
209+ const callback = ( ) => {
206210 this . props . onChangeTab ( { i : localCurrentPage , ref : this . _children ( ) [ localCurrentPage ] , } ) ;
207- } ) ;
211+ } ;
212+ this . updateSceneKeys ( { page : localCurrentPage , callback, } , ) ;
208213 } ,
209214
210215 _updateScrollValue ( value ) {
@@ -223,8 +228,8 @@ const ScrollableTabView = React.createClass({
223228 }
224229 } ,
225230
226- _children ( ) {
227- return React . Children . map ( this . props . children , ( child ) => child ) ;
231+ _children ( children = this . props . children ) {
232+ return React . Children . map ( children , ( child ) => child ) ;
228233 } ,
229234
230235 render ( ) {
0 commit comments