null is not an object (evaluating ‘this._sceneRefs[t].setNativeProps‘), stack:

错误日志如下:
com.facebook.react.common.JavascriptException: 
null is not an object (evaluating 'this._sceneRefs[t].setNativeProps'), stack:
产生

这是Android手机通过跑monkey出现的日志,日志提示很明确,this._sceneRefs[t].setNativeProps对象为空,或者不存在。
项目是用ReactNative+原生写的。

难点

这个错误处理不难,难的是,我需要知道这个错误是出现在什么地方。

处理过程
1. 找到出错的源码
01-19 21:11:48.496 E/AndroidRuntime(19759): com.facebook.react.common.JavascriptException: null is not an object (evaluating 'this._sceneRefs[t].setNativeProps'), stack:
01-19 21:11:48.496 E/AndroidRuntime(19759): _clearTransformations@2262:7353
01-19 21:11:48.496 E/AndroidRuntime(19759): _clearTransformations@-1

这句:_clearTransformations@2262:7353
知道index.android.bundle的2262行出现的问题,找到index.android.bundle处的代码如下:

__d(function(g,r,i,a,m,e,d){'use strict';var t=r(d[0])(r(d[1])),n=r(d[2]),s=(r(d[3]),n.NativeModules.AnimationsDebugModule),o=r(d[4]),u=r(d[5]),h=r(d[6]),c=r(d[7]),l=r(d[8]),p=r(d[9]),v=r(d[10]),f=r(d[11]),_=r(d[12]),S=r(d[13]),x=r(d[14]),I=r(d[15]),G=r(d[16]),b=r(d[17]),R=n.Dimensions.get('window').width,y=n.Dimensions.get('window').height,k={pointerEvents:'none',style:{top:y,bottom:-y,opacity:0}},C=0;function F(t){if(null===t||'object'!=typeof t)return String(t);var n='__navigatorRouteID';return t.hasOwnProperty(n)||Object.defineProperty(t,n,{enumerable:!1,configurable:!1,writable:!1,value:C++}),t[n]}var T={position:'absolute',overflow:'hidden',left:0,right:0,bottom:0,top:0},w={position:'absolute',left:0,right:0,bottom:0,top:0,transform:[{translateX:0},{translateY:0},{scaleX:1},{scaleY:1},{rotate:'0deg'},{skewX:'0deg'},{skewY:'0deg'}]},P=n.StyleSheet.create({container:{flex:1,overflow:'hidden'},defaultSceneStyle:w,baseScene:T,disabledScene:{top:y,bottom:-y},transitioner:{flex:1,backgroundColor:'transparent',overflow:'hidden'}}),A=['pop','jumpBack','jumpForward'],M=_({displayName:"Navigator",propTypes:{configureScene:b.func,renderScene:b.func.isRequired,initialRoute:b.object,initialRouteStack:b.arrayOf(b.object),onWillFocus:b.func,onDidFocus:b.func,navigationBar:b.node,navigator:b.object,sceneStyle:n.ViewPropTypes.style},statics:{BreadcrumbNavigationBar:h,NavigationBar:c,SceneConfigs:l},mixins:[f,o,v.Mixin],getDefaultProps:function(){return{configureScene:function(){return l.PushFromRight},sceneStyle:w}},getInitialState:function(){var t=this;this._navigationBarNavigator=this.props.navigationBarNavigator||this,this._renderedSceneMap=new Map,this._sceneRefs=[];var n=this.props.initialRouteStack||[this.props.initialRoute];x(n.length>=1,'Navigator requires props.initialRoute or props.initialRouteStack.');var s=n.length-1;return this.props.initialRoute&&(s=n.indexOf(this.props.initialRoute),x(-1!==s,'initialRoute is not in initialRouteStack.')),{sceneConfigStack:n.map(function(s){return t.props.configureScene(s,n)}),routeStack:n,presentedIndex:s,transitionFromIndex:null,activeGesture:null,pendingGestureProgress:null,transitionQueue:[]}},componentWillMount:function(){var t=this;this.__defineGetter__('navigationContext',this._getNavigationContext),this._subRouteFocus=[],this.parentNavigator=this.props.navigator,this._handlers={},this.springSystem=new I.SpringSystem,this.spring=this.springSystem.createSpring(),this.spring.setRestSpeedThreshold(.05),this.spring.setCurrentValue(0).setAtRest(),this.spring.addListener({onSpringEndStateChange:function(){t._interactionHandle||(t._interactionHandle=t.createInteractionHandle())},onSpringUpdate:function(){t._handleSpringUpdate()},onSpringAtRest:function(){t._completeTransition()}}),this.panGesture=n.PanResponder.create({onMoveShouldSetPanResponder:this._handleMoveShouldSetPanResponder,onPanResponderRelease:this._handlePanResponderRelease,onPanResponderMove:this._handlePanResponderMove,onPanResponderTerminate:this._handlePanResponderTerminate}),this._interactionHandle=null,this._emitWillFocus(this.state.routeStack[this.state.presentedIndex])},componentDidMount:function(){this._isMounted=!0,this._handleSpringUpdate(),this._emitDidFocus(this.state.routeStack[this.state.presentedIndex]),this._enableTVEventHandler()},componentWillUnmount:function(){this._isMounted=!1,this._navigationContext&&(this._navigationContext.dispose(),this._navigationContext=null),this.spring.destroy(),this._interactionHandle&&this.clearInteractionHandle(this._interactionHandle),this._disableTVEventHandler()},immediatelyResetRouteStack:function(t){var n=this,s=t.length-1;this._emitWillFocus(t[s]),this.setState({routeStack:t,sceneConfigStack:t.map(function(s){return n.props.configureScene(s,t)}),presentedIndex:s,activeGesture:null,transitionFromIndex:null,transitionQueue:[]},function(){n._handleSpringUpdate();var t=n._navBar;t&&t.immediatelyRefresh&&t.immediatelyRefresh(),n._emitDidFocus(n.state.routeStack[n.state.presentedIndex])})},_transitionTo:function(t,n,o,u){if(this.state.presentedIndex!==t)if(null===this.state.transitionFromIndex){this.state.transitionFromIndex=this.state.presentedIndex,this.state.presentedIndex=t,this.state.transitionCb=u,this._onAnimationStart(),s&&s.startRecordingFps();var h=this.state.sceneConfigStack[this.state.transitionFromIndex]||this.state.sceneConfigStack[this.state.presentedIndex];x(h,'Cannot configure scene at index '+this.state.transitionFromIndex),null!=o&&this.spring.setCurrentValue(o),this.spring.setOvershootClampingEnabled(!0),this.spring.getSpringConfig().friction=h.springFriction,this.spring.getSpringConfig().tension=h.springTension,this.spring.setVelocity(n||h.defaultTransitionVelocity),this.spring.setEndValue(1)}else this.state.transitionQueue.push({destIndex:t,velocity:n,cb:u});else u&&u()},_handleSpringUpdate:function(){if(this._isMounted)if(null!=this.state.transitionFromIndex)this._transitionBetween(this.state.transitionFromIndex,this.state.presentedIndex,this.spring.getCurrentValue());else if(null!=this.state.activeGesture){var t=this.state.presentedIndex+this._deltaForGestureAction(this.state.activeGesture);this._transitionBetween(this.state.presentedIndex,t,this.spring.getCurrentValue())}},_completeTransition:function(){if(this._isMounted)if(1===this.spring.getCurrentValue()||0===this.spring.getCurrentValue()){this._onAnimationEnd();var t=this.state.presentedIndex,n=this._subRouteFocus[t]||this.state.routeStack[t];if(s&&s.stopRecordingFps(Date.now()),this.state.transitionFromIndex=null,this.spring.setCurrentValue(0).setAtRest(),this._hideScenes(),this.state.transitionCb&&(this.state.transitionCb(),this.state.transitionCb=null),this._emitDidFocus(n),this._interactionHandle&&(this.clearInteractionHandle(this._interactionHandle),this._interactionHandle=null),this.state.pendingGestureProgress){var o=this.state.presentedIndex+this._deltaForGestureAction(this.state.activeGesture);return this._enableScene(o),void this.spring.setEndValue(this.state.pendingGestureProgress)}if(this.state.transitionQueue.length){var u=this.state.transitionQueue.shift();this._enableScene(u.destIndex),this._emitWillFocus(this.state.routeStack[u.destIndex]),this._transitionTo(u.destIndex,u.velocity,null,u.cb)}}else this.state.pendingGestureProgress&&(this.state.pendingGestureProgress=null)},_emitDidFocus:function(t){this.navigationContext.emit('didfocus',{route:t}),this.props.onDidFocus&&this.props.onDidFocus(t)},_emitWillFocus:function(t){this.navigationContext.emit('willfocus',{route:t});var n=this._navBar;n&&n.handleWillFocus&&n.handleWillFocus(t),this.props.onWillFocus&&this.props.onWillFocus(t)},_hideScenes:function(){var t=null;this.state.activeGesture&&(t=this.state.presentedIndex+this._deltaForGestureAction(this.state.activeGesture));for(var n=0;n<this.state.routeStack.length;n++)n!==this.state.presentedIndex&&n!==this.state.transitionFromIndex&&n!==t&&this._disableScene(n)},_disableScene:function(t){this._sceneRefs[t]&&this._sceneRefs[t].setNativeProps(k)},_enableScene:function(t){var n=G([T,this.props.sceneStyle]),s={pointerEvents:'auto',style:{top:n.top,bottom:n.bottom}};t!==this.state.transitionFromIndex&&t!==this.state.presentedIndex&&(s.style.opacity=0),this._sceneRefs[t]&&this._sceneRefs[t].setNativeProps(s)},_clearTransformations:function(t){var n=G([w]);this._sceneRefs[t].setNativeProps({style:n})},_onAnimationStart:function(){var t=this.state.presentedIndex,n=this.state.presentedIndex;null!=this.state.transitionFromIndex?t=this.state.transitionFromIndex:this.state.activeGesture&&(n=this.state.presentedIndex+this._deltaForGestureAction(this.state.activeGesture)),this._setRenderSceneToHardwareTextureAndroid(t,!0),this._setRenderSceneToHardwareTextureAndroid(n,!0);var s=this._navBar;s&&s.onAnimationStart&&s.onAnimationStart(t,n)},_onAnimationEnd:function(){for(var t=this.state.routeStack.length-1,n=0;n<=t;n++)this._setRenderSceneToHardwareTextureAndroid(n,!1);var s=this._navBar;s&&s.onAnimationEnd&&s.onAnimationEnd()},_setRenderSceneToHardwareTextureAndroid:function(t,n){var s=this._sceneRefs[t];null!==s&&void 0!==s&&s.setNativeProps({renderToHardwareTextureAndroid:n})},_handleTouchStart:function(){this._eligibleGestures=A},_handleMoveShouldSetPanResponder:function(t,n){var s=this.state.sceneConfigStack[this.state.presentedIndex];return!!s&&(this._expectingGestureGrant=this._matchGestureAction(this._eligibleGestures,s.gestures,n),!!this._expectingGestureGrant)},_doesGestureOverswipe:function(t){var n=this.state.presentedIndex<=0&&('pop'===t||'jumpBack'===t);return this.state.presentedIndex>=this.state.routeStack.length-1&&'jumpForward'===t||n},_deltaForGestureAction:function(t){switch(t){case'pop':case'jumpBack':return-1;case'jumpForward':return 1;default:return void x(!1,'Unsupported gesture action '+t)}},_handlePanResponderRelease:function(t,n){var s=this,o=this.state.sceneConfigStack[this.state.presentedIndex],u=this.state.activeGesture;if(u){var h=o.gestures[u],c=this.state.presentedIndex+this._deltaForGestureAction(this.state.activeGesture);if(0===this.spring.getCurrentValue())return this.spring.setCurrentValue(0).setAtRest(),void this._completeTransition();var l,p,v='top-to-bottom'===h.direction||'bottom-to-top'===h.direction,f='right-to-left'===h.direction||'bottom-to-top'===h.direction;v?(l=f?-n.vy:n.vy,p=f?-n.dy:n.dy):(l=f?-n.vx:n.vx,p=f?-n.dx:n.dx);var _=S(-10,l,10);if(Math.abs(l)<h.notMoving)_=p>h.fullDistance*h.stillCompletionRatio?h.snapVelocity:-h.snapVelocity;if(_<0||this._doesGestureOverswipe(u)){if(null==this.state.transitionFromIndex){var x=this.state.presentedIndex;this.state.presentedIndex=c,this._transitionTo(x,-_,1-this.spring.getCurrentValue())}}else this._emitWillFocus(this.state.routeStack[c]),this._transitionTo(c,_,null,function(){'pop'===u&&s._cleanScenesPastIndex(c)});this._detachGesture()}},_handlePanResponderTerminate:function(t,n){if(null!=this.state.activeGesture){var s=this.state.presentedIndex+this._deltaForGestureAction(this.state.activeGesture);this._detachGesture();var o=this.state.presentedIndex;this.state.presentedIndex=s,this._transitionTo(o,null,1-this.spring.getCurrentValue())}},_attachGesture:function(t){this.state.activeGesture=t;var n=this.state.presentedIndex+this._deltaForGestureAction(this.state.activeGesture);this._enableScene(n)},_detachGesture:function(){this.state.activeGesture=null,this.state.pendingGestureProgress=null,this._hideScenes()},_handlePanResponderMove:function(t,n){void 0!==this._isMoveGestureAttached&&(x(this._expectingGestureGrant,'Responder granted unexpectedly.'),this._attachGesture(this._expectingGestureGrant),this._onAnimationStart(),this._expectingGestureGrant=void 0);var s=this.state.sceneConfigStack[this.state.presentedIndex];if(this.state.activeGesture){var o=s.gestures[this.state.activeGesture];return this._moveAttachedGesture(o,n)}var u=this._matchGestureAction(A,s.gestures,n);u&&this._attachGesture(u)},_moveAttachedGesture:function(t,n){var s='top-to-bottom'===t.direction||'bottom-to-top'===t.direction,o='right-to-left'===t.direction||'bottom-to-top'===t.direction,u=s?n.dy:n.dx;u=o?-u:u;var h=t.gestureDetectMovement,c=(u-h)/(t.fullDistance-h);if(c<0&&t.isDetachable){var l=this.state.presentedIndex+this._deltaForGestureAction(this.state.activeGesture);return this._transitionBetween(this.state.presentedIndex,l,0),this._detachGesture(),void(null!=this.state.pendingGestureProgress&&this.spring.setCurrentValue(0))}if(t.overswipe&&this._doesGestureOverswipe(this.state.activeGesture)){var p=t.overswipe.frictionConstant,v=t.overswipe.frictionByDistance;c*=1/(p+Math.abs(c)*v)}c=S(0,c,1),null!=this.state.transitionFromIndex?this.state.pendingGestureProgress=c:this.state.pendingGestureProgress?this.spring.setEndValue(c):this.spring.setCurrentValue(c)},_matchGestureAction:function(t,n,s){var o=this;if(!n||!t||!t.some)return null;var u=null;return t.some(function(t,h){var c=n[t];if(c){if(null==c.overswipe&&o._doesGestureOverswipe(t))return!1;var l='top-to-bottom'===c.direction||'bottom-to-top'===c.direction,p='right-to-left'===c.direction||'bottom-to-top'===c.direction,v=l?s.y0:s.x0,f=l?s.moveY:s.moveX,_=l?s.dy:s.dx,S=l?s.dx:s.dy,x=c.edgeHitWidth;if(p&&(v=-v,f=-f,_=-_,S=-S,x=l?-(y-x):-(R-x)),0===v&&(v=f),!(null==c.edgeHitWidth||v<x))return!1;if(!(_>=c.gestureDetectMovement))return!1;if(Math.abs(_)>Math.abs(S)*c.directionRatio)return u=t,!0;o._eligibleGestures=o._eligibleGestures.slice().splice(h,1)}}),u||null},_transitionSceneStyle:function(t,n,s,o){var u=this._sceneRefs[o];if(null!==u&&void 0!==u){var h=t<n?n:t,c=this.state.sceneConfigStack[h];c||(c=this.state.sceneConfigStack[h-1]);var l={};(o<t||o<n?c.animationInterpolators.out:c.animationInterpolators.into)(l,t<n?s:1-s)&&u.setNativeProps({style:l})}},_transitionBetween:function(t,n,s){this._transitionSceneStyle(t,n,s,t),this._transitionSceneStyle(t,n,s,n);var o=this._navBar;o&&o.updateProgress&&n>=0&&t>=0&&o.updateProgress(s,t,n)},_handleResponderTerminationRequest:function(){return!1},_getDestIndexWithinBounds:function(t){var n=this.state.presentedIndex+t;x(n>=0,'Cannot jump before the first route.');var s=this.state.routeStack.length-1;return x(s>=n,'Cannot jump past the last route.'),n},_jumpN:function(t){var n=this._getDestIndexWithinBounds(t);this._enableScene(n),this._emitWillFocus(this.state.routeStack[n]),this._transitionTo(n)},jumpTo:function(t){var n=this.state.routeStack.indexOf(t);x(-1!==n,'Cannot jump to route that is not in the route stack'),this._jumpN(n-this.state.presentedIndex)},jumpForward:function(){this._jumpN(1)},jumpBack:function(){this._jumpN(-1)},push:function(t){var n=this;x(!!t,'Must supply route to push');var s=this.state.presentedIndex+1,o=this.state.routeStack.slice(0,s),u=this.state.sceneConfigStack.slice(0,s),h=o.concat([t]),c=h.length-1,l=this.props.configureScene(t,h),p=u.concat([l]);this._emitWillFocus(h[c]),this.setState({routeStack:h,sceneConfigStack:p},function(){n._enableScene(c),n._transitionTo(c,l.defaultTransitionVelocity)})},popN:function(t){var n=this;if(x('number'==typeof t,'Must supply a number to popN'),!((t=parseInt(t,10))<=0||this.state.presentedIndex-t<0)){var s=this.state.presentedIndex-t,o=this.state.routeStack[this.state.presentedIndex],u=this.props.configureScene(o);this._enableScene(s),this._clearTransformations(s),this._emitWillFocus(this.state.routeStack[s]),this._transitionTo(s,u.defaultTransitionVelocity,null,function(){n._cleanScenesPastIndex(s)})}},pop:function(){this.state.transitionQueue.length||this.popN(1)},replaceAtIndex:function(t,n,s){var o=this;if(x(!!t,'Must supply route to replace'),n<0&&(n+=this.state.routeStack.length),!(this.state.routeStack.length<=n)){var u=this.state.routeStack.slice(),h=this.state.sceneConfigStack.slice();u[n]=t,h[n]=this.props.configureScene(t,u),n===this.state.presentedIndex&&this._emitWillFocus(t),this.setState({routeStack:u,sceneConfigStack:h},function(){n===o.state.presentedIndex&&o._emitDidFocus(t),s&&s()})}},replace:function(t){this.replaceAtIndex(t,this.state.presentedIndex)},replacePrevious:function(t){this.replaceAtIndex(t,this.state.presentedIndex-1)},popToTop:function(){this.popToRoute(this.state.routeStack[0])},popToRoute:function(t){var n=this.state.routeStack.indexOf(t);x(-1!==n,'Calling popToRoute for a route that doesn\'t exist!');var s=this.state.presentedIndex-n;this.popN(s)},replacePreviousAndPop:function(t){this.state.routeStack.length<2||(this.replacePrevious(t),this.pop())},resetTo:function(t){var n=this;x(!!t,'Must supply route to push'),this.replaceAtIndex(t,0,function(){n.popN(n.state.presentedIndex)})},getCurrentRoutes:function(){return this.state.routeStack.slice()},_cleanScenesPastIndex:function(t){var n=t+1;n<this.state.routeStack.length&&this.setState({sceneConfigStack:this.state.sceneConfigStack.slice(0,n),routeStack:this.state.routeStack.slice(0,n)})},_renderScene:function(t,s){var o=this,u=null,h='auto';return s!==this.state.presentedIndex&&(u=P.disabledScene,h='none'),p.createElement(n.View,{collapsable:!1,key:'scene_'+F(t),ref:function(t){o._sceneRefs[s]=t},onStartShouldSetResponderCapture:function(){return null!=o.state.transitionFromIndex},pointerEvents:h,style:[P.baseScene,this.props.sceneStyle,u]},this.props.renderScene(t,this))},_renderNavigationBar:function(){var t=this,n=this.props.navigationBar;return n?p.cloneElement(n,{ref:function(s){t._navBar=s,n&&'function'==typeof n.ref&&n.ref(s)},navigator:this._navigationBarNavigator,navState:this.state}):null},_tvEventHandler:n.TVEventHandler,_enableTVEventHandler:function(){n.TVEventHandler&&(this._tvEventHandler=new n.TVEventHandler,this._tvEventHandler.enable(this,function(t,n){n&&'menu'===n.eventType&&t.pop()}))},_disableTVEventHandler:function(){this._tvEventHandler&&(this._tvEventHandler.disable(),delete this._tvEventHandler)},render:function(){var s=this,o=new Map,u=this.state.routeStack.map(function(t,n){var u;return u=s._renderedSceneMap.has(t)&&n!==s.state.presentedIndex?s._renderedSceneMap.get(t):s._renderScene(t,n),o.set(t,u),u});return this._renderedSceneMap=o,p.createElement(n.View,{style:[P.container,this.props.style]},p.createElement(n.View,(0,t.default)({style:P.transitioner},this.panGesture.panHandlers,{onTouchStart:this._handleTouchStart,onResponderTerminationRequest:this._handleResponderTerminationRequest}),u),this._renderNavigationBar())},_getNavigationContext:function(){return this._navigationContext||(this._navigationContext=new u),this._navigationContext}});m.exports=M},2251,[1,11,2,2252,2254,2255,2266,2275,2276,48,2277,840,2278,2281,2257,2282,2283,60]);
2.源码分析

