From 95016021b47ec5a0fc18ebad77a0621bcfabe586 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Thu, 9 Jul 2015 16:09:20 +0200 Subject: [PATCH 1/6] Access to underlying UITextView for more configuration options. --- AsyncDisplayKit/ASEditableTextNode.h | 3 +++ AsyncDisplayKit/ASEditableTextNode.mm | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/AsyncDisplayKit/ASEditableTextNode.h b/AsyncDisplayKit/ASEditableTextNode.h index 92811e2457..903fbbee43 100644 --- a/AsyncDisplayKit/ASEditableTextNode.h +++ b/AsyncDisplayKit/ASEditableTextNode.h @@ -19,6 +19,9 @@ #pragma mark - Configuration +//! @abstract Access to underlying UITextView for more configuration options. +@property (nonatomic, readwrite, strong) UITextView *textView; + //! @abstract The attributes to apply to new text being entered by the user. @property (nonatomic, readwrite, strong) NSDictionary *typingAttributes; diff --git a/AsyncDisplayKit/ASEditableTextNode.mm b/AsyncDisplayKit/ASEditableTextNode.mm index 3761134481..84e3cc1572 100644 --- a/AsyncDisplayKit/ASEditableTextNode.mm +++ b/AsyncDisplayKit/ASEditableTextNode.mm @@ -77,6 +77,7 @@ _textKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero]; _textKitComponents.layoutManager.delegate = self; _wordKerner = [[ASTextNodeWordKerner alloc] init]; + _textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer]; // Create the placeholder scaffolding. _placeholderTextKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero]; @@ -133,7 +134,7 @@ [self.view addSubview:_placeholderTextKitComponents.textView]; // Create and configure our text view. - _textKitComponents.textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer]; + _textKitComponents.textView = _textView; //_textKitComponents.textView = NO; // Unfortunately there's a bug here with iOS 7 DP5 that causes the text-view to only be one line high when scrollEnabled is NO. rdar://14729288 _textKitComponents.textView.delegate = self; _textKitComponents.textView.editable = YES; From fd3eb94fcb690cb03191e7a57290fd83e7e56354 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Sun, 12 Jul 2015 21:35:42 +0200 Subject: [PATCH 2/6] Add main thread warnings and setter/getter assert --- AsyncDisplayKit/ASEditableTextNode.h | 5 ++++- AsyncDisplayKit/ASEditableTextNode.mm | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/AsyncDisplayKit/ASEditableTextNode.h b/AsyncDisplayKit/ASEditableTextNode.h index 903fbbee43..c2b2060cdf 100644 --- a/AsyncDisplayKit/ASEditableTextNode.h +++ b/AsyncDisplayKit/ASEditableTextNode.h @@ -19,7 +19,10 @@ #pragma mark - Configuration -//! @abstract Access to underlying UITextView for more configuration options. +/** + @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. + */ @property (nonatomic, readwrite, strong) UITextView *textView; //! @abstract The attributes to apply to new text being entered by the user. diff --git a/AsyncDisplayKit/ASEditableTextNode.mm b/AsyncDisplayKit/ASEditableTextNode.mm index 84e3cc1572..d4abfb6942 100644 --- a/AsyncDisplayKit/ASEditableTextNode.mm +++ b/AsyncDisplayKit/ASEditableTextNode.mm @@ -41,6 +41,7 @@ { @private // Configuration. + UITextView *_textView; NSDictionary *_typingAttributes; // Core. @@ -134,7 +135,7 @@ [self.view addSubview:_placeholderTextKitComponents.textView]; // Create and configure our text view. - _textKitComponents.textView = _textView; + _textKitComponents.textView = _textView; //_textKitComponents.textView = NO; // Unfortunately there's a bug here with iOS 7 DP5 that causes the text-view to only be one line high when scrollEnabled is NO. rdar://14729288 _textKitComponents.textView.delegate = self; _textKitComponents.textView.editable = YES; @@ -189,6 +190,21 @@ #pragma mark - Configuration @synthesize delegate = _delegate; +#pragma mark - +@dynamic textView; + +- (UITextView *)textView{ + ASDisplayNodeAssertMainThread(); + return _textView; +} + +- (void)setTextView:(UITextView *)textView +{ + ASDisplayNodeAssertMainThread(); + _textView = textView; +} + + #pragma mark - @dynamic typingAttributes; From 36b92205ed95a6f88a3c5765950c3330ef7e3ef3 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Sat, 18 Jul 2015 16:10:32 +0200 Subject: [PATCH 3/6] Brace style --- AsyncDisplayKit/ASEditableTextNode.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AsyncDisplayKit/ASEditableTextNode.mm b/AsyncDisplayKit/ASEditableTextNode.mm index d4abfb6942..3339064e89 100644 --- a/AsyncDisplayKit/ASEditableTextNode.mm +++ b/AsyncDisplayKit/ASEditableTextNode.mm @@ -193,7 +193,8 @@ #pragma mark - @dynamic textView; -- (UITextView *)textView{ +- (UITextView *)textView +{ ASDisplayNodeAssertMainThread(); return _textView; } From 6b970e0e4ab3b225fa3475c3affd0af8b287f5f0 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Sat, 18 Jul 2015 16:29:25 +0200 Subject: [PATCH 4/6] Display node assert --- AsyncDisplayKit/ASEditableTextNode.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/AsyncDisplayKit/ASEditableTextNode.mm b/AsyncDisplayKit/ASEditableTextNode.mm index 3339064e89..ec9350781f 100644 --- a/AsyncDisplayKit/ASEditableTextNode.mm +++ b/AsyncDisplayKit/ASEditableTextNode.mm @@ -196,6 +196,7 @@ - (UITextView *)textView { ASDisplayNodeAssertMainThread(); + ASDisplayNodeAssert(_textView != nil, @"ASEditableTextNode's text view has not been allocated yet — access it in -didLoad or after accessing the .view property instead"); return _textView; } From 3c71289927c1ffad72ebaac48ae8122086c1ca63 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Sat, 18 Jul 2015 16:31:13 +0200 Subject: [PATCH 5/6] lazy creation of textview in accessor after assert --- AsyncDisplayKit/ASEditableTextNode.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AsyncDisplayKit/ASEditableTextNode.mm b/AsyncDisplayKit/ASEditableTextNode.mm index ec9350781f..bc1687afdf 100644 --- a/AsyncDisplayKit/ASEditableTextNode.mm +++ b/AsyncDisplayKit/ASEditableTextNode.mm @@ -196,7 +196,9 @@ - (UITextView *)textView { ASDisplayNodeAssertMainThread(); - ASDisplayNodeAssert(_textView != nil, @"ASEditableTextNode's text view has not been allocated yet — access it in -didLoad or after accessing the .view property instead"); + if (!_textView) { + _textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer]; + } return _textView; } From 6b380009414a50f95569aad1dd1df514d03a39a8 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Wed, 22 Jul 2015 11:05:27 +0200 Subject: [PATCH 6/6] A simpler, cleaner implementation --- AsyncDisplayKit/ASEditableTextNode.h | 2 +- AsyncDisplayKit/ASEditableTextNode.mm | 20 ++++---------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/AsyncDisplayKit/ASEditableTextNode.h b/AsyncDisplayKit/ASEditableTextNode.h index c2b2060cdf..05c2bea790 100644 --- a/AsyncDisplayKit/ASEditableTextNode.h +++ b/AsyncDisplayKit/ASEditableTextNode.h @@ -23,7 +23,7 @@ @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. */ -@property (nonatomic, readwrite, strong) UITextView *textView; +@property (nonatomic, readonly, strong) UITextView *textView; //! @abstract The attributes to apply to new text being entered by the user. @property (nonatomic, readwrite, strong) NSDictionary *typingAttributes; diff --git a/AsyncDisplayKit/ASEditableTextNode.mm b/AsyncDisplayKit/ASEditableTextNode.mm index bc1687afdf..31b63fba91 100644 --- a/AsyncDisplayKit/ASEditableTextNode.mm +++ b/AsyncDisplayKit/ASEditableTextNode.mm @@ -41,7 +41,6 @@ { @private // Configuration. - UITextView *_textView; NSDictionary *_typingAttributes; // Core. @@ -78,7 +77,6 @@ _textKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero]; _textKitComponents.layoutManager.delegate = self; _wordKerner = [[ASTextNodeWordKerner alloc] init]; - _textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer]; // Create the placeholder scaffolding. _placeholderTextKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero]; @@ -135,7 +133,7 @@ [self.view addSubview:_placeholderTextKitComponents.textView]; // Create and configure our text view. - _textKitComponents.textView = _textView; + _textKitComponents.textView = self.textView; //_textKitComponents.textView = NO; // Unfortunately there's a bug here with iOS 7 DP5 that causes the text-view to only be one line high when scrollEnabled is NO. rdar://14729288 _textKitComponents.textView.delegate = self; _textKitComponents.textView.editable = YES; @@ -190,25 +188,15 @@ #pragma mark - Configuration @synthesize delegate = _delegate; -#pragma mark - -@dynamic textView; - - (UITextView *)textView { ASDisplayNodeAssertMainThread(); - if (!_textView) { - _textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer]; + if (!_textKitComponents.textView) { + _textKitComponents.textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer]; } - return _textView; + return _textKitComponents.textView; } -- (void)setTextView:(UITextView *)textView -{ - ASDisplayNodeAssertMainThread(); - _textView = textView; -} - - #pragma mark - @dynamic typingAttributes;