create-expo-cljs-app
Version:
Create a react native application with Expo and Shadow-CLJS!
158 lines (119 loc) • 5.59 kB
JavaScript
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
;
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
import AnimatedNode from './AnimatedNode';
import AnimatedTransform from './AnimatedTransform';
import AnimatedWithChildren from './AnimatedWithChildren';
import NativeAnimatedHelper from '../NativeAnimatedHelper';
import flattenStyle from '../../../../exports/StyleSheet/flattenStyle';
var AnimatedStyle = /*#__PURE__*/function (_AnimatedWithChildren) {
_inheritsLoose(AnimatedStyle, _AnimatedWithChildren);
function AnimatedStyle(style) {
var _this;
_this = _AnimatedWithChildren.call(this) || this;
style = flattenStyle(style) || {};
if (style.transform) {
style = _objectSpread(_objectSpread({}, style), {}, {
transform: new AnimatedTransform(style.transform)
});
}
_this._style = style;
return _this;
} // Recursively get values for nested styles (like iOS's shadowOffset)
var _proto = AnimatedStyle.prototype;
_proto._walkStyleAndGetValues = function _walkStyleAndGetValues(style) {
var updatedStyle = {};
for (var key in style) {
var value = style[key];
if (value instanceof AnimatedNode) {
if (!value.__isNative) {
// We cannot use value of natively driven nodes this way as the value we have access from
// JS may not be up to date.
updatedStyle[key] = value.__getValue();
}
} else if (value && !Array.isArray(value) && typeof value === 'object') {
// Support animating nested values (for example: shadowOffset.height)
updatedStyle[key] = this._walkStyleAndGetValues(value);
} else {
updatedStyle[key] = value;
}
}
return updatedStyle;
};
_proto.__getValue = function __getValue() {
return this._walkStyleAndGetValues(this._style);
} // Recursively get animated values for nested styles (like iOS's shadowOffset)
;
_proto._walkStyleAndGetAnimatedValues = function _walkStyleAndGetAnimatedValues(style) {
var updatedStyle = {};
for (var key in style) {
var value = style[key];
if (value instanceof AnimatedNode) {
updatedStyle[key] = value.__getAnimatedValue();
} else if (value && !Array.isArray(value) && typeof value === 'object') {
// Support animating nested values (for example: shadowOffset.height)
updatedStyle[key] = this._walkStyleAndGetAnimatedValues(value);
}
}
return updatedStyle;
};
_proto.__getAnimatedValue = function __getAnimatedValue() {
return this._walkStyleAndGetAnimatedValues(this._style);
};
_proto.__attach = function __attach() {
for (var key in this._style) {
var value = this._style[key];
if (value instanceof AnimatedNode) {
value.__addChild(this);
}
}
};
_proto.__detach = function __detach() {
for (var key in this._style) {
var value = this._style[key];
if (value instanceof AnimatedNode) {
value.__removeChild(this);
}
}
_AnimatedWithChildren.prototype.__detach.call(this);
};
_proto.__makeNative = function __makeNative() {
for (var key in this._style) {
var value = this._style[key];
if (value instanceof AnimatedNode) {
value.__makeNative();
}
}
_AnimatedWithChildren.prototype.__makeNative.call(this);
};
_proto.__getNativeConfig = function __getNativeConfig() {
var styleConfig = {};
for (var styleKey in this._style) {
if (this._style[styleKey] instanceof AnimatedNode) {
var style = this._style[styleKey];
style.__makeNative();
styleConfig[styleKey] = style.__getNativeTag();
} // Non-animated styles are set using `setNativeProps`, no need
// to pass those as a part of the node config
}
NativeAnimatedHelper.validateStyles(styleConfig);
return {
type: 'style',
style: styleConfig
};
};
return AnimatedStyle;
}(AnimatedWithChildren);
export default AnimatedStyle;