Skip to content

Commit e4d2551

Browse files
committed
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.
1 parent e11007f commit e4d2551

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

AsyncDisplayKit/ASEditableTextNode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
//! @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.
6060
@property (nonatomic, readonly) UITextInputMode *textInputMode;
6161

62+
/*
63+
@abstract The textContainerInset of both the placeholder and typed textView. This value defaults to UIEdgeInsetsZero.
64+
*/
65+
@property (nonatomic, readwrite) UIEdgeInsets textContainerInset;
66+
6267
/*
6368
@abstract The returnKeyType of the keyboard. This value defaults to UIReturnKeyDefault.
6469
*/

AsyncDisplayKit/ASEditableTextNode.mm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ - (instancetype)init
7878
_textKitComponents.layoutManager.delegate = self;
7979
_wordKerner = [[ASTextNodeWordKerner alloc] init];
8080
_returnKeyType = UIReturnKeyDefault;
81-
81+
_textContainerInset = UIEdgeInsetsZero;
82+
8283
// Create the placeholder scaffolding.
8384
_placeholderTextKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero];
8485
_placeholderTextKitComponents.layoutManager.delegate = self;
@@ -122,7 +123,7 @@ - (void)didLoad
122123
textView.backgroundColor = nil;
123124
textView.opaque = NO;
124125
}
125-
textView.textContainerInset = UIEdgeInsetsZero;
126+
textView.textContainerInset = self.textContainerInset;
126127
textView.clipsToBounds = NO; // We don't want selection handles cut off.
127128
};
128129

@@ -175,6 +176,15 @@ - (void)setBackgroundColor:(UIColor *)backgroundColor
175176
_placeholderTextKitComponents.textView.backgroundColor = backgroundColor;
176177
}
177178

179+
- (void)setTextContainerInset:(UIEdgeInsets)textContainerInset
180+
{
181+
ASDN::MutexLocker l(_textKitLock);
182+
183+
_textContainerInset = textContainerInset;
184+
_textKitComponents.textView.textContainerInset = textContainerInset;
185+
_placeholderTextKitComponents.textView.textContainerInset = textContainerInset;
186+
}
187+
178188
- (void)setOpaque:(BOOL)opaque
179189
{
180190
[super setOpaque:opaque];

0 commit comments

Comments
 (0)