Skip to content
Browse files
Fix Animated Value initialized with undefined in ScrollView (#28349)
When passing an object to contentOffset that doesn't have `y` prop set it causes the following error:

 Error: AnimatedValue: Attempting to set value to undefined

This error is located at:
    in ScrollView (at src/index.js:638)

This happens since a runtime check was added to the `AnimatedValue` constructor. (a3aaa47)

According to flow types the object passed to contentOffset should always contain both x and y props but since it worked before when y is undefined I think its fine to patch the runtime behaviour defensively, especially since the code change is simple.

## Changelog

[General] [Fixed] - Fix Animated Value initialized with undefined in ScrollView
Pull Request resolved: #28349

Test Plan: Tested that the crash no longer reproduces when passing an empty object to contentOffset.

Reviewed By: cpojer

Differential Revision: D20601664

Pulled By: hramos

fbshipit-source-id: b098a2dd1e702f995a9a92fa6e4e9a204187dac4
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Mar 24, 2020
1 parent 7dff0f4 commit cf02bd9b765e29ed8aa2bbf62661e89c84bb80e5
Showing 1 changed file with 2 additions and 4 deletions.
@@ -716,11 +716,9 @@ class ScrollView extends React.Component<Props, State> {
UNSAFE_componentWillMount() {
this._scrollAnimatedValue = new AnimatedImplementation.Value(
this.props.contentOffset ? this.props.contentOffset.y : 0,
this.props.contentInset ? || 0 : 0,
this.props.contentOffset?.y ?? 0,
this._scrollAnimatedValue.setOffset(this.props.contentInset?.top ?? 0);
this._stickyHeaderRefs = new Map();
this._headerLayoutYs = new Map();

0 comments on commit cf02bd9

Please sign in to comment.