Skip to content

Commit 4fdbc44

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Disable collapsable for Animated Components
Summary: When we were iterating on the Fabric renderer, animated components went through some iteration to ensure that animated shadow nodes were not flattened away. At the time, `collapsable` was not supported on iOS, even in Fabric, because the legacy renderer would not publish the `collapsable` prop on the view config. This has since been fixed and `collapsable` is supported on both Android and iOS. We no longer need the `nativeID` workaround to prevent view flattening. For use cases of the JavaScript driver and legacy renderers, this change will cause views which used to be flattened to no longer be flattened. This seems like an appropriate change considering the direction that we are moving (in which everything is eventually transitioned to using the Fabric renderer). Changelog: [Android][Changed] - Native views backing Animated.View (w/ JavaScript-driven animations) will no longer be flattened; this should be a transparent change. Reviewed By: lunaleaps, mdvacca Differential Revision: D31223031 fbshipit-source-id: 48dc63471eef406f4c215bfea0b3ef82a05d4b24
1 parent c9c14ef commit 4fdbc44

File tree

7 files changed

+13
-56
lines changed

7 files changed

+13
-56
lines changed

Libraries/Animated/components/AnimatedImage.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const createAnimatedComponent = require('../createAnimatedComponent');
1515

1616
import type {AnimatedComponentType} from '../createAnimatedComponent';
1717

18-
module.exports = (createAnimatedComponent((Image: $FlowFixMe), {
19-
collapsable: false,
20-
}): AnimatedComponentType<
18+
module.exports = (createAnimatedComponent(
19+
(Image: $FlowFixMe),
20+
): AnimatedComponentType<
2121
React.ElementConfig<typeof Image>,
2222
React.ElementRef<typeof Image>,
2323
>);

Libraries/Animated/components/AnimatedScrollView.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const ScrollViewWithEventThrottle = React.forwardRef((props, ref) => (
2222
<ScrollView scrollEventThrottle={0.0001} {...props} ref={ref} />
2323
));
2424

25-
module.exports = (createAnimatedComponent(ScrollViewWithEventThrottle, {
26-
collapsable: false,
27-
}): AnimatedComponentType<
25+
module.exports = (createAnimatedComponent(
26+
ScrollViewWithEventThrottle,
27+
): AnimatedComponentType<
2828
React.ElementConfig<typeof ScrollView>,
2929
React.ElementRef<typeof ScrollView>,
3030
>);

Libraries/Animated/components/AnimatedText.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const createAnimatedComponent = require('../createAnimatedComponent');
1515

1616
import type {AnimatedComponentType} from '../createAnimatedComponent';
1717

18-
module.exports = (createAnimatedComponent((Text: $FlowFixMe), {
19-
collapsable: false,
20-
}): AnimatedComponentType<
18+
module.exports = (createAnimatedComponent(
19+
(Text: $FlowFixMe),
20+
): AnimatedComponentType<
2121
React.ElementConfig<typeof Text>,
2222
React.ElementRef<typeof Text>,
2323
>);

Libraries/Animated/components/AnimatedView.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const createAnimatedComponent = require('../createAnimatedComponent');
1515

1616
import type {AnimatedComponentType} from '../createAnimatedComponent';
1717

18-
module.exports = (createAnimatedComponent(View, {
19-
collapsable: true,
20-
}): AnimatedComponentType<
18+
module.exports = (createAnimatedComponent(View): AnimatedComponentType<
2119
React.ElementConfig<typeof View>,
2220
React.ElementRef<typeof View>,
2321
>);

Libraries/Animated/createAnimatedComponent.js

+3-34
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,8 @@ export type AnimatedComponentType<
3939
Instance,
4040
>;
4141

42-
type AnimatedComponentOptions = {
43-
collapsable?: boolean,
44-
};
45-
4642
function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
4743
Component: React.AbstractComponent<Props, Instance>,
48-
options?: AnimatedComponentOptions,
4944
): AnimatedComponentType<Props, Instance> {
5045
invariant(
5146
typeof Component !== 'function' ||
@@ -210,39 +205,13 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
210205
this.props.passthroughAnimatedPropExplicitValues || {};
211206
const mergedStyle = {...style, ...passthruStyle};
212207

213-
// On Fabric, we always want to ensure the container Animated View is *not*
214-
// flattened.
215-
// Because we do not get a host component ref immediately and thus cannot
216-
// do a proper Fabric vs non-Fabric detection immediately, we default to assuming
217-
// that Fabric *is* enabled until we know otherwise.
218-
// Thus, in Fabric, this view will never be flattened. In non-Fabric, the view will
219-
// not be flattened during the initial render but may be flattened in the second render
220-
// and onwards.
221-
const forceNativeIdFabric =
222-
(this._component == null &&
223-
(options?.collapsable === false || props.collapsable !== true)) ||
224-
this._isFabric();
225-
226-
const forceNativeId =
227-
props.collapsable ??
228-
(this._propsAnimated.__isNative ||
229-
forceNativeIdFabric ||
230-
options?.collapsable === false);
231-
// The native driver updates views directly through the UI thread so we
232-
// have to make sure the view doesn't get optimized away because it cannot
233-
// go through the NativeViewHierarchyManager since it operates on the shadow
234-
// thread. TODO: T68258846
235-
const collapsableProps = forceNativeId
236-
? {
237-
nativeID: props.nativeID ?? 'animatedComponent',
238-
collapsable: false,
239-
}
240-
: {};
208+
// Force `collapsable` to be false so that native view is not flattened.
209+
// Flattened views cannot be accurately referenced by a native driver.
241210
return (
242211
<Component
243212
{...props}
244213
{...passthruProps}
245-
{...collapsableProps}
214+
collapsable={false}
246215
style={mergedStyle}
247216
ref={this._setComponentRef}
248217
/>

Libraries/Components/Touchable/__tests__/__snapshots__/TouchableOpacity-test.js.snap

-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ exports[`TouchableOpacity renders correctly 1`] = `
55
accessible={true}
66
collapsable={false}
77
focusable={false}
8-
nativeID="animatedComponent"
98
onClick={[Function]}
109
onResponderGrant={[Function]}
1110
onResponderMove={[Function]}
@@ -35,7 +34,6 @@ exports[`TouchableOpacity renders in disabled state when a disabled prop is pass
3534
accessible={true}
3635
collapsable={false}
3736
focusable={false}
38-
nativeID="animatedComponent"
3937
onClick={[Function]}
4038
onResponderGrant={[Function]}
4139
onResponderMove={[Function]}
@@ -65,7 +63,6 @@ exports[`TouchableOpacity renders in disabled state when a key disabled in acces
6563
accessible={true}
6664
collapsable={false}
6765
focusable={false}
68-
nativeID="animatedComponent"
6966
onClick={[Function]}
7067
onResponderGrant={[Function]}
7168
onResponderMove={[Function]}

Libraries/Components/__tests__/__snapshots__/Button-test.js.snap

-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ exports[`<Button /> should be disabled and it should set accessibilityState to d
1111
accessible={true}
1212
collapsable={false}
1313
focusable={false}
14-
nativeID="animatedComponent"
1514
onClick={[Function]}
1615
onResponderGrant={[Function]}
1716
onResponderMove={[Function]}
@@ -66,7 +65,6 @@ exports[`<Button /> should be disabled when disabled is empty and accessibilityS
6665
accessible={true}
6766
collapsable={false}
6867
focusable={false}
69-
nativeID="animatedComponent"
7068
onClick={[Function]}
7169
onResponderGrant={[Function]}
7270
onResponderMove={[Function]}
@@ -121,7 +119,6 @@ exports[`<Button /> should be disabled when disabled={true} and accessibilitySta
121119
accessible={true}
122120
collapsable={false}
123121
focusable={false}
124-
nativeID="animatedComponent"
125122
onClick={[Function]}
126123
onResponderGrant={[Function]}
127124
onResponderMove={[Function]}
@@ -176,7 +173,6 @@ exports[`<Button /> should not be disabled when disabled={false} and accessibili
176173
accessible={true}
177174
collapsable={false}
178175
focusable={false}
179-
nativeID="animatedComponent"
180176
onClick={[Function]}
181177
onResponderGrant={[Function]}
182178
onResponderMove={[Function]}
@@ -227,7 +223,6 @@ exports[`<Button /> should not be disabled when disabled={false} and accessibili
227223
accessible={true}
228224
collapsable={false}
229225
focusable={false}
230-
nativeID="animatedComponent"
231226
onClick={[Function]}
232227
onResponderGrant={[Function]}
233228
onResponderMove={[Function]}
@@ -278,7 +273,6 @@ exports[`<Button /> should overwrite accessibilityState with value of disabled p
278273
accessible={true}
279274
collapsable={false}
280275
focusable={false}
281-
nativeID="animatedComponent"
282276
onClick={[Function]}
283277
onResponderGrant={[Function]}
284278
onResponderMove={[Function]}
@@ -328,7 +322,6 @@ exports[`<Button /> should render as expected 1`] = `
328322
accessible={true}
329323
collapsable={false}
330324
focusable={false}
331-
nativeID="animatedComponent"
332325
onClick={[Function]}
333326
onResponderGrant={[Function]}
334327
onResponderMove={[Function]}

0 commit comments

Comments
 (0)