mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary:
We are working on making the empty object literal `{}` have the type `{}` - i.e. exact empty object - rather than being unsealed.
Making this change exposes a variety of errors. We can prevent these errors by annotating what we want the type of the empty object to be.
Reduces Xplat error diff to 2.3k
- Announcement: [post](https://fb.workplace.com/groups/flowlang/posts/903386663600331)
- Support group: [Flow Support](https://fb.workplace.com/groups/flow)
drop-conflicts
Format:
```
arc f
```
Sort imports
```
hg l -n | xargs js1 lint --fix --rule 'fb-tools/sort-requires'
```
Changelog: [Internal]
Reviewed By: samwgoldman
Differential Revision: D36086696
fbshipit-source-id: 90447279f2e6e38f44189b74ec0297719f7adf58
129 lines
3.7 KiB
JavaScript
129 lines
3.7 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {PlatformConfig} from '../AnimatedPlatformConfig';
|
|
|
|
const flattenStyle = require('../../StyleSheet/flattenStyle');
|
|
const NativeAnimatedHelper = require('../NativeAnimatedHelper');
|
|
const AnimatedNode = require('./AnimatedNode');
|
|
const AnimatedTransform = require('./AnimatedTransform');
|
|
const AnimatedWithChildren = require('./AnimatedWithChildren');
|
|
|
|
class AnimatedStyle extends AnimatedWithChildren {
|
|
_style: Object;
|
|
|
|
constructor(style: any) {
|
|
super();
|
|
style = flattenStyle(style) || {};
|
|
if (style.transform) {
|
|
style = {
|
|
...style,
|
|
transform: new AnimatedTransform(style.transform),
|
|
};
|
|
}
|
|
this._style = style;
|
|
}
|
|
|
|
// Recursively get values for nested styles (like iOS's shadowOffset)
|
|
_walkStyleAndGetValues(style: any) {
|
|
const updatedStyle: {[string]: any | {...}} = {};
|
|
for (const key in style) {
|
|
const 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;
|
|
}
|
|
|
|
__getValue(): Object {
|
|
return this._walkStyleAndGetValues(this._style);
|
|
}
|
|
|
|
// Recursively get animated values for nested styles (like iOS's shadowOffset)
|
|
_walkStyleAndGetAnimatedValues(style: any) {
|
|
const updatedStyle: {[string]: any | {...}} = {};
|
|
for (const key in style) {
|
|
const 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;
|
|
}
|
|
|
|
__getAnimatedValue(): Object {
|
|
return this._walkStyleAndGetAnimatedValues(this._style);
|
|
}
|
|
|
|
__attach(): void {
|
|
for (const key in this._style) {
|
|
const value = this._style[key];
|
|
if (value instanceof AnimatedNode) {
|
|
value.__addChild(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
__detach(): void {
|
|
for (const key in this._style) {
|
|
const value = this._style[key];
|
|
if (value instanceof AnimatedNode) {
|
|
value.__removeChild(this);
|
|
}
|
|
}
|
|
super.__detach();
|
|
}
|
|
|
|
__makeNative(platformConfig: ?PlatformConfig) {
|
|
for (const key in this._style) {
|
|
const value = this._style[key];
|
|
if (value instanceof AnimatedNode) {
|
|
value.__makeNative(platformConfig);
|
|
}
|
|
}
|
|
super.__makeNative(platformConfig);
|
|
}
|
|
|
|
__getNativeConfig(): Object {
|
|
const styleConfig: {[string]: ?number} = {};
|
|
for (const styleKey in this._style) {
|
|
if (this._style[styleKey] instanceof AnimatedNode) {
|
|
const style = this._style[styleKey];
|
|
style.__makeNative(this.__getPlatformConfig());
|
|
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,
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = AnimatedStyle;
|