From b739c115f99a3e28cb22afb700d2c0ed4d89e4c6 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 28 Nov 2018 17:27:21 -0800 Subject: [PATCH] Summary: Calling -[UIScrollView setContentOffset] with NaN values can cause a crash. That's not clear why exactly the computation returns NaN sometime, but the implemented sanitizing should help to detect this problem during development (and this also prevents the app from crashing). See attached task for more details. Reviewed By: fkgozali Differential Revision: D13242729 fbshipit-source-id: 747bf1b42e02597e9f1300eee24547563ab29b27 --- React/Views/ScrollView/RCTScrollView.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/React/Views/ScrollView/RCTScrollView.m b/React/Views/ScrollView/RCTScrollView.m index 5d5f947d0e6..725deadb1af 100644 --- a/React/Views/ScrollView/RCTScrollView.m +++ b/React/Views/ScrollView/RCTScrollView.m @@ -303,7 +303,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) contentOffset.y = -(scrollViewSize.height - subviewSize.height) / 2.0; } } - super.contentOffset = contentOffset; + + super.contentOffset = CGPointMake( + RCTSanitizeNaNValue(contentOffset.x, @"scrollView.contentOffset.x"), + RCTSanitizeNaNValue(contentOffset.y, @"scrollView.contentOffset.y")); } - (void)setFrame:(CGRect)frame