From 2cdf9694b56e76477dde572eb3dc38be31361eab Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Mon, 13 May 2019 13:00:14 -0700 Subject: [PATCH] Fixes ScrollView centerContent not work in some cases (#24817) Summary: The bug description can see https://github.com/facebook/react-native/issues/24688, we add `contentView` size check before center the content, because in some cases, the contentView's size not yet be calculated, in those cases, we don't adjust the `contentOffset`. cc. cpojer . [iOS] [Fixed] - Fixes ScrollView centerContent not work in some cases Pull Request resolved: https://github.com/facebook/react-native/pull/24817 Differential Revision: D15322502 Pulled By: sahrens fbshipit-source-id: e2081f13e9f2e8597a379a9db1607451ea496909 --- React/Views/ScrollView/RCTScrollView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/React/Views/ScrollView/RCTScrollView.m b/React/Views/ScrollView/RCTScrollView.m index e77ff1d273c..7e73924379f 100644 --- a/React/Views/ScrollView/RCTScrollView.m +++ b/React/Views/ScrollView/RCTScrollView.m @@ -298,7 +298,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) - (void)setContentOffset:(CGPoint)contentOffset { UIView *contentView = [self contentView]; - if (contentView && _centerContent) { + if (contentView && _centerContent && !CGSizeEqualToSize(contentView.frame.size, CGSizeZero)) { CGSize subviewSize = contentView.frame.size; CGSize scrollViewSize = self.bounds.size; if (subviewSize.width <= scrollViewSize.width) {