Skip to content

Commit 66e72bb

Browse files
yungstersfacebook-github-bot
authored andcommitted
Animated: Forward Ref to Component
Summary: Changes `createAnimatedComponent` so that a `ref` assigned to an Animated component will now be forwarded to the internal component. Previously, a ref to the internal component was accessed using the `getNode` method. The `getNode` method is now deprecated and will return the same `ref` but show a deprecation error. Changelog: [General] [Changed] - Refs on an Animated component are now the internal component. The `getNode` call has been deprecated. Reviewed By: TheSavior Differential Revision: D18290474 fbshipit-source-id: 5849809583a17624a89071db8be1282a12caedf3
1 parent 894ee72 commit 66e72bb

File tree

6 files changed

+311
-317
lines changed

6 files changed

+311
-317
lines changed

Libraries/Animated/src/__tests__/Animated-test.js

+15-33
Original file line numberDiff line numberDiff line change
@@ -95,51 +95,33 @@ describe('Animated tests', () => {
9595
});
9696

9797
it('does not detach on updates', () => {
98-
const anim = new Animated.Value(0);
99-
anim.__detach = jest.fn();
98+
const opacity = new Animated.Value(0);
99+
opacity.__detach = jest.fn();
100100

101-
const c = new Animated.View();
102-
c.props = {
103-
style: {
104-
opacity: anim,
105-
},
106-
};
107-
c.UNSAFE_componentWillMount();
101+
const root = TestRenderer.create(<Animated.View style={{opacity}} />);
102+
expect(opacity.__detach).not.toBeCalled();
108103

109-
expect(anim.__detach).not.toBeCalled();
110-
c._component = {};
111-
c.UNSAFE_componentWillReceiveProps({
112-
style: {
113-
opacity: anim,
114-
},
115-
});
116-
expect(anim.__detach).not.toBeCalled();
104+
root.update(<Animated.View style={{opacity}} />);
105+
expect(opacity.__detach).not.toBeCalled();
117106

118-
c.componentWillUnmount();
119-
expect(anim.__detach).toBeCalled();
107+
root.unmount();
108+
expect(opacity.__detach).toBeCalled();
120109
});
121110

122111
it('stops animation when detached', () => {
123-
const anim = new Animated.Value(0);
112+
const opacity = new Animated.Value(0);
124113
const callback = jest.fn();
125114

126-
const c = new Animated.View();
127-
c.props = {
128-
style: {
129-
opacity: anim,
130-
},
131-
};
132-
c.UNSAFE_componentWillMount();
115+
const root = TestRenderer.create(<Animated.View style={{opacity}} />);
133116

134-
Animated.timing(anim, {
117+
Animated.timing(opacity, {
135118
toValue: 10,
136119
duration: 1000,
137120
useNativeDriver: false,
138121
}).start(callback);
139-
c._component = {};
140-
c.componentWillUnmount();
141122

142-
expect(callback).toBeCalledWith({finished: false});
123+
root.unmount();
124+
143125
expect(callback).toBeCalledWith({finished: false});
144126
});
145127

@@ -198,15 +180,15 @@ describe('Animated tests', () => {
198180
<Animated.View style={{opacity}} />,
199181
);
200182

201-
expect(testRenderer.toJSON()).toMatchSnapshot();
183+
expect(testRenderer.toJSON().props.style.opacity).toEqual(0);
202184

203185
Animated.timing(opacity, {
204186
toValue: 1,
205187
duration: 0,
206188
useNativeDriver: false,
207189
}).start();
208190

209-
expect(testRenderer.toJSON()).toMatchSnapshot();
191+
expect(testRenderer.toJSON().props.style.opacity).toEqual(1);
210192
});
211193

212194
it('warns if `useNativeDriver` is missing', () => {

0 commit comments

Comments
 (0)