Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 3aceabb

Browse files
committed
Merge pull request #1069 from lkzhao/master
[ASEditableTextNode] Support scrolling while maintaining workaround for Apple bug when disabling it.
2 parents 44aae77 + 995f437 commit 3aceabb

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

AsyncDisplayKit/ASEditableTextNode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ NS_ASSUME_NONNULL_BEGIN
2323

2424
#pragma mark - Configuration
2525

26+
/**
27+
@abstract Enable scrolling on the textView
28+
*/
29+
@property (nonatomic) BOOL scrollEnabled;
30+
2631
/**
2732
@abstract Access to underlying UITextView for more configuration options.
2833
@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.

AsyncDisplayKit/ASEditableTextNode.mm

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,31 @@
1616
#import "ASTextNodeWordKerner.h"
1717
#import "ASThread.h"
1818

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+
}
2125
@end
2226

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+
}
2439

2540
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
2641
{
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)
2944
return NO;
3045

3146
// Otherwise, proceed as usual.
@@ -207,11 +222,18 @@ - (void)setLayerBacked:(BOOL)layerBacked
207222
#pragma mark - Configuration
208223
@synthesize delegate = _delegate;
209224

225+
- (void)setScrollEnabled:(BOOL)scrollEnabled
226+
{
227+
ASDN::MutexLocker l(_textKitLock);
228+
_scrollEnabled = scrollEnabled;
229+
[_textKitComponents.textView setScrollEnabled:_scrollEnabled];
230+
}
231+
210232
- (UITextView *)textView
211233
{
212234
ASDisplayNodeAssertMainThread();
213235
if (!_textKitComponents.textView) {
214-
_textKitComponents.textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer];
236+
_textKitComponents.textView = [[ASPanningOverriddenUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer];
215237
}
216238
return _textKitComponents.textView;
217239
}

0 commit comments

Comments
 (0)