源码很多,而且还是编译后的代码,说实话,我也没有什么捷径走,只能老牛耕田法,一点点的耙。
结果几十分钟的查找,我终于找到了这个源码里自己认识的东西,

eplace:function(t){this.replaceAtIndex(t,this.state.presentedIndex)}, replacePrevious:function(t){this.replaceAtIndex(t,this.state.presentedIndex-1)}, popToTop:function(){this.popToRoute(this.state.routeStack[0])}, popToRoute:function(t){var n=this.state.routeStack.indexOf(t);x(-1!==n,'Calling popToRoute for a route that doesn\'t exist!');

记录: 在分析编译后的源码的时候,一定要耐心,而且多留心源码里不会变的东西,比如,输出内容,方法名等等,这些东西都能成为很好的切入点。
通过分析上面的源码(popToRoute,popToTop),发现,这像是路由相关的代码,所以,去查找项目中的路由库,我用的是(react-native-deprecated-custom-components),
果然发现这部分代码所在:

popToRoute: function(route) { var indexOfRoute = this.state.routeStack.indexOf(route);
  invariant(
    indexOfRoute !== -1, 'Calling popToRoute for a route that doesn\'t exist!'  ); var numToPop = this.state.presentedIndex - indexOfRoute; this.popN(numToPop);
},

看到这里,其实基本可以确定,我没有找错门。
继续分析:
再查找问题代码:

_disableScene:function(t){this._sceneRefs[t]&&this._sceneRefs[t].setNativeProps(k)}, _enableScene:function(t){var n=G([T,this.props.sceneStyle]), s={pointerEvents:'auto',style:{top:n.top,bottom:n.bottom}};
t!==this.state.transitionFromIndex&&t!==this.state.presentedIndex&&(s.style.opacity=0), this._sceneRefs[t]&&this._sceneRefs[t].setNativeProps(s)}, _clearTransformations:function(t){var n=G([w]);this._sceneRefs[t].setNativeProps({style:n})},

找到对应的代码片段:

三个方法有调用这段问题代码,分别是

_disableScene,_enableScene_clearTransformations  
/**  * Push a scene off the screen, so that opacity:0 scenes will not block touches sent to the presented scenes  */ 
_disableScene: function(sceneIndex) { this._sceneRefs[sceneIndex] && this._sceneRefs[sceneIndex].setNativeProps(SCENE_DISABLED_NATIVE_PROPS);
}, 
/**  * Put the scene back into the state as defined by props.sceneStyle, so transitions can happen normally  */ 
_enableScene: function(sceneIndex) { // First, determine what the defined styles are for scenes in this navigator  var sceneStyle = flattenStyle([BASE_SCENE_STYLE, this.props.sceneStyle]); // Then restore the pointer events and top value for this scene  var enabledSceneNativeProps = {
    pointerEvents: 'auto',
    style: {
      top: sceneStyle.top,
      bottom: sceneStyle.bottom,
    },
  }; if (sceneIndex !== this.state.transitionFromIndex &&
      sceneIndex !== this.state.presentedIndex) { // If we are not in a transition from this index, make sure opacity is 0  // to prevent the enabled scene from flashing over the presented scene  enabledSceneNativeProps.style.opacity = 0;
  } this._sceneRefs[sceneIndex] && this._sceneRefs[sceneIndex].setNativeProps(enabledSceneNativeProps);
},

