|
16 | 16 | #import "ASTextNodeWordKerner.h" |
17 | 17 | #import "ASThread.h" |
18 | 18 |
|
19 | | -//! @abstract This subclass exists solely to ensure the text view's panGestureRecognizer never begins, because it's sporadically enabled by UITextView. It will be removed pending rdar://14729288. |
20 | | -@interface _ASDisabledPanUITextView : UITextView |
| 19 | +//! @abstract This subclass forces the parent UITextView's scrollEnabled property to always be true. Instead, it disables the panGestureRecognizer when scrollEnabled is set to false. This ensures that the contentSize is caculated correctly. |
| 20 | +//! See issue: https://github.com/facebook/AsyncDisplayKit/issues/1063 |
| 21 | +@interface ASPanningOverriddenUITextView : UITextView |
| 22 | +{ |
| 23 | + BOOL _shouldBlockPanGesture; |
| 24 | +} |
21 | 25 | @end |
22 | 26 |
|
23 | | -@implementation _ASDisabledPanUITextView |
| 27 | +@implementation ASPanningOverriddenUITextView |
| 28 | + |
| 29 | +- (BOOL)scrollEnabled |
| 30 | +{ |
| 31 | + return _shouldBlockPanGesture; |
| 32 | +} |
| 33 | + |
| 34 | +- (void)setScrollEnabled:(BOOL)scrollEnabled |
| 35 | +{ |
| 36 | + _shouldBlockPanGesture = !scrollEnabled; |
| 37 | + [super setScrollEnabled:YES]; |
| 38 | +} |
24 | 39 |
|
25 | 40 | - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer |
26 | 41 | { |
27 | | - // Never allow our pans to begin. |
28 | | - if (gestureRecognizer == self.panGestureRecognizer) |
| 42 | + // Never allow our pans to begin when _shouldBlockPanGesture is true. |
| 43 | + if (_shouldBlockPanGesture && gestureRecognizer == self.panGestureRecognizer) |
29 | 44 | return NO; |
30 | 45 |
|
31 | 46 | // Otherwise, proceed as usual. |
@@ -207,11 +222,18 @@ - (void)setLayerBacked:(BOOL)layerBacked |
207 | 222 | #pragma mark - Configuration |
208 | 223 | @synthesize delegate = _delegate; |
209 | 224 |
|
| 225 | +- (void)setScrollEnabled:(BOOL)scrollEnabled |
| 226 | +{ |
| 227 | + ASDN::MutexLocker l(_textKitLock); |
| 228 | + _scrollEnabled = scrollEnabled; |
| 229 | + [_textKitComponents.textView setScrollEnabled:_scrollEnabled]; |
| 230 | +} |
| 231 | + |
210 | 232 | - (UITextView *)textView |
211 | 233 | { |
212 | 234 | ASDisplayNodeAssertMainThread(); |
213 | 235 | if (!_textKitComponents.textView) { |
214 | | - _textKitComponents.textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer]; |
| 236 | + _textKitComponents.textView = [[ASPanningOverriddenUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer]; |
215 | 237 | } |
216 | 238 | return _textKitComponents.textView; |
217 | 239 | } |
|
0 commit comments