Remove textStorageCreationBlock API (#2142)

* Remove textStorageCreationBlock API

* Remove layoutManagerCreationBlock also
This commit is contained in:
Adlai Holler
2016-08-26 11:42:20 -07:00
committed by GitHub
parent 6a482dc153
commit 9c3b688a87
10 changed files with 13 additions and 65 deletions

View File

@@ -20,17 +20,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nullable, nonatomic, copy) NSArray *pointSizeScaleFactors;
#pragma mark - ASTextKit Customization
/**
A block to provide a hook to provide a custom NSLayoutManager to the ASTextKitRenderer
*/
@property (nullable, nonatomic, copy) NSLayoutManager * (^layoutManagerCreationBlock)(void);
/**
A block to provide a hook to provide a NSTextStorage to the TextKit's layout manager.
*/
@property (nullable, nonatomic, copy) NSTextStorage * (^textStorageCreationBlock)(NSAttributedString *_Nullable attributedString);
/**
@abstract Text margins for text laid out in the text node.
@discussion defaults to UIEdgeInsetsZero.

View File

@@ -244,8 +244,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
.exclusionPaths = _exclusionPaths,
// use the property getter so a subclass can provide these scale factors on demand if desired
.pointSizeScaleFactors = self.pointSizeScaleFactors,
.layoutManagerCreationBlock = self.layoutManagerCreationBlock,
.textStorageCreationBlock = self.textStorageCreationBlock,
.shadowOffset = _shadowOffset,
.shadowColor = _cachedShadowUIColor,
.shadowOpacity = _shadowOpacity,

View File

@@ -81,21 +81,12 @@ struct ASTextKitAttributes {
An array of scale factors in descending order to apply to the text to try to make it fit into a constrained size.
*/
NSArray *pointSizeScaleFactors;
/**
An optional block that returns a custom layout manager subclass. If nil, defaults to NSLayoutManager.
*/
NSLayoutManager * (^layoutManagerCreationBlock)(void);
/**
An optional delegate for the NSLayoutManager
*/
id<NSLayoutManagerDelegate> layoutManagerDelegate;
/**
An optional block that returns a custom NSTextStorage for the layout manager.
*/
NSTextStorage * (^textStorageCreationBlock)(NSAttributedString *attributedString);
/**
We provide an explicit copy function so we can use aggregate initializer syntax while providing copy semantics for
the NSObjects inside.
@@ -114,9 +105,7 @@ struct ASTextKitAttributes {
shadowOpacity,
shadowRadius,
pointSizeScaleFactors,
layoutManagerCreationBlock,
layoutManagerDelegate,
textStorageCreationBlock,
};
};
@@ -128,8 +117,6 @@ struct ASTextKitAttributes {
&& shadowOpacity == other.shadowOpacity
&& shadowRadius == other.shadowRadius
&& [pointSizeScaleFactors isEqualToArray:other.pointSizeScaleFactors]
&& layoutManagerCreationBlock == other.layoutManagerCreationBlock
&& textStorageCreationBlock == other.textStorageCreationBlock
&& CGSizeEqualToSize(shadowOffset, other.shadowOffset)
&& ASObjectIsEqual(exclusionPaths, other.exclusionPaths)
&& ASObjectIsEqual(avoidTailTruncationSet, other.avoidTailTruncationSet)

View File

@@ -23,8 +23,6 @@ size_t ASTextKitAttributes::hash() const
[attributedString hash],
[truncationAttributedString hash],
[avoidTailTruncationSet hash],
std::hash<NSUInteger>()((NSUInteger) layoutManagerCreationBlock),
std::hash<NSUInteger>()((NSUInteger) textStorageCreationBlock),
std::hash<NSInteger>()(lineBreakMode),
std::hash<NSInteger>()(maximumNumberOfLines),
[exclusionPaths hash],

View File

@@ -28,9 +28,7 @@
maximumNumberOfLines:(NSUInteger)maximumNumberOfLines
exclusionPaths:(NSArray *)exclusionPaths
constrainedSize:(CGSize)constrainedSize
layoutManagerCreationBlock:(NSLayoutManager * (^)(void))layoutCreationBlock
layoutManagerDelegate:(id<NSLayoutManagerDelegate>)layoutManagerDelegate
textStorageCreationBlock:(NSTextStorage * (^)(NSAttributedString *attributedString))textStorageCreationBlock;
layoutManagerDelegate:(id<NSLayoutManagerDelegate>)layoutManagerDelegate;
@property (nonatomic, assign, readwrite) CGSize constrainedSize;

View File

@@ -29,9 +29,7 @@
maximumNumberOfLines:(NSUInteger)maximumNumberOfLines
exclusionPaths:(NSArray *)exclusionPaths
constrainedSize:(CGSize)constrainedSize
layoutManagerCreationBlock:(NSLayoutManager * (^)(void))layoutCreationBlock
layoutManagerDelegate:(id<NSLayoutManagerDelegate>)layoutManagerDelegate
textStorageCreationBlock:(NSTextStorage * (^)(NSAttributedString *attributedString))textStorageCreationBlock
{
if (self = [super init]) {
@@ -42,12 +40,8 @@
__instanceLock__ = std::make_shared<ASDN::Mutex>();
// Create the TextKit component stack with our default configuration.
if (textStorageCreationBlock) {
_textStorage = textStorageCreationBlock(attributedString);
} else {
_textStorage = (attributedString ? [[NSTextStorage alloc] initWithAttributedString:attributedString] : [[NSTextStorage alloc] init]);
}
_layoutManager = layoutCreationBlock ? layoutCreationBlock() : [[ASLayoutManager alloc] init];
_textStorage = (attributedString ? [[NSTextStorage alloc] initWithAttributedString:attributedString] : [[NSTextStorage alloc] init]);
_layoutManager = [[ASLayoutManager alloc] init];
_layoutManager.usesFontLeading = NO;
_layoutManager.delegate = layoutManagerDelegate;
[_textStorage addLayoutManager:_layoutManager];

View File

@@ -90,9 +90,9 @@
static std::mutex __static_mutex;
std::lock_guard<std::mutex> l(__static_mutex);
NSTextStorage *textStorage = _attributes.textStorageCreationBlock ? _attributes.textStorageCreationBlock(attributedString) : [[NSTextStorage alloc] initWithAttributedString:attributedString];
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:attributedString];
if (_sizingLayoutManager == nil) {
_sizingLayoutManager = _attributes.layoutManagerCreationBlock ? _attributes.layoutManagerCreationBlock() : [[ASLayoutManager alloc] init];
_sizingLayoutManager = [[ASLayoutManager alloc] init];
_sizingLayoutManager.usesFontLeading = NO;
}
[textStorage addLayoutManager:_sizingLayoutManager];

View File

@@ -101,9 +101,7 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
maximumNumberOfLines:attributes.maximumNumberOfLines
exclusionPaths:attributes.exclusionPaths
constrainedSize:shadowConstrainedSize
layoutManagerCreationBlock:attributes.layoutManagerCreationBlock
layoutManagerDelegate:attributes.layoutManagerDelegate
textStorageCreationBlock:attributes.textStorageCreationBlock];
layoutManagerDelegate:attributes.layoutManagerDelegate];
}
return _context;
}

View File

@@ -67,9 +67,7 @@
maximumNumberOfLines:1
exclusionPaths:nil
constrainedSize:constrainedRect.size
layoutManagerCreationBlock:nil
layoutManagerDelegate:nil
textStorageCreationBlock:nil];
layoutManagerDelegate:nil];
__block CGRect truncationUsedRect;
[truncationContext performBlockWithLockedTextKitComponents:^(NSLayoutManager *truncationLayoutManager, NSTextStorage *truncationTextStorage, NSTextContainer *truncationTextContainer) {

View File

@@ -44,9 +44,7 @@
maximumNumberOfLines:0
exclusionPaths:nil
constrainedSize:constrainedSize
layoutManagerCreationBlock:nil
layoutManagerDelegate:nil
textStorageCreationBlock:nil];
layoutManagerDelegate:nil];
__block NSRange textKitVisibleRange;
[context performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
textKitVisibleRange = [layoutManager characterRangeForGlyphRange:[layoutManager glyphRangeForTextContainer:textContainer]
@@ -69,9 +67,7 @@
maximumNumberOfLines:0
exclusionPaths:nil
constrainedSize:constrainedSize
layoutManagerCreationBlock:nil
layoutManagerDelegate:nil
textStorageCreationBlock:nil];
layoutManagerDelegate:nil];
ASTextKitTailTruncater *tailTruncater = [[ASTextKitTailTruncater alloc] initWithContext:context
truncationAttributedString:[self _simpleTruncationAttributedString]
avoidTailTruncationSet:[NSCharacterSet characterSetWithCharactersInString:@""]];
@@ -95,9 +91,7 @@
maximumNumberOfLines:0
exclusionPaths:nil
constrainedSize:constrainedSize
layoutManagerCreationBlock:nil
layoutManagerDelegate:nil
textStorageCreationBlock:nil];
layoutManagerDelegate:nil];
ASTextKitTailTruncater *tailTruncater = [[ASTextKitTailTruncater alloc] initWithContext:context
truncationAttributedString:[self _simpleTruncationAttributedString]
avoidTailTruncationSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
@@ -120,9 +114,7 @@
maximumNumberOfLines:0
exclusionPaths:nil
constrainedSize:constrainedSize
layoutManagerCreationBlock:nil
layoutManagerDelegate:nil
textStorageCreationBlock:nil];
layoutManagerDelegate:nil];
ASTextKitTailTruncater *tailTruncater = [[ASTextKitTailTruncater alloc] initWithContext:context
truncationAttributedString:[self _simpleTruncationAttributedString]
avoidTailTruncationSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
@@ -146,9 +138,7 @@
maximumNumberOfLines:0
exclusionPaths:nil
constrainedSize:constrainedSize
layoutManagerCreationBlock:nil
layoutManagerDelegate:nil
textStorageCreationBlock:nil];
layoutManagerDelegate:nil];
ASTextKitTailTruncater *tailTruncater = [[ASTextKitTailTruncater alloc] initWithContext:context
truncationAttributedString:[self _simpleTruncationAttributedString]
avoidTailTruncationSet:nil];
@@ -166,9 +156,7 @@
maximumNumberOfLines:0
exclusionPaths:nil
constrainedSize:constrainedSize
layoutManagerCreationBlock:nil
layoutManagerDelegate:nil
textStorageCreationBlock:nil];
layoutManagerDelegate:nil];
ASTextKitTailTruncater *tailTruncater = [[ASTextKitTailTruncater alloc] initWithContext:context
truncationAttributedString:[self _simpleTruncationAttributedString]