@tamagui/react-native-web-lite
Version:
React Native for Web
138 lines (137 loc) • 4.84 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 ModalAnimation_exports = {};
__export(ModalAnimation_exports, {
ModalAnimation: () => ModalAnimation
});
module.exports = __toCommonJS(ModalAnimation_exports);
var React = __toESM(require("react"), 1), import_react_native_web_internals = require("@tamagui/react-native-web-internals"), import_createElement = require("../createElement/index"), ANIMATION_DURATION = 300;
function getAnimationStyle(animationType, visible) {
return animationType === "slide" ? visible ? animatedSlideInStyles : animatedSlideOutStyles : animationType === "fade" ? visible ? animatedFadeInStyles : animatedFadeOutStyles : visible ? styles.container : styles.hidden;
}
function ModalAnimation(props) {
var animationType = props.animationType, children = props.children, onDismiss = props.onDismiss, onShow = props.onShow, visible = props.visible, _React$useState = React.useState(!1), isRendering = _React$useState[0], setIsRendering = _React$useState[1], wasVisible = React.useRef(!1), isAnimated = animationType && animationType !== "none", animationEndCallback = React.useCallback(
(e) => {
e && e.currentTarget !== e.target || (visible ? onShow && onShow() : (setIsRendering(!1), onDismiss && onDismiss()));
},
[onDismiss, onShow, visible]
);
return React.useEffect(() => {
visible && setIsRendering(!0), visible !== wasVisible.current && !isAnimated && animationEndCallback(), wasVisible.current = visible;
}, [isAnimated, visible, animationEndCallback]), isRendering || visible ? (0, import_createElement.createElement)("div", {
style: isRendering ? getAnimationStyle(animationType, visible) : styles.hidden,
onAnimationEnd: animationEndCallback,
children
}) : null;
}
var styles = import_react_native_web_internals.StyleSheet.create({
container: {
position: "fixed",
top: 0,
right: 0,
bottom: 0,
left: 0,
zIndex: 9999
},
animatedIn: {
animationDuration: ANIMATION_DURATION + "ms",
animationTimingFunction: "ease-in"
},
animatedOut: {
pointerEvents: "none",
animationDuration: ANIMATION_DURATION + "ms",
animationTimingFunction: "ease-out"
},
fadeIn: {
opacity: 1,
animationKeyframes: {
"0%": {
opacity: 0
},
"100%": {
opacity: 1
}
}
},
fadeOut: {
opacity: 0,
animationKeyframes: {
"0%": {
opacity: 1
},
"100%": {
opacity: 0
}
}
},
slideIn: {
transform: [
{
translateY: "0%"
}
],
animationKeyframes: {
"0%": {
transform: [
{
translateY: "100%"
}
]
},
"100%": {
transform: [
{
translateY: "0%"
}
]
}
}
},
slideOut: {
transform: [
{
translateY: "100%"
}
],
animationKeyframes: {
"0%": {
transform: [
{
translateY: "0%"
}
]
},
"100%": {
transform: [
{
translateY: "100%"
}
]
}
}
},
hidden: {
opacity: 0
}
}), animatedSlideInStyles = [styles.container, styles.animatedIn, styles.slideIn], animatedSlideOutStyles = [styles.container, styles.animatedOut, styles.slideOut], animatedFadeInStyles = [styles.container, styles.animatedIn, styles.fadeIn], animatedFadeOutStyles = [styles.container, styles.animatedOut, styles.fadeOut];
//# sourceMappingURL=ModalAnimation.js.map