Skip to content

Commit

Permalink
Fixed bug where layoutSubviews was called continuously for scrollview
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nicklockwood authored and Facebook Github Bot 2 committed Jun 6, 2016
1 parent a8d4fbb commit 329c716
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion React/Views/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,13 @@ - (void)reactBridgeDidFinishTransaction
lastIndex, subviewCount);
}
}
}

[_scrollView dockClosestSectionHeader];
- (void)didSetProps:(NSArray<NSString *> *)changedProps
{
if ([changedProps containsObject:@"stickyHeaderIndices"]) {
[_scrollView dockClosestSectionHeader];
}
}

// Note: setting several properties of UIScrollView has the effect of
Expand Down

0 comments on commit 329c716

Please sign in to comment.