Allow ASEditableTextNode to scroll

This commit is contained in:
Luke Zhao 2016-01-14 17:53:08 -08:00
parent df10f8f19a
commit 995f437e12
2 changed files with 33 additions and 6 deletions

View File

@ -23,6 +23,11 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Configuration
/**
@abstract Enable scrolling on the textView
*/
@property (nonatomic) BOOL scrollEnabled;
/**
@abstract Access to underlying UITextView for more configuration options.
@warning This property should only be used on the main thread and should not be accessed before the editable text node's view is created.

View File

@ -16,16 +16,31 @@
#import "ASTextNodeWordKerner.h"
#import "ASThread.h"
//! @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.
@interface _ASDisabledPanUITextView : UITextView
//! @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.
//! See issue: https://github.com/facebook/AsyncDisplayKit/issues/1063
@interface ASPanningOverriddenUITextView : UITextView
{
BOOL _shouldBlockPanGesture;
}
@end
@implementation _ASDisabledPanUITextView
@implementation ASPanningOverriddenUITextView
- (BOOL)scrollEnabled
{
return _shouldBlockPanGesture;
}
- (void)setScrollEnabled:(BOOL)scrollEnabled
{
_shouldBlockPanGesture = !scrollEnabled;
[super setScrollEnabled:YES];
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
// Never allow our pans to begin.
if (gestureRecognizer == self.panGestureRecognizer)
// Never allow our pans to begin when _shouldBlockPanGesture is true.
if (_shouldBlockPanGesture && gestureRecognizer == self.panGestureRecognizer)
return NO;
// Otherwise, proceed as usual.
@ -207,11 +222,18 @@
#pragma mark - Configuration
@synthesize delegate = _delegate;
- (void)setScrollEnabled:(BOOL)scrollEnabled
{
ASDN::MutexLocker l(_textKitLock);
_scrollEnabled = scrollEnabled;
[_textKitComponents.textView setScrollEnabled:_scrollEnabled];
}
- (UITextView *)textView
{
ASDisplayNodeAssertMainThread();
if (!_textKitComponents.textView) {
_textKitComponents.textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer];
_textKitComponents.textView = [[ASPanningOverriddenUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer];
}
return _textKitComponents.textView;
}