@tamagui/react-native-web-lite
Version:
React Native for Web
136 lines • 4.71 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var AnimatedStyle_exports = {};
__export(AnimatedStyle_exports, {
AnimatedStyle: () => AnimatedStyle,
default: () => AnimatedStyle_default
});
module.exports = __toCommonJS(AnimatedStyle_exports);
var import_AnimatedNode = require("./AnimatedNode.cjs");
var import_AnimatedTransform = require("./AnimatedTransform.cjs");
var import_AnimatedWithChildren = require("./AnimatedWithChildren.cjs");
var import_NativeAnimatedHelper = require("../NativeAnimatedHelper.cjs");
var 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);
const animatedStyles = {};
for (const key in style) {
const value = style[key];
if (key === "transform" && Array.isArray(value)) {
animatedStyles[key] = new import_AnimatedTransform.AnimatedTransform(value);
} else if (value instanceof import_AnimatedNode.AnimatedNode) {
animatedStyles[key] = value;
} else if (value && !Array.isArray(value) && typeof value === "object") {
animatedStyles[key] = createAnimatedStyle(value);
}
}
return animatedStyles;
}
class AnimatedStyle extends import_AnimatedWithChildren.AnimatedWithChildren {
_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];
if (value instanceof import_AnimatedNode.AnimatedNode) {
if (!value.__isNative) {
updatedStyle[key] = value.__getValue();
}
} else if (value && !Array.isArray(value) && typeof value === "object") {
updatedStyle[key] = this._walkStyleAndGetValues(value);
} else {
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];
if (value instanceof import_AnimatedNode.AnimatedNode) {
updatedStyle[key] = value.__getAnimatedValue();
} else if (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];
if (value instanceof import_AnimatedNode.AnimatedNode) {
value.__addChild(this);
}
}
}
__detach() {
for (const key in this._style) {
const value = this._style[key];
if (value instanceof import_AnimatedNode.AnimatedNode) {
value.__removeChild(this);
}
}
super.__detach();
}
__makeNative() {
for (const key in this._style) {
const value = this._style[key];
if (value instanceof import_AnimatedNode.AnimatedNode) {
value.__makeNative();
}
}
super.__makeNative();
}
__getNativeConfig() {
const styleConfig = {};
for (const styleKey in this._style) {
if (this._style[styleKey] instanceof import_AnimatedNode.AnimatedNode) {
const style = this._style[styleKey];
style.__makeNative();
styleConfig[styleKey] = style.__getNativeTag();
}
}
import_NativeAnimatedHelper.NativeAnimatedHelper.validateStyles(styleConfig);
return {
type: "style",
style: styleConfig
};
}
}
var AnimatedStyle_default = AnimatedStyle;