Skip to content

Commit

Permalink
Animated: Decouple __attach from new AnimatedProps
Browse files Browse the repository at this point in the history
Summary:
Decouples `__attach` from the constructor in `AnimatedProps`.

This change will enable the instantiation of `AnimatedProps` (and subsequent invocation of `__getValue()`) without having to trigger side effects until after mount or update. This is important in order for `Animated` to ever become safe for Concurrent Mode.

Changelog:
[Internal]

Reviewed By: lunaleaps

Differential Revision: D28271628

fbshipit-source-id: 6ccfed6de79382cecdfa6939c7dad3134e1ecaaa
  • Loading branch information
yungsters authored and pull[bot] committed Jun 18, 2021
1 parent b91e4b7 commit 8341411
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Libraries/Animated/__tests__/Animated-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ describe('Animated tests', () => {
callback,
);

expect(anim.__getChildren().length).toBe(3);

expect(node.__getValue()).toEqual({
style: {
backgroundColor: 'red',
Expand All @@ -71,6 +69,12 @@ describe('Animated tests', () => {
},
});

expect(anim.__getChildren().length).toBe(0);

node.__attach();

expect(anim.__getChildren().length).toBe(3);

anim.setValue(0.5);

expect(callback).toBeCalled();
Expand Down Expand Up @@ -811,6 +815,10 @@ describe('Animated tests', () => {
},
});

node.__attach();

expect(callback.mock.calls.length).toBe(0);

vec.setValue({x: 42, y: 1492});

expect(callback.mock.calls.length).toBe(2); // once each for x, y
Expand Down Expand Up @@ -904,6 +912,7 @@ describe('Animated tests', () => {
},
callback,
);
view.__attach();
const listener = jest.fn();
const id = value4.addListener(listener);
value3.setValue(137);
Expand Down
1 change: 1 addition & 0 deletions Libraries/Animated/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
nextProps,
this._animatedPropsCallback,
);
this._propsAnimated.__attach();

// When you call detach, it removes the element from the parent list
// of children. If it goes to 0, then the parent also detaches itself
Expand Down
1 change: 0 additions & 1 deletion Libraries/Animated/nodes/AnimatedProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class AnimatedProps extends AnimatedNode {
}
this._props = props;
this._callback = callback;
this.__attach();
}

__getValue(): Object {
Expand Down

0 comments on commit 8341411

Please sign in to comment.