@tamagui/react-native-web-lite
Version:
React Native for Web
103 lines (102 loc) • 4.92 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 AnimatedStyle_exports = {};
__export(AnimatedStyle_exports, {
default: () => AnimatedStyle_default
});
module.exports = __toCommonJS(AnimatedStyle_exports);
var import_AnimatedNode = __toESM(require("./AnimatedNode")), import_AnimatedTransform = __toESM(require("./AnimatedTransform")), import_AnimatedWithChildren = __toESM(require("./AnimatedWithChildren")), import_NativeAnimatedHelper = __toESM(require("../NativeAnimatedHelper")), import_react_native_web_internals = require("@tamagui/react-native-web-internals");
const flattenStyle = import_react_native_web_internals.StyleSheet.flatten;
function createAnimatedStyle(inputStyle) {
const style = flattenStyle(inputStyle), animatedStyles = {};
for (const key in style) {
const value = style[key];
key === "transform" && Array.isArray(value) ? animatedStyles[key] = new import_AnimatedTransform.default(value) : value instanceof import_AnimatedNode.default ? animatedStyles[key] = value : value && !Array.isArray(value) && typeof value == "object" && (animatedStyles[key] = createAnimatedStyle(value));
}
return animatedStyles;
}
class AnimatedStyle extends import_AnimatedWithChildren.default {
_inputStyle;
_style;
constructor(style) {
super(), this._inputStyle = style, this._style = createAnimatedStyle(style);
}
// Recursively get values for nested styles (like iOS's shadowOffset)
_walkStyleAndGetValues(style) {
const updatedStyle = {};
for (const key in style) {
const value = style[key];
value instanceof import_AnimatedNode.default ? value.__isNative || (updatedStyle[key] = value.__getValue()) : value && !Array.isArray(value) && typeof value == "object" ? updatedStyle[key] = this._walkStyleAndGetValues(value) : updatedStyle[key] = value;
}
return updatedStyle;
}
__getValue() {
return [this._inputStyle, this._walkStyleAndGetValues(this._style)];
}
// Recursively get animated values for nested styles (like iOS's shadowOffset)
_walkStyleAndGetAnimatedValues(style) {
const updatedStyle = {};
for (const key in style) {
const value = style[key];
value instanceof import_AnimatedNode.default ? updatedStyle[key] = value.__getAnimatedValue() : value && !Array.isArray(value) && typeof value == "object" && (updatedStyle[key] = this._walkStyleAndGetAnimatedValues(value));
}
return updatedStyle;
}
__getAnimatedValue() {
return this._walkStyleAndGetAnimatedValues(this._style);
}
__attach() {
for (const key in this._style) {
const value = this._style[key];
value instanceof import_AnimatedNode.default && value.__addChild(this);
}
}
__detach() {
for (const key in this._style) {
const value = this._style[key];
value instanceof import_AnimatedNode.default && value.__removeChild(this);
}
super.__detach();
}
__makeNative() {
for (const key in this._style) {
const value = this._style[key];
value instanceof import_AnimatedNode.default && value.__makeNative();
}
super.__makeNative();
}
__getNativeConfig() {
const styleConfig = {};
for (const styleKey in this._style)
if (this._style[styleKey] instanceof import_AnimatedNode.default) {
const style = this._style[styleKey];
style.__makeNative(), styleConfig[styleKey] = style.__getNativeTag();
}
return import_NativeAnimatedHelper.default.validateStyles(styleConfig), {
type: "style",
style: styleConfig
};
}
}
var AnimatedStyle_default = AnimatedStyle;
//# sourceMappingURL=AnimatedStyle.js.map