_clearTransformations: function(sceneIndex) { const defaultStyle = flattenStyle([DEFAULT_SCENE_STYLE]); this._sceneRefs[sceneIndex].setNativeProps({ style: defaultStyle });
},

编译前后的代码比对发现是吻合的,所以,可以判断我没找错地方。
最后回到解释报错的内容:是由于this._sceneRefs[t].setNativeProps为空或者不存在才报错的,所以解决办法是,修改这部分源码;

同时发现this._sceneRefs是在如下代码段中被赋值的:

_renderScene: function(route, i) { var disabledSceneStyle = null; var disabledScenePointerEvents = 'auto'; if (i !== this.state.presentedIndex) {
    disabledSceneStyle = styles.disabledScene;
    disabledScenePointerEvents = 'none';
  } return ( <View  collapsable={false}  key={'scene_' + getRouteID(route)}  ref={(scene) => { this._sceneRefs[i] = scene;
      }}  onStartShouldSetResponderCapture={() => { return (this.state.transitionFromIndex != null);
      }}  pointerEvents={disabledScenePointerEvents}  style={[styles.baseScene, this.props.sceneStyle, disabledSceneStyle]}> {this.props.renderScene(
        route, this  )} </View> );
},

而这里的_renderScene是在下面被定义的:

var scenes = this.state.routeStack.map((route, index) => { var renderedScene; if (this._renderedSceneMap.has(route) &&
      index !== this.state.presentedIndex) {
    renderedScene = this._renderedSceneMap.get(route);
  } else {
    renderedScene = this._renderScene(route, index);
  }
  newRenderedSceneMap.set(route, renderedScene); return renderedScene;
});

