Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AsyncDisplayKit/ASEditableTextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ NS_ASSUME_NONNULL_BEGIN

#pragma mark - Configuration

/**
@abstract Enable scrolling on the textView
*/
@property (nonatomic) BOOL scrollEnabled;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify the @default value for this


/**
@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.
Expand Down
34 changes: 28 additions & 6 deletions AsyncDisplayKit/ASEditableTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break out the abstract into a few lines. Pretty good as-written! I would add a clarification / maybe replace some of your words with:

"As originally reported in rdar://14729288, when scrollEnabled = NO, UITextView does not calculate its contentSize. This makes it difficult for a client to embed a UITextView inside a different scroll view with other content (setting scrollEnabled = NO on the UITextView itself, because the containing scroll view will handle the gesture)...because accessing contentSize is typically necessary to perform layout. Apple later closed the issue as expected behavior. This works around the issue by ensuring that contentSize is always calculated, while still providing control over the UITextView's scrolling."

@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.
Expand Down Expand Up @@ -207,11 +222,18 @@ - (void)setLayerBacked:(BOOL)layerBacked
#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;
}
Expand Down