From 329c7168975a508de535ea7809ddd1d8c6ab5455 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Mon, 6 Jun 2016 05:20:51 -0700 Subject: [PATCH] Fixed bug where layoutSubviews was called continuously for scrollview Summary: RCTScrollView was calling `dockClosestSectionHeader` in `reactBridgeDidFinishTransaction`, which triggers a layout update. The reason for this was in case the `stickyHeaderIndexes` property was updated, which would require the headers to be adjusted. However, doing this in `reactBridgeDidFinishTransaction` had the affect of causing `layoutSubviews` to be called repeatedly every frame even if nothing had changed and the scrollview wasn't moving, which was especially expensive when combined with the `removeClippedSubviews` logic, that loops through every view to calculate if it needs to be clipped. This fix moves the `dockClosestSectionHeader` call into `didUpdateProps`, and checks that the stickyHeaderIndexes have actually changed before calling it. Reviewed By: javache Differential Revision: D3387607 fbshipit-source-id: c71e00c6fac48337a63d7fee7c7c23e016acf24e --- React/Views/RCTScrollView.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index a90de0d0436e6e..a2d1e5d859cf58 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -894,8 +894,13 @@ - (void)reactBridgeDidFinishTransaction lastIndex, subviewCount); } } +} - [_scrollView dockClosestSectionHeader]; +- (void)didSetProps:(NSArray *)changedProps +{ + if ([changedProps containsObject:@"stickyHeaderIndices"]) { + [_scrollView dockClosestSectionHeader]; + } } // Note: setting several properties of UIScrollView has the effect of