问题到这里其实就很明朗了。

this._renderedSceneMap.has(route) &&index !== this.state.presentedIndex

当上面这两个条件被满足的时候,就不会存在this._sceneRefs对象,所以也就可以理解,对象会不存在的异常了。

解决办法

如下,对这个对象的长度继续判断,源码修改如下:

 _disableScene: function(sceneIndex) { this._sceneRefs.length&&this._sceneRefs[sceneIndex] && this._sceneRefs[sceneIndex].setNativeProps(SCENE_DISABLED_NATIVE_PROPS);
}, 
_enableScene: function(sceneIndex) { // First, determine what the defined styles are for scenes in this navigator  var sceneStyle = flattenStyle([BASE_SCENE_STYLE, this.props.sceneStyle]); // Then restore the pointer events and top value for this scene  var enabledSceneNativeProps = {
    pointerEvents: 'auto',
    style: {
      top: sceneStyle.top,
      bottom: sceneStyle.bottom,
    },
  }; if (sceneIndex !== this.state.transitionFromIndex &&
      sceneIndex !== this.state.presentedIndex) { // If we are not in a transition from this index, make sure opacity is 0  // to prevent the enabled scene from flashing over the presented scene  enabledSceneNativeProps.style.opacity = 0;
  } this._sceneRefs.length&&this._sceneRefs[sceneIndex] && this._sceneRefs[sceneIndex].setNativeProps(enabledSceneNativeProps);
},
_clearTransformations: function(sceneIndex) { const defaultStyle = flattenStyle([DEFAULT_SCENE_STYLE]); this._sceneRefs.length&&this._sceneRefs[sceneIndex].setNativeProps({ style: defaultStyle });
},

重新打包跑monkey。

顺便记录下:
我使用的react-native-deprecated-custom-components库版本是:0.1.2
这库比较老,而且因为这是老项目,所以我也没去更新,解决这个问题就继续使用。
建议还是使用官方的库,我新项目也没再使用这个库。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值