@tamagui/react-native-web-lite
Version:
React Native for Web
109 lines (108 loc) • 4.75 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
mod
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var TouchableOpacity_exports = {};
__export(TouchableOpacity_exports, {
default: () => TouchableOpacity_default
});
module.exports = __toCommonJS(TouchableOpacity_exports);
var import_jsx_runtime = require("react/jsx-runtime"), React = __toESM(require("react")), import_react = require("react"), import_react_native_web_internals = require("@tamagui/react-native-web-internals"), import_View = __toESM(require("./View"));
function TouchableOpacity(props, forwardedRef) {
var { activeOpacity, delayPressIn, delayPressOut, delayLongPress, disabled, focusable, onLongPress, onPress, onPressIn, onPressOut, rejectResponderTermination, style, ...rest } = props, hostRef = (0, import_react.useRef)(null), setRef = (0, import_react_native_web_internals.useMergeRefs)(forwardedRef, hostRef), [duration, setDuration] = (0, import_react.useState)("0s"), [opacityOverride, setOpacityOverride] = (0, import_react.useState)(null), setOpacityTo = (0, import_react.useCallback)(function(value, duration2) {
setOpacityOverride(value), setDuration(duration2 ? `${duration2 / 1e3}s` : "0s");
}, [
setOpacityOverride,
setDuration
]), setOpacityActive = (0, import_react.useCallback)(function(duration2) {
setOpacityTo(activeOpacity ?? 0.2, duration2);
}, [
activeOpacity,
setOpacityTo
]), setOpacityInactive = (0, import_react.useCallback)(function(duration2) {
setOpacityTo(null, duration2);
}, [
setOpacityTo
]), pressConfig = (0, import_react.useMemo)(function() {
return {
cancelable: !rejectResponderTermination,
disabled,
delayLongPress,
delayPressStart: delayPressIn,
delayPressEnd: delayPressOut,
onLongPress,
onPress,
onPressStart(event) {
var isGrant = event.dispatchConfig != null ? event.dispatchConfig.registrationName === "onResponderGrant" : event.type === "keydown";
setOpacityActive(isGrant ? 0 : 150), onPressIn != null && onPressIn(event);
},
onPressEnd(event) {
setOpacityInactive(250), onPressOut != null && onPressOut(event);
}
};
}, [
delayLongPress,
delayPressIn,
delayPressOut,
disabled,
onLongPress,
onPress,
onPressIn,
onPressOut,
rejectResponderTermination,
setOpacityActive,
setOpacityInactive
]), pressEventHandlers = (0, import_react_native_web_internals.usePressEvents)(hostRef, pressConfig);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_View.default, {
...rest,
...pressEventHandlers,
accessibilityDisabled: disabled,
focusable: !disabled && focusable !== !1,
ref: setRef,
style: [
styles.root,
!disabled && styles.actionable,
style,
opacityOverride != null && {
opacity: opacityOverride
},
{
transitionDuration: duration
}
]
});
}
var styles = import_react_native_web_internals.StyleSheet.create({
root: {
transitionProperty: "opacity",
transitionDuration: "0.15s",
userSelect: "none"
},
actionable: {
cursor: "pointer",
touchAction: "manipulation"
}
}), MemoedTouchableOpacity = /* @__PURE__ */ React.memo(/* @__PURE__ */ React.forwardRef(TouchableOpacity));
MemoedTouchableOpacity.displayName = "TouchableOpacity";
MemoedTouchableOpacity.Mixin = {};
var TouchableOpacity_default = MemoedTouchableOpacity;
//# sourceMappingURL=TouchableOpacity.js.map