Add an ASEditableTextNode initializer that allows customization of its ASTextKitComponents

This commit is contained in:
Eric Jensen 2016-03-25 22:23:03 -07:00
parent f8f3585764
commit 0d52176e03
3 changed files with 22 additions and 4 deletions

View File

@ -7,6 +7,7 @@
*/
#import <AsyncDisplayKit/ASDisplayNode.h>
#import <AsyncDisplayKit/ASTextKitHelpers.h>
NS_ASSUME_NONNULL_BEGIN
@ -18,6 +19,17 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface ASEditableTextNode : ASDisplayNode
/**
* @abstract Initializes a editable text node with a provided TextKit stack.
*
* @param textKitComponents The TextKit stack used to render text.
* @param placeholderTextKitComponents The TextKit stack used to render placeholder text.
*
* @returns An initialized ASEditableTextNode.
*/
- (instancetype)initWithTextKitComponents:(ASTextKitComponents *)textKitComponents
placeholderTextKitComponents:(ASTextKitComponents *)placeholderTextKitComponents;
//! @abstract The text node's delegate, which must conform to the <ASEditableTextNodeDelegate> protocol.
@property (nonatomic, readwrite, weak) id <ASEditableTextNodeDelegate> delegate;

View File

@ -12,7 +12,6 @@
#import "ASDisplayNode+Subclasses.h"
#import "ASEqualityHelpers.h"
#import "ASTextKitHelpers.h"
#import "ASTextNodeWordKerner.h"
#import "ASThread.h"
@ -93,6 +92,13 @@
#pragma mark - NSObject Overrides
- (instancetype)init
{
return [self initWithTextKitComponents:[ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero]
placeholderTextKitComponents:[ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero]];
}
- (instancetype)initWithTextKitComponents:(ASTextKitComponents *)textKitComponents
placeholderTextKitComponents:(ASTextKitComponents *)placeholderTextKitComponents
{
if (!(self = [super init]))
return nil;
@ -101,14 +107,14 @@
_scrollEnabled = YES;
// Create the scaffolding for the text view.
_textKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero];
_textKitComponents = textKitComponents;
_textKitComponents.layoutManager.delegate = self;
_wordKerner = [[ASTextNodeWordKerner alloc] init];
_returnKeyType = UIReturnKeyDefault;
_textContainerInset = UIEdgeInsetsZero;
// Create the placeholder scaffolding.
_placeholderTextKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero];
_placeholderTextKitComponents = placeholderTextKitComponents;
_placeholderTextKitComponents.layoutManager.delegate = self;
return self;

View File

@ -15,7 +15,6 @@
#import <AsyncDisplayKit/ASButtonNode.h>
#import <AsyncDisplayKit/ASMapNode.h>
#import <AsyncDisplayKit/ASVideoNode.h>
#import <AsyncDisplayKit/ASEditableTextNode.h>
#import <AsyncDisplayKit/ASBasicImageDownloader.h>
@ -77,5 +76,6 @@
#import <AsyncDisplayKit/UICollectionViewLayout+ASConvenience.h>
#import <AsyncDisplayKit/UIView+ASConvenience.h>
#import <AsyncDisplayKit/ASRunLoopQueue.h>
#import <AsyncDisplayKit/ASTextKitHelpers.h>
#import <AsyncDisplayKit/AsyncDisplayKit+Debug.h>