UNPKG

3.35 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.ContextPressable = void 0;
7exports.MotionPressable = MotionPressable;
8var _react = _interopRequireWildcard(require("react"));
9var _reactNative = require("react-native");
10function _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); }
11function _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; }
12function _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); }
13const ContextPressable = /*#__PURE__*/(0, _react.createContext)({
14 pressed: false,
15 hovered: false
16});
17exports.ContextPressable = ContextPressable;
18function MotionPressable(props) {
19 // @ts-ignore Web props cause errors
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 /*#__PURE__*/_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 // @ts-ignore
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 // @ts-ignore
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), /*#__PURE__*/_react.default.createElement(ContextPressable.Provider, {
60 value: state
61 }, children));
62}
63//# sourceMappingURL=MotionPressable.js.map
\No newline at end of file