1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.ContextPressable = void 0;
|
7 | exports.MotionPressable = MotionPressable;
|
8 | var _react = _interopRequireWildcard(require("react"));
|
9 | var _reactNative = require("react-native");
|
10 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
11 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
12 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
13 | const ContextPressable = (0, _react.createContext)({
|
14 | pressed: false,
|
15 | hovered: false
|
16 | });
|
17 | exports.ContextPressable = ContextPressable;
|
18 | function MotionPressable(props) {
|
19 |
|
20 | const {
|
21 | onPressIn,
|
22 | onPressOut,
|
23 | onMouseEnter,
|
24 | onMouseLeave,
|
25 | children,
|
26 | ...rest
|
27 | } = props;
|
28 | const [state, setState] = (0, _react.useState)({
|
29 | pressed: false,
|
30 | hovered: false
|
31 | });
|
32 | const update = (0, _react.useCallback)((pressed, hovered) => {
|
33 | setState(cur => ({
|
34 | pressed: pressed !== null && pressed !== void 0 ? pressed : cur.pressed,
|
35 | hovered: hovered !== null && hovered !== void 0 ? hovered : cur.hovered
|
36 | }));
|
37 | }, []);
|
38 | return _react.default.createElement(_reactNative.Pressable, _extends({
|
39 | onPressIn: e => {
|
40 | update(true, undefined);
|
41 | onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn(e);
|
42 | },
|
43 | onPressOut: e => {
|
44 | update(false, undefined);
|
45 | onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(e);
|
46 | }
|
47 |
|
48 | ,
|
49 | onMouseEnter: _reactNative.Platform.OS === 'web' ? e => {
|
50 | update(undefined, true);
|
51 | onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(e);
|
52 | } : undefined
|
53 |
|
54 | ,
|
55 | onMouseLeave: _reactNative.Platform.OS === 'web' ? e => {
|
56 | update(undefined, false);
|
57 | onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave(e);
|
58 | } : undefined
|
59 | }, rest), _react.default.createElement(ContextPressable.Provider, {
|
60 | value: state
|
61 | }, children));
|
62 | }
|
63 |
|
\ | No newline at end of file |