react-navigation-stack
Version:
Stack navigator component for React Navigation
2 lines • 3.14 kB
JavaScript
import _extends from"@babel/runtime/helpers/extends";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/Callstack/react-navigation-stack/src/views/StackView/createPointerEventsContainer.tsx";import*as React from'react';var MIN_POSITION_OFFSET=0.01;export default function createPointerEventsContainer(Component){var Container=function(_React$Component){_inherits(Container,_React$Component);function Container(){var _getPrototypeOf2;var _this;_classCallCheck(this,Container);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_possibleConstructorReturn(this,(_getPrototypeOf2=_getPrototypeOf(Container)).call.apply(_getPrototypeOf2,[this].concat(args)));_this.pointerEvents=_this.computePointerEvents();_this.component=null;_this.handleComponentRef=function(component){_this.component=component;if(component&&typeof component.setNativeProps!=='function'){throw new Error('Component must implement method `setNativeProps`');}};_this.handlePositionChange=function(){if(_this.component){var pointerEvents=_this.computePointerEvents();if(_this.pointerEvents!==pointerEvents){_this.pointerEvents=pointerEvents;_this.component.setNativeProps({pointerEvents:pointerEvents});}}};return _this;}_createClass(Container,[{key:"componentWillUnmount",value:function componentWillUnmount(){this.positionListener&&this.positionListener.remove();}},{key:"bindPosition",value:function bindPosition(){this.positionListener&&this.positionListener.remove();this.positionListener=new AnimatedValueSubscription(this.props.realPosition,this.handlePositionChange);}},{key:"computePointerEvents",value:function computePointerEvents(){var _this$props=this.props,navigation=_this$props.navigation,realPosition=_this$props.realPosition,scene=_this$props.scene;if(scene.isStale||navigation.state.index!==scene.index){return scene.index>navigation.state.index?'box-only':'none';}var offset=realPosition.__getAnimatedValue()-navigation.state.index;if(Math.abs(offset)>MIN_POSITION_OFFSET){return'box-only';}return'auto';}},{key:"render",value:function render(){this.bindPosition();this.pointerEvents=this.computePointerEvents();return React.createElement(Component,_extends({},this.props,{pointerEvents:this.pointerEvents,onComponentRef:this.handleComponentRef,__source:{fileName:_jsxFileName,lineNumber:95}}));}}]);return Container;}(React.Component);return Container;}var AnimatedValueSubscription=function(){function AnimatedValueSubscription(value,callback){_classCallCheck(this,AnimatedValueSubscription);this.value=value;this.token=value.addListener(callback);}_createClass(AnimatedValueSubscription,[{key:"remove",value:function remove(){this.value.removeListener(this.token);}}]);return AnimatedValueSubscription;}();
//# sourceMappingURL=createPointerEventsContainer.js.map