From e4d25513846e640d5e86ee291d4c1b96d7d7e209 Mon Sep 17 00:00:00 2001 From: Samuel Hsiung Date: Thu, 29 Oct 2015 16:03:06 -0700 Subject: [PATCH] Make textContainerInset configurable for ASEditableTextNode placeholder and typed textViews Previously, it was only possible to configure the textContainerInset of the typed textView by accessing the textView property on didLoad. This would cause the placeholder and typed textViews to become desynced however, so in this commit we add the ability to configure both. --- AsyncDisplayKit/ASEditableTextNode.h | 5 +++++ AsyncDisplayKit/ASEditableTextNode.mm | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/AsyncDisplayKit/ASEditableTextNode.h b/AsyncDisplayKit/ASEditableTextNode.h index 0581cfe638..ee20ce808a 100644 --- a/AsyncDisplayKit/ASEditableTextNode.h +++ b/AsyncDisplayKit/ASEditableTextNode.h @@ -59,6 +59,11 @@ //! @abstract The text input mode used by the receiver's keyboard, if it is visible. This value is undefined if the receiver is not the first responder. @property (nonatomic, readonly) UITextInputMode *textInputMode; +/* + @abstract The textContainerInset of both the placeholder and typed textView. This value defaults to UIEdgeInsetsZero. + */ +@property (nonatomic, readwrite) UIEdgeInsets textContainerInset; + /* @abstract The returnKeyType of the keyboard. This value defaults to UIReturnKeyDefault. */ diff --git a/AsyncDisplayKit/ASEditableTextNode.mm b/AsyncDisplayKit/ASEditableTextNode.mm index 5b929ccfb3..b0beb67385 100644 --- a/AsyncDisplayKit/ASEditableTextNode.mm +++ b/AsyncDisplayKit/ASEditableTextNode.mm @@ -78,7 +78,8 @@ _textKitComponents.layoutManager.delegate = self; _wordKerner = [[ASTextNodeWordKerner alloc] init]; _returnKeyType = UIReturnKeyDefault; - + _textContainerInset = UIEdgeInsetsZero; + // Create the placeholder scaffolding. _placeholderTextKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero]; _placeholderTextKitComponents.layoutManager.delegate = self; @@ -122,7 +123,7 @@ textView.backgroundColor = nil; textView.opaque = NO; } - textView.textContainerInset = UIEdgeInsetsZero; + textView.textContainerInset = self.textContainerInset; textView.clipsToBounds = NO; // We don't want selection handles cut off. }; @@ -175,6 +176,15 @@ _placeholderTextKitComponents.textView.backgroundColor = backgroundColor; } +- (void)setTextContainerInset:(UIEdgeInsets)textContainerInset +{ + ASDN::MutexLocker l(_textKitLock); + + _textContainerInset = textContainerInset; + _textKitComponents.textView.textContainerInset = textContainerInset; + _placeholderTextKitComponents.textView.textContainerInset = textContainerInset; +} + - (void)setOpaque:(BOOL)opaque { [super setOpaque:opaque];