text: var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _assertThisInitialized2=_interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _react=_interopRequireWildcard(require("react"));var _propTypes=_interopRequireDefault(require("prop-types"));var _reactNative=require("react-native");var _withTheme=_interopRequireDefault(require("../../Theme/withTheme"));var _MarkerContainer=_interopRequireDefault(require("./MarkerContainer/MarkerContainer"));var _Track=_interopRequireDefault(require("./Track/Track"));var _converts=require("./converts");var _Slider=_interopRequireDefault(require("./Slider.styles"));var _jsxFileName="C:\\mike\\eps\\repos\\material-bread\\src\\Components\\Slider\\Slider.js";var Slider=function(_Component){(0,_inherits2.default)(Slider,_Component);function Slider(props){var _this;(0,_classCallCheck2.default)(this,Slider);_this=(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(Slider).call(this,props));(0,_defineProperty2.default)((0,_assertThisInitialized2.default)(_this),"startMarkerLeft",function(){var disableOne=_this.props.disableOne;var onePressed=_this.state.onePressed;if(!disableOne){_this.setState({onePressed:!onePressed});}});(0,_defineProperty2.default)((0,_assertThisInitialized2.default)(_this),"startMarkerRight",function(){var disableTwo=_this.props.disableTwo;var twoPressed=_this.state.twoPressed;if(!disableTwo){_this.setState({twoPressed:!twoPressed});}});(0,_defineProperty2.default)((0,_assertThisInitialized2.default)(_this),"moveMarkerLeft",function(gestureState){var _this$props=_this.props,disableOne=_this$props.disableOne,allowOverlap=_this$props.allowOverlap,sliderLength=_this$props.sliderLength,onValuesChange=_this$props.onValuesChange;var _this$state=_this.state,pastOne=_this$state.pastOne,positionTwo=_this$state.positionTwo,valueOne=_this$state.valueOne;if(disableOne){return;}var accumDistance=gestureState.dx;var unconfined=accumDistance+pastOne;var bottom=0;var trueTop=positionTwo-(allowOverlap?0:_this.stepLength);var top=trueTop===0?0:trueTop||sliderLength;var confined=unconfined<bottom?bottom:unconfined>top?top:unconfined;var value=(0,_converts.positionToValue)(confined,_this.optionsArray,sliderLength);_this.setState({positionOne:confined});if(value!==valueOne){_this.setState({valueOne:value},function(){var _this$state2=_this.state,newValOne=_this$state2.valueOne,valueTwo=_this$state2.valueTwo;var change=[newValOne];if(valueTwo){change.push(valueTwo);}onValuesChange(change);});}});(0,_defineProperty2.default)((0,_assertThisInitialized2.default)(_this),"moveMarkerRight",function(gestureState){var _this$props2=_this.props,disableTwo=_this$props2.disableTwo,allowOverlap=_this$props2.allowOverlap,sliderLength=_this$props2.sliderLength,onValuesChange=_this$props2.onValuesChange;var _this$state3=_this.state,pastTwo=_this$state3.pastTwo,positionOne=_this$state3.positionOne,valueTwo=_this$state3.valueTwo;if(disableTwo){return;}var accumDistance=gestureState.dx;var unconfined=accumDistance+pastTwo;var bottom=positionOne+(allowOverlap?0:_this.stepLength);var top=sliderLength;var confined=unconfined<bottom?bottom:unconfined>top?top:unconfined;var value=(0,_converts.positionToValue)(confined,_this.optionsArray,sliderLength);_this.setState({positionTwo:confined});if(value!==valueTwo){_this.setState({valueTwo:value},function(){var _this$state4=_this.state,valueOne=_this$state4.valueOne,newValTwo=_this$state4.valueTwo;onValuesChange([valueOne,newValTwo]);});}});(0,_defineProperty2.default)((0,_assertThisInitialized2.default)(_this),"endMarkerLeft",function(){var onValuesChangeEnd=_this.props.onValuesChangeEnd;var _this$state5=_this.state,positionOne=_this$state5.positionOne,onePressed=_this$state5.onePressed;_this.setState({pastOne:positionOne,onePressed:!onePressed},function(){var _this$state6=_this.state,valueOne=_this$state6.valueOne,valueTwo=_this$state6.valueTwo;var change=[valueOne];if(valueTwo){change.push(valueTwo);}onValuesChangeEnd(change);});});(0,_defineProperty2.default)((0,_assertThisInitialized2.default)(_this),"endMarkerRight",function(){var _this$state7=_this.state,twoPressed=_this$state7.twoPressed,positionTwo=_this$state7.positionTwo;_this.setState({twoPressed:!twoPressed,pastTwo:positionTwo},function(){var _this$state8=_this.state,valueOne=_this$state8.valueOne,valueTwo=_this$state8.valueTwo;_this.props.onValuesChangeEnd([valueOne,valueTwo]);});});var _this$props3=_this.props,_sliderLength=_this$props3.sliderLength,values=_this$props3.values,min=_this$props3.min,max=_this$props3.max,step=_this$props3.step,trackHeight=_this$props3.trackHeight,trackStyle=_this$props3.trackStyle;_this.optionsArray=(0,_converts.createArray)(min,max,step);_this.stepLength=_sliderLength/_this.optionsArray.length;_this.finalTrackHeight=trackHeight||_reactNative.StyleSheet.flatten(trackStyle).height||2;var initialValues=values.map(function(value){return(0,_converts.valueToPosition)(value,_this.optionsArray,_sliderLength);});var customPanResponder=function customPanResponder(start,move,end){return _reactNative.PanResponder.create({onStartShouldSetPanResponder:function onStartShouldSetPanResponder(){return true;},onStartShouldSetPanResponderCapture:function onStartShouldSetPanResponderCapture(){return false;},onMoveShouldSetPanResponder:function onMoveShouldSetPanResponder(){return true;},onMoveShouldSetPanResponderCapture:function onMoveShouldSetPanResponderCapture(){return true;},onPanResponderGrant:function onPanResponderGrant(){return start();},onPanResponderMove:function onPanResponderMove(evt,gestureState){return move(gestureState);},onPanResponderTerminationRequest:function onPanResponderTerminationRequest(){return false;},onPanResponderRelease:function onPanResponderRelease(evt,gestureState){return end(gestureState);},onPanResponderTerminate:function onPanResponderTerminate(evt,gestureState){return end(gestureState);},onShouldBlockNativeResponder:function onShouldBlockNativeResponder(){return true;}});};_this._panResponderOne=customPanResponder(_this.startMarkerLeft,_this.moveMarkerLeft,_this.endMarkerLeft);_this._panResponderTwo=customPanResponder(_this.startMarkerRight,_this.moveMarkerRight,_this.endMarkerRight);_this.state={pressedOne:true,valueOne:values[0],valueTwo:values[1],pastOne:initialValues[0],pastTwo:initialValues[1],positionOne:initialValues[0],positionTwo:initialValues[1]};return _this;}(0,_createClass2.default)(Slider,[{key:"componentWillReceiveProps",value:function componentWillReceiveProps(nextProps){var _this$props4=this.props,sliderLength=_this$props4.sliderLength,min=_this$props4.min,max=_this$props4.max,step=_this$props4.step;var _this$state9=this.state,onePressed=_this$state9.onePressed,twoPressed=_this$state9.twoPressed,valueOne=_this$state9.valueOne,valueTwo=_this$state9.valueTwo;if(onePressed||twoPressed){return;}var nextState={};if(nextProps.min!==min||nextProps.max!==max||nextProps.step!==step||nextProps.values[0]!==valueOne||nextProps.sliderLength!==sliderLength||nextProps.values[1]!==valueTwo||nextProps.sliderLength!==sliderLength&&nextProps.values[1]){this.optionsArray=(0,_converts.createArray)(nextProps.min,nextProps.max,nextProps.step);this.stepLength=sliderLength/this.optionsArray.length;var positionOne=(0,_converts.valueToPosition)(nextProps.values[0],this.optionsArray,nextProps.sliderLength);nextState.valueOne=nextProps.values[0];nextState.pastOne=positionOne;nextState.positionOne=positionOne;var positionTwo=(0,_converts.valueToPosition)(nextProps.values[1],this.optionsArray,nextProps.sliderLength);nextState.valueTwo=nextProps.values[1];nextState.pastTwo=positionTwo;nextState.positionTwo=positionTwo;}if(nextState!={}){this.setState(nextState);}}},{key:"_renderMarkerRight",value:function _renderMarkerRight(){var _this$props5=this.props,sliderLength=_this$props5.sliderLength,disableTwo=_this$props5.disableTwo,markerColor=_this$props5.markerColor,onPress=_this$props5.onPress,markerSize=_this$props5.markerSize;var _this$state10=this.state,positionTwo=_this$state10.positionTwo,twoPressed=_this$state10.twoPressed;return _react.default.createElement(_MarkerContainer.default,{sliderLength:sliderLength,position:positionTwo,pressed:twoPressed,disabled:disableTwo,panResponder:this._panResponderTwo.panHandlers,color:markerColor,onPress:onPress,markerSize:markerSize,trackHeight:this.finalTrackHeight,__source:{fileName:_jsxFileName,lineNumber:310}});}},{key:"_renderMarkerLeft",value:function _renderMarkerLeft(){var _this$props6=this.props,sliderLength=_this$props6.sliderLength,disableOne=_this$props6.disableOne,markerColor=_this$props6.markerColor,onPress=_this$props6.onPress,markerSize=_this$props6.markerSize;var _this$state11=this.state,positionOne=_this$state11.positionOne,onePressed=_this$state11.onePressed;return _react.default.createElement(_MarkerContainer.default,{sliderLength:sliderLength,position:positionOne,pressed:onePressed,disabled:disableOne,panResponder:this._panResponderOne.panHandlers,color:markerColor,onPress:onPress,markerSize:markerSize,trackHeight:this.finalTrackHeight,__source:{fileName:_jsxFileName,lineNumber:335}});}},{key:"_renderTracks",value:function _renderTracks(){var _this$props7=this.props,sliderLength=_this$props7.sliderLength,values=_this$props7.values,trackColor=_this$props7.trackColor,backgroundTrackColor=_this$props7.backgroundTrackColor,disableOne=_this$props7.disableOne,disableTwo=_this$props7.disableTwo,trackStyle=_this$props7.trackStyle;var _this$state12=this.state,positionOne=_this$state12.positionOne,positionTwo=_this$state12.positionTwo;return _react.default.createElement(_Track.default,{twoMarkers:values.length==2,sliderLength:sliderLength,positionTwo:positionTwo,positionOne:positionOne,trackColor:trackColor,backgroundTrackColor:backgroundTrackColor,bothDisabled:disableOne&&disableTwo,oneDisabled:disableOne,trackHeight:this.finalTrackHeight,trackStyle:trackStyle,__source:{fileName:_jsxFileName,lineNumber:362}});}},{key:"render",value:function render(){var _this$props8=this.props,sliderLength=_this$props8.sliderLength,values=_this$props8.values,style=_this$props8.style,testID=_this$props8.testID;var twoMarkers=values.length==2;return _react.default.createElement(_reactNative.View,{style:[_Slider.default.container,style],testID:testID,__source:{fileName:_jsxFileName,lineNumber:382}},_react.default.createElement(_reactNative.View,{style:[_Slider.default.fullTrack,{width:sliderLength}],__source:{fileName:_jsxFileName,lineNumber:383}},this._renderTracks(),this._renderMarkerLeft(),twoMarkers?this._renderMarkerRight():null));}}]);return Slider;}(_react.Component);(0,_defineProperty2.default)(Slider,"propTypes",{values:_propTypes.default.array,sliderLength:_propTypes.default.number,min:_propTypes.default.number,max:_propTypes.default.number,step:_propTypes.default.number,disableOne:_propTypes.default.bool,disableTwo:_propTypes.default.bool,onValuesChange:_propTypes.default.func,onValuesChangeEnd:_propTypes.default.func,trackColor:_propTypes.default.string,backgroundTrackColor:_propTypes.default.string,markerColor:_propTypes.default.string,allowOverlap:_propTypes.default.bool,style:_propTypes.default.oneOfType([_propTypes.default.object,_propTypes.default.array]),testID:_propTypes.default.string,markerSize:_propTypes.default.number,trackHeight:_propTypes.default.number,trackStyle:_propTypes.default.oneOfType([_propTypes.default.object,_propTypes.default.array])});(0,_defineProperty2.default)(Slider,"defaultProps",{values:[0],onValuesChange:function onValuesChange(){},onValuesChangeEnd:function onValuesChangeEnd(){},step:1,min:0,max:100,sliderLength:280,disableOne:false,disableTwo:false,allowOverlap:false,snapped:false,minMarkerOverlapDistance:0,markerSize:12,trackStyle:{}});var _default=(0,_withTheme.default)(Slider);exports.default=_default;