-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Animated: Lazily Allocate AnimatedNode Instances (#46317)
Summary: Pull Request resolved: #46317 Changes `AnimatedProps` to avoid allocating `AnimatedStyle` (and `AnimatedTransform`, `AnimatedObject`) unless necessary. This not only reduces memory and traversal overhead, but it enables us to implement allowlist strategies to prune unnecessary traversals. Changelog: [General][Changed] - Animated now omits `style` if the supplied value is null, undefined, or not an object. Previously, it would emit an empty `style` object. [General][Changed] - Animated now resolves `style` to the original prop value if it contains no `AnimatedNode` instances. Previously, it would resolve to a flattened style object. Reviewed By: javache Differential Revision: D62117423 fbshipit-source-id: 34b0c9940be5b6f5d94467993a5344406cc56f93
- Loading branch information
1 parent
9e6c4fd
commit ca234ba
Showing
6 changed files
with
131 additions
and
42 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/react-native/Libraries/Animated/__tests__/AnimatedProps-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* 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 strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import AnimatedProps from '../nodes/AnimatedProps'; | ||
|
||
describe('AnimatedProps', () => { | ||
function getValue(inputProps: {[string]: mixed}) { | ||
const animatedProps = new AnimatedProps(inputProps, jest.fn()); | ||
return animatedProps.__getValue(); | ||
} | ||
|
||
it('returns original `style` if it has no nodes', () => { | ||
const style = {color: 'red'}; | ||
expect(getValue({style}).style).toBe(style); | ||
}); | ||
|
||
it('returns original `style` for invalid style values', () => { | ||
const values = [undefined, null, function () {}, true, 123, 'foo']; | ||
for (const value of values) { | ||
expect(getValue({style: value})).toEqual({style: value}); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters