Skip to content

Commit

Permalink
Make JS Animated Driver use forceUpdate in Fabric for list components
Browse files Browse the repository at this point in the history
Summary:
List components aren't host components so checking if the direct component itself's internals isn't sufficient to know if we are in Fabric. For lists, we have to call through some helper functions to get to the host component.

Hopefully we will fix this in the future by making the lists use forwardRef, or by getting rid of the JS Driver altogether, but for now, this is fine (TM).

Changelog: Internal

Reviewed By: mdvacca

Differential Revision: D19731067

fbshipit-source-id: 0e73583c6bf7c10de30e668a390d29718d31b295
  • Loading branch information
elicwhite authored and osdnk committed Mar 9, 2020
1 parent 8b127ea commit 6511795
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Libraries/Animated/src/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,28 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
typeof this._component.setNativeProps !== 'function' ||
// In Fabric, force animations to go through forceUpdate and skip setNativeProps
// eslint-disable-next-line dot-notation
this._component['_internalInstanceHandle']?.stateNode?.canonical != null
this._component['_internalInstanceHandle']?.stateNode?.canonical !=
null ||
// Some components have a setNativeProps function but aren't a host component
// such as lists like FlatList and SectionList. These should also use
// forceUpdate in Fabric since setNativeProps doesn't exist on the underlying
// host component. This crazy hack is essentially special casing those lists and
// ScrollView itself to use forceUpdate in Fabric.
// If these components end up using forwardRef then these hacks can go away
// as this._component would actually be the underlying host component and the above check
// would be sufficient.
(this._component.getNativeScrollRef != null &&
this._component.getNativeScrollRef() != null &&
// eslint-disable-next-line dot-notation
this._component.getNativeScrollRef()['_internalInstanceHandle']
?.stateNode?.canonical != null) ||
(this._component.getScrollResponder != null &&
this._component.getScrollResponder().getNativeScrollRef != null &&
this._component.getScrollResponder().getNativeScrollRef() != null &&
this._component.getScrollResponder().getNativeScrollRef()[
// eslint-disable-next-line dot-notation
'_internalInstanceHandle'
]?.stateNode?.canonical != null)
) {
this.forceUpdate();
} else if (!this._propsAnimated.__isNative) {
Expand Down

0 comments on commit 6511795

Please sign in to comment.