Permalink
Browse files

Better TextInput: Removed redundant UIScrollView from RCTTextView

Reviewed By: mmmulani

Differential Revision: D4640207

fbshipit-source-id: 01fc65b0212ad6baef500625679dab5e99da9db5
  • Loading branch information...
shergin authored and facebook-github-bot committed Mar 20, 2017
1 parent d272334 commit 3acafd1f3dd42cc27a592cdee0530e0dbf1c8afd
Showing with 33 additions and 32 deletions.
  1. +33 −32 Libraries/Text/RCTTextView.m
@@ -58,6 +58,13 @@ - (void)didMoveToWindow
}
}
- (void)setContentOffset:(CGPoint)contentOffset animated:(__unused BOOL)animated
{
// Turning off scroll animation.
// This fixes the problem also known as "flaky scrolling".
[super setContentOffset:contentOffset animated:NO];
}
@end
@implementation RCTTextView
@@ -69,7 +76,6 @@ @implementation RCTTextView
UITextView *_textView;
RCTText *_richTextView;
NSAttributedString *_pendingAttributedText;
UIScrollView *_scrollView;
UITextRange *_previousSelectionRange;
NSUInteger _previousTextLength;
@@ -100,27 +106,23 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
#if !TARGET_OS_TV
_textView.scrollsToTop = NO;
#endif
_textView.scrollEnabled = NO;
_textView.scrollEnabled = YES;
_textView.delegate = self;
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
#if !TARGET_OS_TV
_scrollView.scrollsToTop = NO;
#endif
_scrollView.delegate = self;
[_scrollView addSubview:_textView];
[self addSubview:_scrollView];
[self addSubview:_textView];
}
return self;
}
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
#pragma mark - RCTComponent
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index
{
[super insertReactSubview:subview atIndex:index];
if ([subview isKindOfClass:[RCTText class]]) {
if (_richTextView) {
RCTLogError(@"Tried to insert a second <Text> into <TextInput> - there can only be one.");
@@ -143,11 +145,6 @@ - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index
}
}
- (void)dealloc
{
_scrollView.delegate = nil;
}
- (void)removeReactSubview:(UIView *)subview
{
[super removeReactSubview:subview];
@@ -159,9 +156,11 @@ - (void)removeReactSubview:(UIView *)subview
- (void)didUpdateReactSubviews
{
// Do nothing, as we don't allow non-text subviews
// Do nothing, as we don't allow non-text subviews.
}
#pragma mark - Routine
- (void)setMostRecentEventCount:(NSInteger)mostRecentEventCount
{
_mostRecentEventCount = mostRecentEventCount;
@@ -262,7 +261,6 @@ - (void)updateFrames
CGRect frame = UIEdgeInsetsInsetRect(self.bounds, adjustedFrameInset);
_textView.frame = frame;
_placeholderView.frame = frame;
_scrollView.frame = frame;
[self updateContentSize];
_textView.textContainerInset = adjustedTextContainerInset;
@@ -271,10 +269,8 @@ - (void)updateFrames
- (void)updateContentSize
{
CGSize size = (CGSize){_scrollView.frame.size.width, INFINITY};
size.height = [_textView sizeThatFits:size].height;
_scrollView.contentSize = size;
_textView.frame = (CGRect){CGPointZero, size};
CGSize size = _textView.frame.size;
size.height = [_textView sizeThatFits:CGSizeMake(size.width, INFINITY)].height;
if (_viewDidCompleteInitialLayout && _onContentSizeChange && !CGSizeEqualToSize(_previousContentSize, size)) {
_previousContentSize = size;
@@ -725,26 +721,31 @@ - (UIColor *)defaultPlaceholderTextColor
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (_onScroll) {
CGPoint contentOffset = scrollView.contentOffset;
CGSize contentSize = scrollView.contentSize;
CGSize size = scrollView.bounds.size;
UIEdgeInsets contentInset = scrollView.contentInset;
_onScroll(@{
@"contentOffset": @{
@"x": @(scrollView.contentOffset.x),
@"y": @(scrollView.contentOffset.y)
@"x": @(contentOffset.x),
@"y": @(contentOffset.y)
},
@"contentInset": @{
@"top": @(_scrollView.contentInset.top),
@"left": @(_scrollView.contentInset.left),
@"bottom": @(_scrollView.contentInset.bottom),
@"right": @(_scrollView.contentInset.right)
@"top": @(contentInset.top),
@"left": @(contentInset.left),
@"bottom": @(contentInset.bottom),
@"right": @(contentInset.right)
},
@"contentSize": @{
@"width": @(_scrollView.contentSize.width),
@"height": @(_scrollView.contentSize.height)
@"width": @(contentSize.width),
@"height": @(contentSize.height)
},
@"layoutMeasurement": @{
@"width": @(_scrollView.frame.size.width),
@"height": @(_scrollView.frame.size.height)
@"width": @(size.width),
@"height": @(size.height)
},
@"zoomScale": @(_scrollView.zoomScale ?: 1),
@"zoomScale": @(scrollView.zoomScale ?: 1),
});
}
}

0 comments on commit 3acafd1

Please sign in to comment.