UNPKG

react-native-tab-view

Version:
2 lines 2.86 kB
import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/satya/Workspace/Projects/react-native-tab-view/src/SceneView.tsx";import*as React from'react';import{View,StyleSheet}from'react-native';var SceneView=function(_React$Component){_inherits(SceneView,_React$Component);function SceneView(){var _getPrototypeOf2;var _this;_classCallCheck(this,SceneView);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_possibleConstructorReturn(this,(_getPrototypeOf2=_getPrototypeOf(SceneView)).call.apply(_getPrototypeOf2,[this].concat(args)));_this.state={loading:Math.abs(_this.props.navigationState.index-_this.props.index)>_this.props.lazyPreloadDistance};_this.handleEnter=function(value){var index=_this.props.index;if(value===index&&_this.state.loading){_this.setState({loading:false});}};return _this;}_createClass(SceneView,[{key:"componentDidMount",value:function componentDidMount(){var _this2=this;if(this.props.lazy){this.props.addListener('enter',this.handleEnter);}else if(this.state.loading){setTimeout(function(){return _this2.setState({loading:false});},0);}}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps,prevState){if(this.props.lazy!==prevProps.lazy||this.state.loading!==prevState.loading){if(this.props.lazy&&this.state.loading){this.props.addListener('enter',this.handleEnter);}else{this.props.removeListener('enter',this.handleEnter);}}}},{key:"componentWillUnmount",value:function componentWillUnmount(){this.props.removeListener('enter',this.handleEnter);}},{key:"render",value:function render(){var _this$props=this.props,navigationState=_this$props.navigationState,index=_this$props.index,layout=_this$props.layout,style=_this$props.style;var loading=this.state.loading;var focused=navigationState.index===index;return React.createElement(View,{accessibilityElementsHidden:!focused,importantForAccessibility:focused?'auto':'no-hide-descendants',style:[styles.route,layout.width?{width:layout.width}:focused?StyleSheet.absoluteFill:null,style],__source:{fileName:_jsxFileName,lineNumber:92}},focused||layout.width?this.props.children({loading:loading}):null);}}],[{key:"getDerivedStateFromProps",value:function getDerivedStateFromProps(props,state){if(state.loading&&Math.abs(props.navigationState.index-props.index)<=props.lazyPreloadDistance){return{loading:false};}return null;}}]);return SceneView;}(React.Component);export{SceneView as default};var styles=StyleSheet.create({route:{flex:1,overflow:'hidden'}}); //# sourceMappingURL=SceneView.js.map