mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-07 22:40:55 +08:00
Summary: Previously, we stored a pointer to ShadowNode inside NSAttributedString's attributes to make possible retrieving an EventEmitter associated with some text fragment. That worked fine besides only one caveat: the internal implementation of NSAttributedString is quite strange and that causes a memory leak. Because of some reason, NSAttributedString does not release stored attributes after own destruction (maybe OS uses some kind of caching). So, now, instead of storing a strong pointer to ShadowNode inside NSAttributedString, we store a weak pointer to EventEmitter. Storing a weak pointer is okay because a desired lifetime of EventEmitter is guaranteed by LocalData stored inside a View. Storing a weak EventEmitter instead of weak ShadowNode will also help us with migration to ShadowView (we cannot store ShadowView weakly because it's a stack allocated object). Reviewed By: sahrens Differential Revision: D13196886 fbshipit-source-id: f8714e4b3709765629d6456edf0c635bf5f7c53b
46 lines
1.4 KiB
Objective-C
46 lines
1.4 KiB
Objective-C
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
#import <react/attributedstring/AttributedString.h>
|
|
#import <react/attributedstring/ParagraphAttributes.h>
|
|
#import <react/core/LayoutConstraints.h>
|
|
#import <react/graphics/Geometry.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
/**
|
|
* iOS-specific TextLayoutManager
|
|
*/
|
|
@interface RCTTextLayoutManager : NSObject
|
|
|
|
- (facebook::react::Size)
|
|
measureWithAttributedString:
|
|
(facebook::react::AttributedString)attributedString
|
|
paragraphAttributes:
|
|
(facebook::react::ParagraphAttributes)paragraphAttributes
|
|
layoutConstraints:
|
|
(facebook::react::LayoutConstraints)layoutConstraints;
|
|
|
|
- (void)drawAttributedString:(facebook::react::AttributedString)attributedString
|
|
paragraphAttributes:
|
|
(facebook::react::ParagraphAttributes)paragraphAttributes
|
|
frame:(CGRect)frame;
|
|
|
|
- (facebook::react::SharedEventEmitter)
|
|
getEventEmitterWithAttributeString:
|
|
(facebook::react::AttributedString)attributedString
|
|
paragraphAttributes:
|
|
(facebook::react::ParagraphAttributes)paragraphAttributes
|
|
frame:(CGRect)frame
|
|
atPoint:(CGPoint)point;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|