mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Merge pull request #1437 from ejensen/editable-text-node-layout-manager
[ASEditableTextNode] Allow TextKit component customization
This commit is contained in:
@@ -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.
|
||||
@@ -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];
|
||||
Reference in New Issue
Block a user