From fa1d4e8d81a4d88f6bbca5ea410e75cbcae2c854 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 18 Jul 2017 14:33:49 -0700 Subject: [PATCH] ScrollView/TextInput: The amnesty of `scrollRectToVisible` Reviewed By: javache Differential Revision: D5414438 fbshipit-source-id: 45b6a32bc2584ed99efd1514d724e2b5ca29d8e9 --- React/Views/RCTScrollView.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 9c4be9d6f..24d129ba8 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -214,9 +214,21 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) } } -- (void)scrollRectToVisible:(__unused CGRect)rect animated:(__unused BOOL)animated +- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated { - // noop + // Limiting scroll area to an area where we actually have content. + CGSize contentSize = self.contentSize; + UIEdgeInsets contentInset = self.contentInset; + CGSize fullSize = CGSizeMake( + contentSize.width + contentInset.left + contentInset.right, + contentSize.height + contentInset.top + contentInset.bottom); + + rect = CGRectIntersection((CGRect){CGPointZero, fullSize}, rect); + if (CGRectIsNull(rect)) { + return; + } + + [super scrollRectToVisible:rect animated:animated]; } /**