@@ -58,6 +58,13 @@ - (void)didMoveToWindow
58
58
}
59
59
}
60
60
61
+ - (void )setContentOffset : (CGPoint )contentOffset animated : (__unused BOOL )animated
62
+ {
63
+ // Turning off scroll animation.
64
+ // This fixes the problem also known as "flaky scrolling".
65
+ [super setContentOffset: contentOffset animated: NO ];
66
+ }
67
+
61
68
@end
62
69
63
70
@implementation RCTTextView
@@ -69,7 +76,6 @@ @implementation RCTTextView
69
76
UITextView *_textView;
70
77
RCTText *_richTextView;
71
78
NSAttributedString *_pendingAttributedText;
72
- UIScrollView *_scrollView;
73
79
74
80
UITextRange *_previousSelectionRange;
75
81
NSUInteger _previousTextLength;
@@ -100,27 +106,23 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
100
106
#if !TARGET_OS_TV
101
107
_textView.scrollsToTop = NO ;
102
108
#endif
103
- _textView.scrollEnabled = NO ;
109
+ _textView.scrollEnabled = YES ;
104
110
_textView.delegate = self;
105
111
106
- _scrollView = [[UIScrollView alloc ] initWithFrame: CGRectZero ];
107
- #if !TARGET_OS_TV
108
- _scrollView.scrollsToTop = NO ;
109
- #endif
110
- _scrollView.delegate = self;
111
- [_scrollView addSubview: _textView];
112
-
113
- [self addSubview: _scrollView];
112
+ [self addSubview: _textView];
114
113
}
115
114
return self;
116
115
}
117
116
118
117
RCT_NOT_IMPLEMENTED (- (instancetype )initWithFrame:(CGRect )frame)
119
118
RCT_NOT_IMPLEMENTED(- (instancetype )initWithCoder:(NSCoder *)aDecoder)
120
119
120
+ #pragma mark - RCTComponent
121
+
121
122
- (void )insertReactSubview : (UIView *)subview atIndex : (NSInteger )index
122
123
{
123
124
[super insertReactSubview: subview atIndex: index ];
125
+
124
126
if ([subview isKindOfClass: [RCTText class ]]) {
125
127
if (_richTextView) {
126
128
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
143
145
}
144
146
}
145
147
146
- - (void )dealloc
147
- {
148
- _scrollView.delegate = nil ;
149
- }
150
-
151
148
- (void )removeReactSubview : (UIView *)subview
152
149
{
153
150
[super removeReactSubview: subview];
@@ -159,9 +156,11 @@ - (void)removeReactSubview:(UIView *)subview
159
156
160
157
- (void )didUpdateReactSubviews
161
158
{
162
- // Do nothing, as we don't allow non-text subviews
159
+ // Do nothing, as we don't allow non-text subviews.
163
160
}
164
161
162
+ #pragma mark - Routine
163
+
165
164
- (void )setMostRecentEventCount : (NSInteger )mostRecentEventCount
166
165
{
167
166
_mostRecentEventCount = mostRecentEventCount;
@@ -262,7 +261,6 @@ - (void)updateFrames
262
261
CGRect frame = UIEdgeInsetsInsetRect (self.bounds , adjustedFrameInset);
263
262
_textView.frame = frame;
264
263
_placeholderView.frame = frame;
265
- _scrollView.frame = frame;
266
264
[self updateContentSize ];
267
265
268
266
_textView.textContainerInset = adjustedTextContainerInset;
@@ -271,10 +269,8 @@ - (void)updateFrames
271
269
272
270
- (void )updateContentSize
273
271
{
274
- CGSize size = (CGSize ){_scrollView.frame .size .width , INFINITY};
275
- size.height = [_textView sizeThatFits: size].height ;
276
- _scrollView.contentSize = size;
277
- _textView.frame = (CGRect ){CGPointZero , size};
272
+ CGSize size = _textView.frame .size ;
273
+ size.height = [_textView sizeThatFits: CGSizeMake (size.width, INFINITY)].height ;
278
274
279
275
if (_viewDidCompleteInitialLayout && _onContentSizeChange && !CGSizeEqualToSize (_previousContentSize, size)) {
280
276
_previousContentSize = size;
@@ -725,26 +721,31 @@ - (UIColor *)defaultPlaceholderTextColor
725
721
- (void )scrollViewDidScroll : (UIScrollView *)scrollView
726
722
{
727
723
if (_onScroll) {
724
+ CGPoint contentOffset = scrollView.contentOffset ;
725
+ CGSize contentSize = scrollView.contentSize ;
726
+ CGSize size = scrollView.bounds .size ;
727
+ UIEdgeInsets contentInset = scrollView.contentInset ;
728
+
728
729
_onScroll (@{
729
730
@" contentOffset" : @{
730
- @" x" : @(scrollView. contentOffset .x ),
731
- @" y" : @(scrollView. contentOffset .y )
731
+ @" x" : @(contentOffset.x ),
732
+ @" y" : @(contentOffset.y )
732
733
},
733
734
@" contentInset" : @{
734
- @" top" : @(_scrollView. contentInset .top ),
735
- @" left" : @(_scrollView. contentInset .left ),
736
- @" bottom" : @(_scrollView. contentInset .bottom ),
737
- @" right" : @(_scrollView. contentInset .right )
735
+ @" top" : @(contentInset.top ),
736
+ @" left" : @(contentInset.left ),
737
+ @" bottom" : @(contentInset.bottom ),
738
+ @" right" : @(contentInset.right )
738
739
},
739
740
@" contentSize" : @{
740
- @" width" : @(_scrollView. contentSize .width ),
741
- @" height" : @(_scrollView. contentSize .height )
741
+ @" width" : @(contentSize.width ),
742
+ @" height" : @(contentSize.height )
742
743
},
743
744
@" layoutMeasurement" : @{
744
- @" width" : @(_scrollView. frame . size .width ),
745
- @" height" : @(_scrollView. frame . size .height )
745
+ @" width" : @(size.width ),
746
+ @" height" : @(size.height )
746
747
},
747
- @" zoomScale" : @(_scrollView .zoomScale ?: 1 ),
748
+ @" zoomScale" : @(scrollView .zoomScale ?: 1 ),
748
749
});
749
750
}
750
751
}
0 commit comments