Skip to content

Commit cf02bd9

Browse files
janicduplessisfacebook-github-bot
authored andcommitted
Fix Animated Value initialized with undefined in ScrollView (#28349)
Summary: 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
1 parent 7dff0f4 commit cf02bd9

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Libraries/Components/ScrollView/ScrollView.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,9 @@ class ScrollView extends React.Component<Props, State> {
716716
UNSAFE_componentWillMount() {
717717
this._scrollResponder.UNSAFE_componentWillMount();
718718
this._scrollAnimatedValue = new AnimatedImplementation.Value(
719-
this.props.contentOffset ? this.props.contentOffset.y : 0,
720-
);
721-
this._scrollAnimatedValue.setOffset(
722-
this.props.contentInset ? this.props.contentInset.top || 0 : 0,
719+
this.props.contentOffset?.y ?? 0,
723720
);
721+
this._scrollAnimatedValue.setOffset(this.props.contentInset?.top ?? 0);
724722
this._stickyHeaderRefs = new Map();
725723
this._headerLayoutYs = new Map();
726724
}

0 commit comments

Comments
 (0)