{"ast":null,"code":"import _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\nimport _assertThisInitialized from \"@babel/runtime/helpers/assertThisInitialized\";\nimport _inherits from \"@babel/runtime/helpers/inherits\";\nimport _possibleConstructorReturn from \"@babel/runtime/helpers/possibleConstructorReturn\";\nimport _getPrototypeOf from \"@babel/runtime/helpers/getPrototypeOf\";\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }\nfunction _extends() {\n _extends = Object.assign || function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n return target;\n };\n return _extends.apply(this, arguments);\n}\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n return obj;\n}\nimport * as React from 'react';\nimport { Component } from 'react';\nimport Animated from \"react-native-web/dist/exports/Animated\";\nimport Platform from \"react-native-web/dist/exports/Platform\";\nimport { State } from \"../../State\";\nimport { BaseButton } from \"../GestureButtons\";\nexport var TOUCHABLE_STATE = {\n UNDETERMINED: 0,\n BEGAN: 1,\n MOVED_OUTSIDE: 2\n};\nvar GenericTouchable = function (_Component) {\n _inherits(GenericTouchable, _Component);\n var _super = _createSuper(GenericTouchable);\n function GenericTouchable() {\n var _this;\n _classCallCheck(this, GenericTouchable);\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n _this = _super.call.apply(_super, [this].concat(args));\n _defineProperty(_assertThisInitialized(_this), \"pressInTimeout\", void 0);\n _defineProperty(_assertThisInitialized(_this), \"pressOutTimeout\", void 0);\n _defineProperty(_assertThisInitialized(_this), \"longPressTimeout\", void 0);\n _defineProperty(_assertThisInitialized(_this), \"longPressDetected\", false);\n _defineProperty(_assertThisInitialized(_this), \"pointerInside\", true);\n _defineProperty(_assertThisInitialized(_this), \"STATE\", TOUCHABLE_STATE.UNDETERMINED);\n _defineProperty(_assertThisInitialized(_this), \"onGestureEvent\", function (_ref) {\n var pointerInside = _ref.nativeEvent.pointerInside;\n if (_this.pointerInside !== pointerInside) {\n if (pointerInside) {\n _this.onMoveIn();\n } else {\n _this.onMoveOut();\n }\n }\n _this.pointerInside = pointerInside;\n });\n _defineProperty(_assertThisInitialized(_this), \"onHandlerStateChange\", function (_ref2) {\n var nativeEvent = _ref2.nativeEvent;\n var state = nativeEvent.state;\n if (state === State.CANCELLED || state === State.FAILED) {\n _this.moveToState(TOUCHABLE_STATE.UNDETERMINED);\n } else if (state === (Platform.OS !== 'android' ? State.ACTIVE : State.BEGAN) && _this.STATE === TOUCHABLE_STATE.UNDETERMINED) {\n _this.handlePressIn();\n } else if (state === State.END) {\n var shouldCallOnPress = !_this.longPressDetected && _this.STATE !== TOUCHABLE_STATE.MOVED_OUTSIDE && _this.pressOutTimeout === null;\n _this.handleGoToUndetermined();\n if (shouldCallOnPress) {\n var _this$props$onPress, _this$props;\n (_this$props$onPress = (_this$props = _this.props).onPress) === null || _this$props$onPress === void 0 ? void 0 : _this$props$onPress.call(_this$props);\n }\n }\n });\n _defineProperty(_assertThisInitialized(_this), \"onLongPressDetected\", function () {\n var _this$props$onLongPre, _this$props2;\n _this.longPressDetected = true;\n (_this$props$onLongPre = (_this$props2 = _this.props).onLongPress) === null || _this$props$onLongPre === void 0 ? void 0 : _this$props$onLongPre.call(_this$props2);\n });\n return _this;\n }\n _createClass(GenericTouchable, [{\n key: \"handlePressIn\",\n value: function handlePressIn() {\n var _this2 = this;\n if (this.props.delayPressIn) {\n this.pressInTimeout = setTimeout(function () {\n _this2.moveToState(TOUCHABLE_STATE.BEGAN);\n _this2.pressInTimeout = null;\n }, this.props.delayPressIn);\n } else {\n this.moveToState(TOUCHABLE_STATE.BEGAN);\n }\n if (this.props.onLongPress) {\n var time = (this.props.delayPressIn || 0) + (this.props.delayLongPress || 0);\n this.longPressTimeout = setTimeout(this.onLongPressDetected, time);\n }\n }\n }, {\n key: \"handleMoveOutside\",\n value: function handleMoveOutside() {\n var _this3 = this;\n if (this.props.delayPressOut) {\n this.pressOutTimeout = this.pressOutTimeout || setTimeout(function () {\n _this3.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);\n _this3.pressOutTimeout = null;\n }, this.props.delayPressOut);\n } else {\n this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);\n }\n }\n }, {\n key: \"handleGoToUndetermined\",\n value: function handleGoToUndetermined() {\n var _this4 = this;\n clearTimeout(this.pressOutTimeout);\n if (this.props.delayPressOut) {\n this.pressOutTimeout = setTimeout(function () {\n if (_this4.STATE === TOUCHABLE_STATE.UNDETERMINED) {\n _this4.moveToState(TOUCHABLE_STATE.BEGAN);\n }\n _this4.moveToState(TOUCHABLE_STATE.UNDETERMINED);\n _this4.pressOutTimeout = null;\n }, this.props.delayPressOut);\n } else {\n if (this.STATE === TOUCHABLE_STATE.UNDETERMINED) {\n this.moveToState(TOUCHABLE_STATE.BEGAN);\n }\n this.moveToState(TOUCHABLE_STATE.UNDETERMINED);\n }\n }\n }, {\n key: \"componentDidMount\",\n value: function componentDidMount() {\n this.reset();\n }\n }, {\n key: \"reset\",\n value: function reset() {\n this.longPressDetected = false;\n this.pointerInside = true;\n clearTimeout(this.pressInTimeout);\n clearTimeout(this.pressOutTimeout);\n clearTimeout(this.longPressTimeout);\n this.pressOutTimeout = null;\n this.longPressTimeout = null;\n this.pressInTimeout = null;\n }\n }, {\n key: \"moveToState\",\n value: function moveToState(newState) {\n var _this$props$onStateCh, _this$props6;\n if (newState === this.STATE) {\n return;\n }\n if (newState === TOUCHABLE_STATE.BEGAN) {\n var _this$props$onPressIn, _this$props3;\n (_this$props$onPressIn = (_this$props3 = this.props).onPressIn) === null || _this$props$onPressIn === void 0 ? void 0 : _this$props$onPressIn.call(_this$props3);\n } else if (newState === TOUCHABLE_STATE.MOVED_OUTSIDE) {\n var _this$props$onPressOu, _this$props4;\n (_this$props$onPressOu = (_this$props4 = this.props).onPressOut) === null || _this$props$onPressOu === void 0 ? void 0 : _this$props$onPressOu.call(_this$props4);\n } else if (newState === TOUCHABLE_STATE.UNDETERMINED) {\n this.reset();\n if (this.STATE === TOUCHABLE_STATE.BEGAN) {\n var _this$props$onPressOu2, _this$props5;\n (_this$props$onPressOu2 = (_this$props5 = this.props).onPressOut) === null || _this$props$onPressOu2 === void 0 ? void 0 : _this$props$onPressOu2.call(_this$props5);\n }\n }\n (_this$props$onStateCh = (_this$props6 = this.props).onStateChange) === null || _this$props$onStateCh === void 0 ? void 0 : _this$props$onStateCh.call(_this$props6, this.STATE, newState);\n this.STATE = newState;\n }\n }, {\n key: \"componentWillUnmount\",\n value: function componentWillUnmount() {\n this.reset();\n }\n }, {\n key: \"onMoveIn\",\n value: function onMoveIn() {\n if (this.STATE === TOUCHABLE_STATE.MOVED_OUTSIDE) {\n this.moveToState(TOUCHABLE_STATE.BEGAN);\n }\n }\n }, {\n key: \"onMoveOut\",\n value: function onMoveOut() {\n clearTimeout(this.longPressTimeout);\n this.longPressTimeout = null;\n if (this.STATE === TOUCHABLE_STATE.BEGAN) {\n this.handleMoveOutside();\n }\n }\n }, {\n key: \"render\",\n value: function render() {\n var _this$props$touchSoun;\n var coreProps = {\n accessible: this.props.accessible !== false,\n accessibilityLabel: this.props.accessibilityLabel,\n accessibilityHint: this.props.accessibilityHint,\n accessibilityRole: this.props.accessibilityRole,\n accessibilityState: this.props.accessibilityState,\n accessibilityActions: this.props.accessibilityActions,\n onAccessibilityAction: this.props.onAccessibilityAction,\n nativeID: this.props.nativeID,\n onLayout: this.props.onLayout,\n hitSlop: this.props.hitSlop\n };\n return React.createElement(BaseButton, _extends({\n style: this.props.containerStyle,\n onHandlerStateChange: this.props.disabled ? undefined : this.onHandlerStateChange,\n onGestureEvent: this.onGestureEvent,\n hitSlop: this.props.hitSlop,\n shouldActivateOnStart: this.props.shouldActivateOnStart,\n disallowInterruption: this.props.disallowInterruption,\n testID: this.props.testID,\n touchSoundDisabled: (_this$props$touchSoun = this.props.touchSoundDisabled) !== null && _this$props$touchSoun !== void 0 ? _this$props$touchSoun : false,\n enabled: !this.props.disabled\n }, this.props.extraButtonProps), React.createElement(Animated.View, _extends({}, coreProps, {\n style: this.props.style\n }), this.props.children));\n }\n }]);\n return GenericTouchable;\n}(Component);\nexport { GenericTouchable as default };\n_defineProperty(GenericTouchable, \"defaultProps\", {\n delayLongPress: 600,\n extraButtonProps: {\n rippleColor: 'transparent',\n exclusive: true\n }\n});","map":{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,SAAT,QAA0B,OAA1B;AAAA;AAAA;AASA,SAASC,KAAT;AACA,SAASC,UAAT;AAgBA,OAAO,IAAMC,eAAe,GAAG;EAC7BC,YAAY,EAAE,CADe;EAE7BC,KAAK,EAAE,CAFsB;EAG7BC,aAAa,EAAE;AAHc,CAAxB;AAAA,IAuCcC,gBAAN;EAAA;EAAA;EAEb;IAAA;IAAA;IAAA;MAAAC;IAAA;IAAA;IAAAC;IAAAA;IAAAA;IAAAA,oEAeoB,KAfpB;IAAAA,gEAiBgB,IAjBhB;IAAAA,wDAoBwBN,eAAe,CAACC,YApBxC;IAAAK,iEAkHiB,gBAEoC;MAAA,IADpCC,qB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QASEC,oBAAoB,EAAE,KAAKvC,KAAL,CAAWuC,oBATnC;QAUEC,MAAM,EAAE,KAAKxC,KAAL,CAAWwC,MAVrB;QAWEC,kBAAkB,2BAAE,KAAKzC,KAAL,CAAWyC,kBAAb,yEAAmC,KAXvD;QAYEC,OAAO,EAAE,CAAC,KAAK1C,KAAL,CAAWmC;MAZvB,GAaM,KAAKnC,KAAL,CAAW2C,gBAbjB,GAcExE,oBAACyE,QAAD,CAAUC,IAAV,eAAmBxB,SAAnB;QAA8BW,KAAK,EAAE,KAAKhC,KAAL,CAAWgC;MAAhD,IACG,KAAKhC,KAAL,CAAW8C,QADd,CAdF,CADF;IAoBD;EAAA;EAAA;AAAA,EA7N2C1E,SAA/B;AAAA,SAAMO,gBAAN;gBAAMA,gB,kBAGG;EACpB4B,cAAc,EAAE,GADI;EAEpBoC,gBAAgB,EAAE;IAChBI,WAAW,EAAE,aADG;IAEhBC,SAAS,EAAE;EAFK;AAFE,C","names":["React","Component","State","BaseButton","TOUCHABLE_STATE","UNDETERMINED","BEGAN","MOVED_OUTSIDE","GenericTouchable","args","_defineProperty","pointerInside","nativeEvent","onMoveIn","onMoveOut","state","CANCELLED","FAILED","moveToState","Platform","OS","ACTIVE","STATE","handlePressIn","END","shouldCallOnPress","longPressDetected","pressOutTimeout","handleGoToUndetermined","props","onPress","onLongPress","delayPressIn","pressInTimeout","setTimeout","time","delayLongPress","longPressTimeout","onLongPressDetected","handleMoveOutside","delayPressOut","clearTimeout","componentDidMount","reset","newState","onPressIn","onPressOut","onStateChange","componentWillUnmount","render","coreProps","accessible","accessibilityLabel","accessibilityHint","accessibilityRole","accessibilityState","accessibilityActions","onAccessibilityAction","nativeID","onLayout","hitSlop","style","containerStyle","onHandlerStateChange","disabled","undefined","onGestureEvent","shouldActivateOnStart","disallowInterruption","testID","touchSoundDisabled","enabled","extraButtonProps","Animated","View","children","rippleColor","exclusive"],"sources":["/Users/mathildejean/Documents/BUT/LaSuperMeteo/LaSuperMeteo/iut-expo-starter/node_modules/react-native-gesture-handler/lib/module/components/touchables/GenericTouchable.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Component } from 'react';\nimport {\n Animated,\n Platform,\n StyleProp,\n ViewStyle,\n TouchableWithoutFeedbackProps,\n} from 'react-native';\n\nimport { State } from '../../State';\nimport { BaseButton } from '../GestureButtons';\n\nimport {\n GestureEvent,\n HandlerStateChangeEvent,\n} from '../../handlers/gestureHandlerCommon';\nimport { NativeViewGestureHandlerPayload } from '../../handlers/NativeViewGestureHandler';\nimport { TouchableNativeFeedbackExtraProps } from './TouchableNativeFeedback.android';\n\n/**\n * Each touchable is a states' machine which preforms transitions.\n * On very beginning (and on the very end or recognition) touchable is\n * UNDETERMINED. Then it moves to BEGAN. If touchable recognizes that finger\n * travel outside it transits to special MOVED_OUTSIDE state. Gesture recognition\n * finishes in UNDETERMINED state.\n */\nexport const TOUCHABLE_STATE = {\n UNDETERMINED: 0,\n BEGAN: 1,\n MOVED_OUTSIDE: 2,\n} as const;\n\ntype TouchableState = typeof TOUCHABLE_STATE[keyof typeof TOUCHABLE_STATE];\n\nexport interface GenericTouchableProps extends TouchableWithoutFeedbackProps {\n // Decided to drop not used fields from RN's implementation.\n // e.g. onBlur and onFocus as well as deprecated props. - TODO: this comment may be unuseful in this moment\n\n // TODO: in RN these events get native event parameter, which prolly could be used in our implementation too\n onPress?: () => void;\n onPressIn?: () => void;\n onPressOut?: () => void;\n onLongPress?: () => void;\n\n nativeID?: string;\n shouldActivateOnStart?: boolean;\n disallowInterruption?: boolean;\n\n containerStyle?: StyleProp;\n}\n\ninterface InternalProps {\n extraButtonProps: TouchableNativeFeedbackExtraProps;\n onStateChange?: (oldState: TouchableState, newState: TouchableState) => void;\n}\n\n// TODO: maybe can be better\n// TODO: all clearTimeout have ! added, maybe they shouldn't ?\ntype Timeout = ReturnType | null | undefined;\n\n/**\n * GenericTouchable is not intented to be used as it is.\n * Should be treated as a source for the rest of touchables\n */\n\nexport default class GenericTouchable extends Component<\n GenericTouchableProps & InternalProps\n> {\n static defaultProps = {\n delayLongPress: 600,\n extraButtonProps: {\n rippleColor: 'transparent',\n exclusive: true,\n },\n };\n\n // timeout handlers\n pressInTimeout: Timeout;\n pressOutTimeout: Timeout;\n longPressTimeout: Timeout;\n\n // This flag is required since recognition of longPress implies not-invoking onPress\n longPressDetected = false;\n\n pointerInside = true;\n\n // State of touchable\n STATE: TouchableState = TOUCHABLE_STATE.UNDETERMINED;\n\n // handlePressIn in called on first touch on traveling inside component.\n // Handles state transition with delay.\n handlePressIn() {\n if (this.props.delayPressIn) {\n this.pressInTimeout = setTimeout(() => {\n this.moveToState(TOUCHABLE_STATE.BEGAN);\n this.pressInTimeout = null;\n }, this.props.delayPressIn);\n } else {\n this.moveToState(TOUCHABLE_STATE.BEGAN);\n }\n if (this.props.onLongPress) {\n const time =\n (this.props.delayPressIn || 0) + (this.props.delayLongPress || 0);\n this.longPressTimeout = setTimeout(this.onLongPressDetected, time);\n }\n }\n // handleMoveOutside in called on traveling outside component.\n // Handles state transition with delay.\n handleMoveOutside() {\n if (this.props.delayPressOut) {\n this.pressOutTimeout =\n this.pressOutTimeout ||\n setTimeout(() => {\n this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);\n this.pressOutTimeout = null;\n }, this.props.delayPressOut);\n } else {\n this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);\n }\n }\n\n // handleGoToUndetermined transits to UNDETERMINED state with proper delay\n handleGoToUndetermined() {\n clearTimeout(this.pressOutTimeout!); // TODO: maybe it can be undefined\n if (this.props.delayPressOut) {\n this.pressOutTimeout = setTimeout(() => {\n if (this.STATE === TOUCHABLE_STATE.UNDETERMINED) {\n this.moveToState(TOUCHABLE_STATE.BEGAN);\n }\n this.moveToState(TOUCHABLE_STATE.UNDETERMINED);\n this.pressOutTimeout = null;\n }, this.props.delayPressOut);\n } else {\n if (this.STATE === TOUCHABLE_STATE.UNDETERMINED) {\n this.moveToState(TOUCHABLE_STATE.BEGAN);\n }\n this.moveToState(TOUCHABLE_STATE.UNDETERMINED);\n }\n }\n\n componentDidMount() {\n this.reset();\n }\n // reset timeout to prevent memory leaks.\n reset() {\n this.longPressDetected = false;\n this.pointerInside = true;\n clearTimeout(this.pressInTimeout!);\n clearTimeout(this.pressOutTimeout!);\n clearTimeout(this.longPressTimeout!);\n this.pressOutTimeout = null;\n this.longPressTimeout = null;\n this.pressInTimeout = null;\n }\n\n // All states' transitions are defined here.\n moveToState(newState: TouchableState) {\n if (newState === this.STATE) {\n // Ignore dummy transitions\n return;\n }\n if (newState === TOUCHABLE_STATE.BEGAN) {\n // First touch and moving inside\n this.props.onPressIn?.();\n } else if (newState === TOUCHABLE_STATE.MOVED_OUTSIDE) {\n // Moving outside\n this.props.onPressOut?.();\n } else if (newState === TOUCHABLE_STATE.UNDETERMINED) {\n // Need to reset each time on transition to UNDETERMINED\n this.reset();\n if (this.STATE === TOUCHABLE_STATE.BEGAN) {\n // ... and if it happens inside button.\n this.props.onPressOut?.();\n }\n }\n // Finally call lister (used by subclasses)\n this.props.onStateChange?.(this.STATE, newState);\n // ... and make transition.\n this.STATE = newState;\n }\n\n onGestureEvent = ({\n nativeEvent: { pointerInside },\n }: GestureEvent) => {\n if (this.pointerInside !== pointerInside) {\n if (pointerInside) {\n this.onMoveIn();\n } else {\n this.onMoveOut();\n }\n }\n this.pointerInside = pointerInside;\n };\n\n onHandlerStateChange = ({\n nativeEvent,\n }: HandlerStateChangeEvent) => {\n const { state } = nativeEvent;\n if (state === State.CANCELLED || state === State.FAILED) {\n // Need to handle case with external cancellation (e.g. by ScrollView)\n this.moveToState(TOUCHABLE_STATE.UNDETERMINED);\n } else if (\n // This platform check is an implication of slightly different behavior of handlers on different platform.\n // And Android \"Active\" state is achieving on first move of a finger, not on press in.\n // On iOS event on \"Began\" is not delivered.\n state === (Platform.OS !== 'android' ? State.ACTIVE : State.BEGAN) &&\n this.STATE === TOUCHABLE_STATE.UNDETERMINED\n ) {\n // Moving inside requires\n this.handlePressIn();\n } else if (state === State.END) {\n const shouldCallOnPress =\n !this.longPressDetected &&\n this.STATE !== TOUCHABLE_STATE.MOVED_OUTSIDE &&\n this.pressOutTimeout === null;\n this.handleGoToUndetermined();\n if (shouldCallOnPress) {\n // Calls only inside component whether no long press was called previously\n this.props.onPress?.();\n }\n }\n };\n\n onLongPressDetected = () => {\n this.longPressDetected = true;\n // checked for in the caller of `onLongPressDetected`, but better to check twice\n this.props.onLongPress?.();\n };\n\n componentWillUnmount() {\n // to prevent memory leaks\n this.reset();\n }\n\n onMoveIn() {\n if (this.STATE === TOUCHABLE_STATE.MOVED_OUTSIDE) {\n // This call is not throttled with delays (like in RN's implementation).\n this.moveToState(TOUCHABLE_STATE.BEGAN);\n }\n }\n\n onMoveOut() {\n // long press should no longer be detected\n clearTimeout(this.longPressTimeout!);\n this.longPressTimeout = null;\n if (this.STATE === TOUCHABLE_STATE.BEGAN) {\n this.handleMoveOutside();\n }\n }\n\n render() {\n const coreProps = {\n accessible: this.props.accessible !== false,\n accessibilityLabel: this.props.accessibilityLabel,\n accessibilityHint: this.props.accessibilityHint,\n accessibilityRole: this.props.accessibilityRole,\n // TODO: check if changed to no 's' correctly, also removed 2 props that are no longer available: `accessibilityComponentType` and `accessibilityTraits`,\n // would be good to check if it is ok for sure, see: https://github.com/facebook/react-native/issues/24016\n accessibilityState: this.props.accessibilityState,\n accessibilityActions: this.props.accessibilityActions,\n onAccessibilityAction: this.props.onAccessibilityAction,\n nativeID: this.props.nativeID,\n onLayout: this.props.onLayout,\n hitSlop: this.props.hitSlop,\n };\n\n return (\n \n \n {this.props.children}\n \n \n );\n }\n}\n"]},"metadata":{},"sourceType":"module","externalDependencies":[]}