Perform clip update on RCTScrollView in increments of 50 pt

Summary:
This diff removes calls to `-updateClippedSubviews` by only re-clipping when the scroll view moves by a certain number of pixels.

leeway = 50pt => 46.9% of calls removed
leeway = 10pt => 13.2% " " "
This commit is contained in:
Alex Akers 2015-08-13 07:41:42 -07:00
parent b9dc29bcb3
commit 672b77f355
3 changed files with 50 additions and 1 deletions

View File

@ -256,6 +256,7 @@
83CBBA971A6020BB00E9B192 /* RCTTouchHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTouchHandler.m; sourceTree = "<group>"; }; 83CBBA971A6020BB00E9B192 /* RCTTouchHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTouchHandler.m; sourceTree = "<group>"; };
83CBBACA1A6023D300E9B192 /* RCTConvert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTConvert.h; sourceTree = "<group>"; }; 83CBBACA1A6023D300E9B192 /* RCTConvert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTConvert.h; sourceTree = "<group>"; };
83CBBACB1A6023D300E9B192 /* RCTConvert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTConvert.m; sourceTree = "<group>"; }; 83CBBACB1A6023D300E9B192 /* RCTConvert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTConvert.m; sourceTree = "<group>"; };
83F15A171B7CC46900F10295 /* UIView+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIView+Private.h"; sourceTree = "<group>"; };
E3BBC8EB1ADE6F47001BBD81 /* RCTTextDecorationLineType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTTextDecorationLineType.h; sourceTree = "<group>"; }; E3BBC8EB1ADE6F47001BBD81 /* RCTTextDecorationLineType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTTextDecorationLineType.h; sourceTree = "<group>"; };
E9B20B791B500126007A2DA7 /* RCTAccessibilityManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTAccessibilityManager.h; sourceTree = "<group>"; }; E9B20B791B500126007A2DA7 /* RCTAccessibilityManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTAccessibilityManager.h; sourceTree = "<group>"; };
E9B20B7A1B500126007A2DA7 /* RCTAccessibilityManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAccessibilityManager.m; sourceTree = "<group>"; }; E9B20B7A1B500126007A2DA7 /* RCTAccessibilityManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAccessibilityManager.m; sourceTree = "<group>"; };
@ -405,6 +406,7 @@
13C156041AB1A2840079392D /* RCTWebViewManager.m */, 13C156041AB1A2840079392D /* RCTWebViewManager.m */,
13B080231A694A8400A75B9A /* RCTWrapperViewController.h */, 13B080231A694A8400A75B9A /* RCTWrapperViewController.h */,
13B080241A694A8400A75B9A /* RCTWrapperViewController.m */, 13B080241A694A8400A75B9A /* RCTWrapperViewController.m */,
83F15A171B7CC46900F10295 /* UIView+Private.h */,
13E067531A70F44B002CDEE1 /* UIView+React.h */, 13E067531A70F44B002CDEE1 /* UIView+React.h */,
13E067541A70F44B002CDEE1 /* UIView+React.m */, 13E067541A70F44B002CDEE1 /* UIView+React.m */,
); );

View File

@ -16,6 +16,7 @@
#import "RCTLog.h" #import "RCTLog.h"
#import "RCTUIManager.h" #import "RCTUIManager.h"
#import "RCTUtils.h" #import "RCTUtils.h"
#import "UIView+Private.h"
#import "UIView+React.h" #import "UIView+React.h"
CGFloat const ZINDEX_DEFAULT = 0; CGFloat const ZINDEX_DEFAULT = 0;
@ -365,6 +366,7 @@ RCT_NOT_IMPLEMENTED(-init)
NSTimeInterval _lastScrollDispatchTime; NSTimeInterval _lastScrollDispatchTime;
NSMutableArray *_cachedChildFrames; NSMutableArray *_cachedChildFrames;
BOOL _allowNextScrollNoMatterWhat; BOOL _allowNextScrollNoMatterWhat;
CGRect _lastClippedToRect;
} }
@synthesize nativeMainScrollDelegate = _nativeMainScrollDelegate; @synthesize nativeMainScrollDelegate = _nativeMainScrollDelegate;
@ -374,7 +376,6 @@ RCT_NOT_IMPLEMENTED(-init)
RCTAssertParam(eventDispatcher); RCTAssertParam(eventDispatcher);
if ((self = [super initWithFrame:CGRectZero])) { if ((self = [super initWithFrame:CGRectZero])) {
_eventDispatcher = eventDispatcher; _eventDispatcher = eventDispatcher;
_scrollView = [[RCTCustomScrollView alloc] initWithFrame:CGRectZero]; _scrollView = [[RCTCustomScrollView alloc] initWithFrame:CGRectZero];
_scrollView.delegate = self; _scrollView.delegate = self;
@ -382,6 +383,7 @@ RCT_NOT_IMPLEMENTED(-init)
_automaticallyAdjustContentInsets = YES; _automaticallyAdjustContentInsets = YES;
_contentInset = UIEdgeInsetsZero; _contentInset = UIEdgeInsetsZero;
_contentSize = CGSizeZero; _contentSize = CGSizeZero;
_lastClippedToRect = CGRectNull;
_scrollEventThrottle = 0.0; _scrollEventThrottle = 0.0;
_lastScrollDispatchTime = CACurrentMediaTime(); _lastScrollDispatchTime = CACurrentMediaTime();
@ -469,6 +471,33 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
[self updateClippedSubviews]; [self updateClippedSubviews];
} }
- (void)updateClippedSubviews
{
// Find a suitable view to use for clipping
UIView *clipView = [self react_findClipView];
if (!clipView) {
return;
}
static const CGFloat leeway = 50.0;
const CGSize contentSize = _scrollView.contentSize;
const CGRect bounds = _scrollView.bounds;
const BOOL scrollsHorizontally = contentSize.width > bounds.size.width;
const BOOL scrollsVertically = contentSize.height > bounds.size.height;
const BOOL shouldClipAgain =
CGRectIsNull(_lastClippedToRect) ||
(scrollsHorizontally && (bounds.size.width < leeway || fabs(_lastClippedToRect.origin.x - bounds.origin.x) >= leeway)) ||
(scrollsVertically && (bounds.size.height < leeway || fabs(_lastClippedToRect.origin.y - bounds.origin.y) >= leeway));
if (shouldClipAgain) {
const CGRect clipRect = CGRectInset(clipView.bounds, -leeway, -leeway);
[self react_updateClippedSubviewsWithClipRect:clipRect relativeToView:clipView];
_lastClippedToRect = bounds;
}
}
- (void)setContentInset:(UIEdgeInsets)contentInset - (void)setContentInset:(UIEdgeInsets)contentInset
{ {
CGPoint contentOffset = _scrollView.contentOffset; CGPoint contentOffset = _scrollView.contentOffset;

View File

@ -0,0 +1,18 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <UIKit/UIKit.h>
@interface UIView (RCTViewUnmounting)
- (void)react_remountAllSubviews;
- (void)react_updateClippedSubviewsWithClipRect:(CGRect)clipRect relativeToView:(UIView *)clipView;
- (UIView *)react_findClipView;
@end