From 950c2b2a731e3319051ab5b3e7eaabe6a7372b8e Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 22 Aug 2017 16:25:26 -0700 Subject: [PATCH] ScrollView: `contentOffset` validatation now respects `contentInset` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: > The property contentInset can change the maximum and minimum values of the content offset to allow scrolling outside of the scrollable area. Its type is UIEdgeInsets, which consists of 4 numbers: {top, left, bottom, right}. When you introduce an inset, you change the range of the content offset. For example, setting the content inset to have a value of 10 for its top value allows the content offset’s y value to reach -10. This introduces padding around the scrollable area. ( https://www.objc.io/issues/3-views/scroll-view/ ) See also: https://github.com/facebook/react-native/pull/15395 Reviewed By: mmmulani Differential Revision: D5607192 fbshipit-source-id: 1acd6a84e2bcfefc6e82861cfbdfe6247d0e4264 --- React/Views/RCTScrollView.m | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 18e5546d1e9..9e8eb88876f 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -315,15 +315,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) UIEdgeInsets contentInset = self.contentInset; CGSize contentSize = self.contentSize; - CGSize fullContentSize = CGSizeMake( - contentSize.width + contentInset.left + contentInset.right, - contentSize.height + contentInset.top + contentInset.bottom); CGSize boundsSize = self.bounds.size; self.contentOffset = CGPointMake( - MAX(0, MIN(originalOffset.x, fullContentSize.width - boundsSize.width)), - MAX(0, MIN(originalOffset.y, fullContentSize.height - boundsSize.height))); + MAX(-contentInset.top, MIN(contentSize.width - boundsSize.width + contentInset.bottom, originalOffset.x)), + MAX(-contentInset.left, MIN(contentSize.height - boundsSize.height + contentInset.right, originalOffset.y))); } #if !TARGET_OS_TV