UNPKG

2.91 kBJavaScriptView Raw
1var $01d3f539e91688c8$exports = require("./context.main.js");
2var $3maub$reactariautils = require("@react-aria/utils");
3var $3maub$react = require("react");
4
5
6function $parcel$interopDefault(a) {
7 return a && a.__esModule ? a.default : a;
8}
9
10function $parcel$export(e, n, v, s) {
11 Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
12}
13
14$parcel$export(module.exports, "PressResponder", () => $3596bae48579386f$export$3351871ee4b288b8);
15$parcel$export(module.exports, "ClearPressResponder", () => $3596bae48579386f$export$cf75428e0b9ed1ea);
16/*
17 * Copyright 2020 Adobe. All rights reserved.
18 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19 * you may not use this file except in compliance with the License. You may obtain a copy
20 * of the License at http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software distributed under
23 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
24 * OF ANY KIND, either express or implied. See the License for the specific language
25 * governing permissions and limitations under the License.
26 */
27
28
29const $3596bae48579386f$export$3351871ee4b288b8 = /*#__PURE__*/ (0, ($parcel$interopDefault($3maub$react))).forwardRef(({ children: children, ...props }, ref)=>{
30 let isRegistered = (0, $3maub$react.useRef)(false);
31 let prevContext = (0, $3maub$react.useContext)((0, $01d3f539e91688c8$exports.PressResponderContext));
32 ref = (0, $3maub$reactariautils.useObjectRef)(ref || (prevContext === null || prevContext === void 0 ? void 0 : prevContext.ref));
33 let context = (0, $3maub$reactariautils.mergeProps)(prevContext || {}, {
34 ...props,
35 ref: ref,
36 register () {
37 isRegistered.current = true;
38 if (prevContext) prevContext.register();
39 }
40 });
41 (0, $3maub$reactariautils.useSyncRef)(prevContext, ref);
42 (0, $3maub$react.useEffect)(()=>{
43 if (!isRegistered.current) {
44 console.warn("A PressResponder was rendered without a pressable child. Either call the usePress hook, or wrap your DOM node with <Pressable> component.");
45 isRegistered.current = true; // only warn once in strict mode.
46 }
47 }, []);
48 return /*#__PURE__*/ (0, ($parcel$interopDefault($3maub$react))).createElement((0, $01d3f539e91688c8$exports.PressResponderContext).Provider, {
49 value: context
50 }, children);
51});
52function $3596bae48579386f$export$cf75428e0b9ed1ea({ children: children }) {
53 let context = (0, $3maub$react.useMemo)(()=>({
54 register: ()=>{}
55 }), []);
56 return /*#__PURE__*/ (0, ($parcel$interopDefault($3maub$react))).createElement((0, $01d3f539e91688c8$exports.PressResponderContext).Provider, {
57 value: context
58 }, children);
59}
60
61
62//# sourceMappingURL=PressResponder.main.js.map