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
25 KiB
1 line
25 KiB
{"ast":null,"code":"import _objectWithoutProperties from \"@babel/runtime/helpers/objectWithoutProperties\";\nimport _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\";\nvar _excluded = [\"rippleColor\"],\n _excluded2 = [\"children\", \"style\"],\n _excluded3 = [\"children\", \"style\"];\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 Animated from \"react-native-web/dist/exports/Animated\";\nimport Platform from \"react-native-web/dist/exports/Platform\";\nimport processColor from \"react-native-web/dist/exports/processColor\";\nimport StyleSheet from \"react-native-web/dist/exports/StyleSheet\";\nimport createNativeWrapper from \"../handlers/createNativeWrapper\";\nimport GestureHandlerButton from \"./GestureHandlerButton\";\nimport { State } from \"../State\";\nexport var RawButton = createNativeWrapper(GestureHandlerButton, {\n shouldCancelWhenOutside: false,\n shouldActivateOnStart: false\n});\nexport var BaseButton = function (_React$Component) {\n _inherits(BaseButton, _React$Component);\n var _super = _createSuper(BaseButton);\n function BaseButton(props) {\n var _this;\n _classCallCheck(this, BaseButton);\n _this = _super.call(this, props);\n _defineProperty(_assertThisInitialized(_this), \"lastActive\", void 0);\n _defineProperty(_assertThisInitialized(_this), \"longPressTimeout\", void 0);\n _defineProperty(_assertThisInitialized(_this), \"longPressDetected\", void 0);\n _defineProperty(_assertThisInitialized(_this), \"handleEvent\", function (_ref) {\n var nativeEvent = _ref.nativeEvent;\n var state = nativeEvent.state,\n oldState = nativeEvent.oldState,\n pointerInside = nativeEvent.pointerInside;\n var active = pointerInside && state === State.ACTIVE;\n if (active !== _this.lastActive && _this.props.onActiveStateChange) {\n _this.props.onActiveStateChange(active);\n }\n if (!_this.longPressDetected && oldState === State.ACTIVE && state !== State.CANCELLED && _this.lastActive && _this.props.onPress) {\n _this.props.onPress(active);\n }\n if (!_this.lastActive && state === (Platform.OS !== 'android' ? State.ACTIVE : State.BEGAN) && pointerInside) {\n _this.longPressDetected = false;\n if (_this.props.onLongPress) {\n _this.longPressTimeout = setTimeout(_this.onLongPress, _this.props.delayLongPress);\n }\n } else if (state === State.ACTIVE && !pointerInside && _this.longPressTimeout !== undefined) {\n clearTimeout(_this.longPressTimeout);\n _this.longPressTimeout = undefined;\n } else if (_this.longPressTimeout !== undefined && (state === State.END || state === State.CANCELLED || state === State.FAILED)) {\n clearTimeout(_this.longPressTimeout);\n _this.longPressTimeout = undefined;\n }\n _this.lastActive = active;\n });\n _defineProperty(_assertThisInitialized(_this), \"onLongPress\", function () {\n var _this$props$onLongPre, _this$props;\n _this.longPressDetected = true;\n (_this$props$onLongPre = (_this$props = _this.props).onLongPress) === null || _this$props$onLongPre === void 0 ? void 0 : _this$props$onLongPre.call(_this$props);\n });\n _defineProperty(_assertThisInitialized(_this), \"onHandlerStateChange\", function (e) {\n var _this$props$onHandler, _this$props2;\n (_this$props$onHandler = (_this$props2 = _this.props).onHandlerStateChange) === null || _this$props$onHandler === void 0 ? void 0 : _this$props$onHandler.call(_this$props2, e);\n _this.handleEvent(e);\n });\n _defineProperty(_assertThisInitialized(_this), \"onGestureEvent\", function (e) {\n var _this$props$onGesture, _this$props3;\n (_this$props$onGesture = (_this$props3 = _this.props).onGestureEvent) === null || _this$props$onGesture === void 0 ? void 0 : _this$props$onGesture.call(_this$props3, e);\n _this.handleEvent(e);\n });\n _this.lastActive = false;\n _this.longPressDetected = false;\n return _this;\n }\n _createClass(BaseButton, [{\n key: \"render\",\n value: function render() {\n var _this$props6 = this.props,\n rippleColor = _this$props6.rippleColor,\n rest = _objectWithoutProperties(_this$props6, _excluded);\n return React.createElement(RawButton, _extends({\n rippleColor: processColor(rippleColor)\n }, rest, {\n onGestureEvent: this.onGestureEvent,\n onHandlerStateChange: this.onHandlerStateChange\n }));\n }\n }]);\n return BaseButton;\n}(React.Component);\n_defineProperty(BaseButton, \"defaultProps\", {\n delayLongPress: 600\n});\nvar AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);\nvar btnStyles = StyleSheet.create({\n underlay: {\n position: 'absolute',\n left: 0,\n right: 0,\n bottom: 0,\n top: 0\n }\n});\nexport var RectButton = function (_React$Component2) {\n _inherits(RectButton, _React$Component2);\n var _super2 = _createSuper(RectButton);\n function RectButton(props) {\n var _this2;\n _classCallCheck(this, RectButton);\n _this2 = _super2.call(this, props);\n _defineProperty(_assertThisInitialized(_this2), \"opacity\", void 0);\n _defineProperty(_assertThisInitialized(_this2), \"onActiveStateChange\", function (active) {\n var _this$props$onActiveS, _this$props4;\n if (Platform.OS !== 'android') {\n _this2.opacity.setValue(active ? _this2.props.activeOpacity : 0);\n }\n (_this$props$onActiveS = (_this$props4 = _this2.props).onActiveStateChange) === null || _this$props$onActiveS === void 0 ? void 0 : _this$props$onActiveS.call(_this$props4, active);\n });\n _this2.opacity = new Animated.Value(0);\n return _this2;\n }\n _createClass(RectButton, [{\n key: \"render\",\n value: function render() {\n var _this$props7 = this.props,\n children = _this$props7.children,\n style = _this$props7.style,\n rest = _objectWithoutProperties(_this$props7, _excluded2);\n var resolvedStyle = StyleSheet.flatten(style !== null && style !== void 0 ? style : {});\n return React.createElement(BaseButton, _extends({}, rest, {\n style: resolvedStyle,\n onActiveStateChange: this.onActiveStateChange\n }), React.createElement(Animated.View, {\n style: [btnStyles.underlay, {\n opacity: this.opacity,\n backgroundColor: this.props.underlayColor,\n borderRadius: resolvedStyle.borderRadius,\n borderTopLeftRadius: resolvedStyle.borderTopLeftRadius,\n borderTopRightRadius: resolvedStyle.borderTopRightRadius,\n borderBottomLeftRadius: resolvedStyle.borderBottomLeftRadius,\n borderBottomRightRadius: resolvedStyle.borderBottomRightRadius\n }]\n }), children);\n }\n }]);\n return RectButton;\n}(React.Component);\n_defineProperty(RectButton, \"defaultProps\", {\n activeOpacity: 0.105,\n underlayColor: 'black'\n});\nexport var BorderlessButton = function (_React$Component3) {\n _inherits(BorderlessButton, _React$Component3);\n var _super3 = _createSuper(BorderlessButton);\n function BorderlessButton(props) {\n var _this3;\n _classCallCheck(this, BorderlessButton);\n _this3 = _super3.call(this, props);\n _defineProperty(_assertThisInitialized(_this3), \"opacity\", void 0);\n _defineProperty(_assertThisInitialized(_this3), \"onActiveStateChange\", function (active) {\n var _this$props$onActiveS2, _this$props5;\n if (Platform.OS !== 'android') {\n _this3.opacity.setValue(active ? _this3.props.activeOpacity : 1);\n }\n (_this$props$onActiveS2 = (_this$props5 = _this3.props).onActiveStateChange) === null || _this$props$onActiveS2 === void 0 ? void 0 : _this$props$onActiveS2.call(_this$props5, active);\n });\n _this3.opacity = new Animated.Value(1);\n return _this3;\n }\n _createClass(BorderlessButton, [{\n key: \"render\",\n value: function render() {\n var _this$props8 = this.props,\n children = _this$props8.children,\n style = _this$props8.style,\n rest = _objectWithoutProperties(_this$props8, _excluded3);\n return React.createElement(AnimatedBaseButton, _extends({}, rest, {\n onActiveStateChange: this.onActiveStateChange,\n style: [style, Platform.OS === 'ios' && {\n opacity: this.opacity\n }]\n }), children);\n }\n }]);\n return BorderlessButton;\n}(React.Component);\n_defineProperty(BorderlessButton, \"defaultProps\", {\n activeOpacity: 0.3,\n borderless: true\n});\nexport { default as PureNativeButton } from \"./GestureHandlerButton\";","map":{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAAA;AAAA;AAAA;AAAA;AAUA,OAAOC,mBAAP;AACA,OAAOC,oBAAP;AACA,SAASC,KAAT;AA2GA,OAAO,IAAMC,SAAS,GAAGH,mBAAmB,CAACC,oBAAD,EAAuB;EACjEG,uBAAuB,EAAE,KADwC;EAEjEC,qBAAqB,EAAE;AAF0C,CAAvB,CAArC;AAKP,WAAaC,UAAN;EAAA;EAAA;EASLC,oBAAYC,KAAD,EAAyB;IAAA;IAAA;IAClC,0BAAMA,KAAN;IADkCC;IAAAA;IAAAA;IAAAA,8DAMd,gBAE0C;MAAA,IAD9DC;MAEA,IAAQC,KAAF,GAAqCD,WAA3C,CAAQC,KAAF;QAASC,QAAT,GAAqCF,WAA3C,CAAeE,QAAT;QAAmBC,gBAAkBH,WAA3C,CAAyBG;MACzB,IAAMC,MAAM,GAAGD,aAAa,IAAIF,KAAK,KAAKT,KAAK,CAACa,MAAhD;MAEA,IAAID,MAAM,KAAK,MAAKE,UAAhB,IAA8B,MAAKR,KAAL,CAAWS,mBAA7C,EAAkE;QAChE,MAAKT,KAAL,CAAWS,mBAAX,CAA+BH,MAA/B;MACD;MAED,IACE,CAAC,MAAKI,iBAAN,IACAN,QAAQ,KAAKV,KAAK,CAACa,MADnB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,MAAM,GAAG,OAAKN,KAAL,CAAWgD,aAAd,GAA+B,CAA3D;MACD;MAED,iDAAKhD,KAAL,EAAWS,mBAAX,qGAAiCH,MAAjC;IACD,CAXyC;IAExC,OAAKwC,OAAL,GAAe,IAAIZ,QAAQ,CAACe,KAAb,CAAmB,CAAnB,CAAf;IAAA;EACD;EAAA;IAAA;IAAA,OAUDrB,kBAAS;MACP,mBAAqC,KAAK5B,KAA1C;QAAQkD,QAAF,gBAAEA,QAAF;QAAYC,KAAZ,gBAAYA,KAAZ;QAAsBrB;MAE5B,OACEvC,oBAAC0C,kBAAD,eACMH,IADN;QAEErB,mBAAmB,EAAE,KAAKA,mBAF5B;QAGE0C,KAAK,EAAE,CAACA,KAAD,EAAQtC,QAAQ,CAACC,EAAT,KAAgB,KAAhB,IAAyB;UAAEgC,OAAO,EAAE,KAAKA;QAAhB,CAAjC;MAHT,IAIGI,QAJH,CADF;IAQD;EAAA;EAAA;AAAA,EAhCmC3D,KAAK,CAACyC,SAArC;gBAAM8B,gB,kBACW;EACpBd,aAAa,EAAE,GADK;EAEpBe,UAAU,EAAE;AAFQ,C;AAkCxB,SAASC,OAAO,IAAIC,gBAApB","names":["React","createNativeWrapper","GestureHandlerButton","State","RawButton","shouldCancelWhenOutside","shouldActivateOnStart","BaseButton","constructor","props","_defineProperty","nativeEvent","state","oldState","pointerInside","active","ACTIVE","lastActive","onActiveStateChange","longPressDetected","CANCELLED","onPress","Platform","OS","BEGAN","onLongPress","longPressTimeout","setTimeout","delayLongPress","undefined","clearTimeout","END","FAILED","e","onHandlerStateChange","handleEvent","onGestureEvent","render","rippleColor","rest","processColor","Component","AnimatedBaseButton","Animated","createAnimatedComponent","btnStyles","StyleSheet","create","underlay","position","left","right","bottom","top","RectButton","opacity","setValue","activeOpacity","Value","children","style","resolvedStyle","flatten","View","backgroundColor","underlayColor","borderRadius","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","BorderlessButton","borderless","default","PureNativeButton"],"sources":["/Users/mathildejean/Documents/BUT/LaSuperMeteo/LaSuperMeteo/iut-expo-starter/node_modules/react-native-gesture-handler/lib/module/components/GestureButtons.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n Platform,\n processColor,\n StyleSheet,\n StyleProp,\n ViewStyle,\n} from 'react-native';\n\nimport createNativeWrapper from '../handlers/createNativeWrapper';\nimport GestureHandlerButton from './GestureHandlerButton';\nimport { State } from '../State';\n\nimport {\n GestureEvent,\n HandlerStateChangeEvent,\n} from '../handlers/gestureHandlerCommon';\nimport {\n NativeViewGestureHandlerPayload,\n NativeViewGestureHandlerProps,\n} from '../handlers/NativeViewGestureHandler';\n\nexport interface RawButtonProps extends NativeViewGestureHandlerProps {\n /**\n * Defines if more than one button could be pressed simultaneously. By default\n * set true.\n */\n exclusive?: boolean;\n // TODO: we should transform props in `createNativeWrapper`\n\n /**\n * Android only.\n *\n * Defines color of native ripple animation used since API level 21.\n */\n rippleColor?: any; // it was present in BaseButtonProps before but is used here in code\n\n /**\n * Android only.\n *\n * Defines radius of native ripple animation used since API level 21.\n */\n rippleRadius?: number | null;\n\n /**\n * Android only.\n *\n * Set this to true if you want the ripple animation to render outside the view bounds.\n */\n borderless?: boolean;\n\n /**\n * Android only.\n *\n * Defines whether the ripple animation should be drawn on the foreground of the view.\n */\n foreground?: boolean;\n\n /**\n * Android only.\n *\n * Set this to true if you don't want the system to play sound when the button is pressed.\n */\n touchSoundDisabled?: boolean;\n}\n\nexport interface BaseButtonProps extends RawButtonProps {\n /**\n * Called when the button gets pressed (analogous to `onPress` in\n * `TouchableHighlight` from RN core).\n */\n onPress?: (pointerInside: boolean) => void;\n\n /**\n * Called when the button gets pressed and is held for `delayLongPress`\n * milliseconds.\n */\n onLongPress?: () => void;\n\n /**\n * Called when button changes from inactive to active and vice versa. It\n * passes active state as a boolean variable as a first parameter for that\n * method.\n */\n onActiveStateChange?: (active: boolean) => void;\n style?: StyleProp<ViewStyle>;\n testID?: string;\n\n /**\n * Delay, in milliseconds, after which the `onLongPress` callback gets called.\n * Defaults to 600.\n */\n delayLongPress?: number;\n}\n\nexport interface RectButtonProps extends BaseButtonProps {\n /**\n * Background color that will be dimmed when button is in active state.\n */\n underlayColor?: string;\n\n /**\n * iOS only.\n *\n * Opacity applied to the underlay when button is in active state.\n */\n activeOpacity?: number;\n}\n\nexport interface BorderlessButtonProps extends BaseButtonProps {\n /**\n * iOS only.\n *\n * Opacity applied to the button when it is in an active state.\n */\n activeOpacity?: number;\n}\n\nexport const RawButton = createNativeWrapper(GestureHandlerButton, {\n shouldCancelWhenOutside: false,\n shouldActivateOnStart: false,\n});\n\nexport class BaseButton extends React.Component<BaseButtonProps> {\n static defaultProps = {\n delayLongPress: 600,\n };\n\n private lastActive: boolean;\n private longPressTimeout: ReturnType<typeof setTimeout> | undefined;\n private longPressDetected: boolean;\n\n constructor(props: BaseButtonProps) {\n super(props);\n this.lastActive = false;\n this.longPressDetected = false;\n }\n\n private handleEvent = ({\n nativeEvent,\n }: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>) => {\n const { state, oldState, pointerInside } = nativeEvent;\n const active = pointerInside && state === State.ACTIVE;\n\n if (active !== this.lastActive && this.props.onActiveStateChange) {\n this.props.onActiveStateChange(active);\n }\n\n if (\n !this.longPressDetected &&\n oldState === State.ACTIVE &&\n state !== State.CANCELLED &&\n this.lastActive &&\n this.props.onPress\n ) {\n this.props.onPress(active);\n }\n\n if (\n !this.lastActive &&\n // NativeViewGestureHandler sends different events based on platform\n state === (Platform.OS !== 'android' ? State.ACTIVE : State.BEGAN) &&\n pointerInside\n ) {\n this.longPressDetected = false;\n if (this.props.onLongPress) {\n this.longPressTimeout = setTimeout(\n this.onLongPress,\n this.props.delayLongPress\n );\n }\n } else if (\n // cancel longpress timeout if it's set and the finger moved out of the view\n state === State.ACTIVE &&\n !pointerInside &&\n this.longPressTimeout !== undefined\n ) {\n clearTimeout(this.longPressTimeout);\n this.longPressTimeout = undefined;\n } else if (\n // cancel longpress timeout if it's set and the gesture has finished\n this.longPressTimeout !== undefined &&\n (state === State.END ||\n state === State.CANCELLED ||\n state === State.FAILED)\n ) {\n clearTimeout(this.longPressTimeout);\n this.longPressTimeout = undefined;\n }\n\n this.lastActive = active;\n };\n\n private onLongPress = () => {\n this.longPressDetected = true;\n this.props.onLongPress?.();\n };\n\n // Normally, the parent would execute it's handler first, then forward the\n // event to listeners. However, here our handler is virtually only forwarding\n // events to listeners, so we reverse the order to keep the proper order of\n // the callbacks (from \"raw\" ones to \"processed\").\n private onHandlerStateChange = (\n e: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>\n ) => {\n this.props.onHandlerStateChange?.(e);\n this.handleEvent(e);\n };\n\n private onGestureEvent = (\n e: GestureEvent<NativeViewGestureHandlerPayload>\n ) => {\n this.props.onGestureEvent?.(e);\n this.handleEvent(\n e as HandlerStateChangeEvent<NativeViewGestureHandlerPayload>\n ); // TODO: maybe it is not correct\n };\n\n render() {\n const { rippleColor, ...rest } = this.props;\n\n return (\n <RawButton\n rippleColor={processColor(rippleColor)}\n {...rest}\n onGestureEvent={this.onGestureEvent}\n onHandlerStateChange={this.onHandlerStateChange}\n />\n );\n }\n}\n\nconst AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);\n\nconst btnStyles = StyleSheet.create({\n underlay: {\n position: 'absolute',\n left: 0,\n right: 0,\n bottom: 0,\n top: 0,\n },\n});\n\nexport class RectButton extends React.Component<RectButtonProps> {\n static defaultProps = {\n activeOpacity: 0.105,\n underlayColor: 'black',\n };\n\n private opacity: Animated.Value;\n\n constructor(props: RectButtonProps) {\n super(props);\n this.opacity = new Animated.Value(0);\n }\n\n private onActiveStateChange = (active: boolean) => {\n if (Platform.OS !== 'android') {\n this.opacity.setValue(active ? this.props.activeOpacity! : 0);\n }\n\n this.props.onActiveStateChange?.(active);\n };\n\n render() {\n const { children, style, ...rest } = this.props;\n\n const resolvedStyle = StyleSheet.flatten(style ?? {});\n\n return (\n <BaseButton\n {...rest}\n style={resolvedStyle}\n onActiveStateChange={this.onActiveStateChange}>\n <Animated.View\n style={[\n btnStyles.underlay,\n {\n opacity: this.opacity,\n backgroundColor: this.props.underlayColor,\n borderRadius: resolvedStyle.borderRadius,\n borderTopLeftRadius: resolvedStyle.borderTopLeftRadius,\n borderTopRightRadius: resolvedStyle.borderTopRightRadius,\n borderBottomLeftRadius: resolvedStyle.borderBottomLeftRadius,\n borderBottomRightRadius: resolvedStyle.borderBottomRightRadius,\n },\n ]}\n />\n {children}\n </BaseButton>\n );\n }\n}\n\nexport class BorderlessButton extends React.Component<BorderlessButtonProps> {\n static defaultProps = {\n activeOpacity: 0.3,\n borderless: true,\n };\n\n private opacity: Animated.Value;\n\n constructor(props: BorderlessButtonProps) {\n super(props);\n this.opacity = new Animated.Value(1);\n }\n\n private onActiveStateChange = (active: boolean) => {\n if (Platform.OS !== 'android') {\n this.opacity.setValue(active ? this.props.activeOpacity! : 1);\n }\n\n this.props.onActiveStateChange?.(active);\n };\n\n render() {\n const { children, style, ...rest } = this.props;\n\n return (\n <AnimatedBaseButton\n {...rest}\n onActiveStateChange={this.onActiveStateChange}\n style={[style, Platform.OS === 'ios' && { opacity: this.opacity }]}>\n {children}\n </AnimatedBaseButton>\n );\n }\n}\n\nexport { default as PureNativeButton } from './GestureHandlerButton';\n"]},"metadata":{},"sourceType":"module","externalDependencies":[]} |