Merge pull request #1437 from ejensen/editable-text-node-layout-manager

[ASEditableTextNode] Allow TextKit component customization
This commit is contained in:
appleguy
2016-03-31 20:46:19 -07:00
10 changed files with 85 additions and 37 deletions

View File

@@ -6,11 +6,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <objc/message.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "ASBaseDefines.h"
#import <AsyncDisplayKit/ASBaseDefines.h>
NS_ASSUME_NONNULL_BEGIN
@@ -37,8 +34,20 @@ ASDISPLAYNODE_INLINE CGSize ceilSizeValue(CGSize s)
@return An `ASTextKitComponents` containing the created components. The text view component will be nil.
@discussion The returned components will be hooked up together, so they are ready for use as a system upon return.
*/
+ (ASTextKitComponents *)componentsWithAttributedSeedString:(nullable NSAttributedString *)attributedSeedString
textContainerSize:(CGSize)textContainerSize;
+ (instancetype)componentsWithAttributedSeedString:(nullable NSAttributedString *)attributedSeedString
textContainerSize:(CGSize)textContainerSize;
/**
@abstract Creates the stack of TextKit components.
@param textStorage The NSTextStorage to use.
@param textContainerSize The size of the text-container. Typically, size specifies the constraining width of the layout, and FLT_MAX for height. Pass CGSizeZero if these components will be hooked up to a UITextView, which will manage the text container's size itself.
@param layoutManager The NSLayoutManager to use.
@return An `ASTextKitComponents` containing the created components. The text view component will be nil.
@discussion The returned components will be hooked up together, so they are ready for use as a system upon return.
*/
+ (instancetype)componentsWithTextStorage:(NSTextStorage *)textStorage
textContainerSize:(CGSize)textContainerSize
layoutManager:(NSLayoutManager *)layoutManager;
/**
@abstract Returns the bounding size for the text view's text.

View File

@@ -6,7 +6,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "ASTextKitHelpers.h"
#import "ASTextKitComponents.h"
@interface ASTextKitComponents ()
@@ -19,15 +19,25 @@
@implementation ASTextKitComponents
+ (ASTextKitComponents *)componentsWithAttributedSeedString:(NSAttributedString *)attributedSeedString
textContainerSize:(CGSize)textContainerSize
+ (instancetype)componentsWithAttributedSeedString:(NSAttributedString *)attributedSeedString
textContainerSize:(CGSize)textContainerSize
{
ASTextKitComponents *components = [[ASTextKitComponents alloc] init];
NSTextStorage *textStorage = attributedSeedString ? [[NSTextStorage alloc] initWithAttributedString:attributedSeedString] : [[NSTextStorage alloc] init];
// Create the TextKit component stack with our default configuration.
components.textStorage = (attributedSeedString ? [[NSTextStorage alloc] initWithAttributedString:attributedSeedString] : [[NSTextStorage alloc] init]);
return [self componentsWithTextStorage:textStorage
textContainerSize:textContainerSize
layoutManager:[[NSLayoutManager alloc] init]];
}
components.layoutManager = [[NSLayoutManager alloc] init];
+ (instancetype)componentsWithTextStorage:(NSTextStorage *)textStorage
textContainerSize:(CGSize)textContainerSize
layoutManager:(NSLayoutManager *)layoutManager
{
ASTextKitComponents *components = [[self alloc] init];
components.textStorage = textStorage;
components.layoutManager = layoutManager;
[components.textStorage addLayoutManager:components.layoutManager];
components.textContainer = [[NSTextContainer alloc] initWithSize:textContainerSize];