You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
28 KiB

{"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,"sources":["GenericTouchable.tsx"],"names":["React","Component","State","BaseButton","TOUCHABLE_STATE","UNDETERMINED","BEGAN","MOVED_OUTSIDE","GenericTouchable","delayLongPress","extraButtonProps","rippleColor","exclusive","handlePressIn","props","delayPressIn","pressInTimeout","setTimeout","moveToState","onLongPress","time","longPressTimeout","onLongPressDetected","handleMoveOutside","delayPressOut","pressOutTimeout","handleGoToUndetermined","clearTimeout","STATE","componentDidMount","reset","longPressDetected","pointerInside","newState","onPressIn","onPressOut","onStateChange","nativeEvent","onMoveIn","onMoveOut","state","CANCELLED","FAILED","Platform","OS","ACTIVE","END","shouldCallOnPress","onPress","componentWillUnmount","render","coreProps","accessible","accessibilityLabel","accessibilityHint","accessibilityRole","accessibilityState","accessibilityActions","onAccessibilityAction","nativeID","onLayout","hitSlop","containerStyle","disabled","undefined","onHandlerStateChange","onGestureEvent","shouldActivateOnStart","disallowInterruption","testID","touchSoundDisabled","style","children"],"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,4BAAA;IAAA;IAAA;IAAA,kCAAA,IAAA;MAAA,IAAA;IAAA;IAAA,gDAAA,IAAA;IAAA,eAAA,gCAAA,gBAAA,EAAA,KAAA,CAAA,CAAA;IAAA,eAAA,gCAAA,iBAAA,EAAA,KAAA,CAAA,CAAA;IAAA,eAAA,gCAAA,kBAAA,EAAA,KAAA,CAAA,CAAA;IAAA,eAAA,gCAAA,mBAAA,EAeoB,KAfpB,CAAA;IAAA,eAAA,gCAAA,eAAA,EAiBgB,IAjBhB,CAAA;IAAA,eAAA,gCAAA,OAAA,EAoBwBJ,eAAe,CAACC,YApBxC,CAAA;IAAA,eAAA,gCAAA,gBAAA,EAkHiB,gBAEoC;MAAA,IADpC2B,aAAAA,QAAfK,WAAW,CAAIL,aAAAA;MAEf,IAAI,MAAKA,aAAL,KAAuBA,aAA3B,EAA0C;QACxC,IAAIA,aAAJ,EAAmB;UACjB,MAAKM,QAAL,EAAA;QACD,CAFD,MAEO;UACL,MAAKC,SAAL,EAAA;QACD;MACF;MACD,MAAKP,aAAL,GAAqBA,aAArB;IACD,CA7HD,CAAA;IAAA,eAAA,gCAAA,sBAAA,EA+HuB,iBAEyC;MAAA,IAD9DK,WAAAA,SAAAA,WAAAA;MAEA,IAAQG,K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,cANvB;QAOE,OAAO,EAAE,IAAA,CAAKpD,KAAL,CAAW+C,OAPtB;QAQE,qBAAqB,EAAE,IAAA,CAAK/C,KAAL,CAAWqD,qBARpC;QASE,oBAAoB,EAAE,IAAA,CAAKrD,KAAL,CAAWsD,oBATnC;QAUE,MAAM,EAAE,IAAA,CAAKtD,KAAL,CAAWuD,MAVrB;QAWE,kBAAkB,EAAA,CAAA,qBAAA,GAAE,IAAA,CAAKvD,KAAL,CAAWwD,kBAAb,MAAA,IAAA,IAAA,qBAAA,KAAA,KAAA,CAAA,GAAA,qBAAA,GAAmC,KAXvD;QAYE,OAAO,EAAE,CAAC,IAAA,CAAKxD,KAAL,CAAWiD;MAZvB,CAAA,EAaM,IAAA,CAAKjD,KAAL,CAAWJ,gBAbjB,CAAA,EAcE,KAAA,CAAA,aAAA,CAAC,QAAD,CAAU,IAAV,EAAA,QAAA,CAAA,CAAA,CAAA,EAAmByC,SAAnB,EAAA;QAA8B,KAAK,EAAE,IAAA,CAAKrC,KAAL,CAAWyD;MAAhD,CAAA,CAAA,EACG,IAAA,CAAKzD,KAAL,CAAW0D,QADd,CAdF,CADF;IAoBD;EAAA;EAAA;AAAA,EA7N2CvE,SAA/B;AAAA,SAAMO,gBAAN;gBAAMA,gB,kBAGG;EACpBC,cAAc,EAAE,GADI;EAEpBC,gBAAgB,EAAE;IAChBC,WAAW,EAAE,aADG;IAEhBC,SAAS,EAAE;EAFK;AAFE,C","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<ViewStyle>;\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<typeof setTimeout> | 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<NativeViewGestureHandlerPayload>) => {\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<NativeViewGestureHandlerPayload>) => {\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 <BaseButton\n style={this.props.containerStyle}\n onHandlerStateChange={\n // TODO: not sure if it can be undefined instead of null\n this.props.disabled ? undefined : this.onHandlerStateChange\n }\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.touchSoundDisabled ?? false}\n enabled={!this.props.disabled}\n {...this.props.extraButtonProps}>\n <Animated.View {...coreProps} style={this.props.style}>\n {this.props.children}\n </Animated.View>\n </BaseButton>\n );\n }\n}\n"]},"metadata":{},"sourceType":"module"}