2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import "RCTTextManager.h"
|
|
|
|
|
2016-12-07 13:12:11 +00:00
|
|
|
#import <yoga/Yoga.h>
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTAccessibilityManager.h>
|
|
|
|
#import <React/RCTAssert.h>
|
|
|
|
#import <React/RCTConvert.h>
|
|
|
|
#import <React/RCTLog.h>
|
|
|
|
#import <React/UIView+React.h>
|
2016-09-06 16:12:42 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTShadowRawText.h"
|
|
|
|
#import "RCTShadowText.h"
|
|
|
|
#import "RCTText.h"
|
2015-11-04 12:04:37 +00:00
|
|
|
#import "RCTTextView.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-05-31 17:18:37 +00:00
|
|
|
static void collectDirtyNonTextDescendants(RCTShadowText *shadowView, NSMutableArray *nonTextDescendants) {
|
|
|
|
for (RCTShadowView *child in shadowView.reactSubviews) {
|
|
|
|
if ([child isKindOfClass:[RCTShadowText class]]) {
|
|
|
|
collectDirtyNonTextDescendants((RCTShadowText *)child, nonTextDescendants);
|
|
|
|
} else if ([child isKindOfClass:[RCTShadowRawText class]]) {
|
|
|
|
// no-op
|
|
|
|
} else if ([child isTextDirty]) {
|
|
|
|
[nonTextDescendants addObject:child];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-04 12:04:37 +00:00
|
|
|
@interface RCTShadowText (Private)
|
|
|
|
|
2016-12-02 13:47:43 +00:00
|
|
|
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(YGMeasureMode)widthMode;
|
2015-11-04 12:04:37 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
@implementation RCTTextManager
|
|
|
|
|
2015-04-08 12:42:43 +00:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
- (UIView *)view
|
|
|
|
{
|
2015-08-17 14:35:34 +00:00
|
|
|
return [RCTText new];
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (RCTShadowView *)shadowView
|
|
|
|
{
|
2015-08-17 14:35:34 +00:00
|
|
|
return [RCTShadowText new];
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 14:04:39 +00:00
|
|
|
#pragma mark - Shadow properties
|
|
|
|
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(color, UIColor)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(fontFamily, NSString)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(fontSize, CGFloat)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(fontWeight, NSString)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(fontStyle, NSString)
|
2016-08-09 15:42:58 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(fontVariant, NSArray)
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(isHighlighted, BOOL)
|
2015-05-12 07:25:08 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(letterSpacing, CGFloat)
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(lineHeight, CGFloat)
|
2015-07-07 13:03:56 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(numberOfLines, NSUInteger)
|
2016-07-25 20:05:14 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(ellipsizeMode, NSLineBreakMode)
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(textAlign, NSTextAlignment)
|
2015-07-07 13:03:56 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(textDecorationStyle, NSUnderlineStyle)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(textDecorationColor, UIColor)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(textDecorationLine, RCTTextDecorationLineType)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(writingDirection, NSWritingDirection)
|
2015-07-31 14:37:12 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(allowFontScaling, BOOL)
|
2015-11-04 16:52:46 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(opacity, CGFloat)
|
2016-01-01 17:32:59 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(textShadowOffset, CGSize)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(textShadowRadius, CGFloat)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(textShadowColor, UIColor)
|
2016-08-10 18:14:36 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(adjustsFontSizeToFit, BOOL)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(minimumFontScale, CGFloat)
|
2016-11-18 00:09:43 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(selectable, BOOL)
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-11-14 18:25:00 +00:00
|
|
|
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NSNumber *, RCTShadowView *> *)shadowViewRegistry
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
2015-11-14 18:25:00 +00:00
|
|
|
for (RCTShadowView *rootView in shadowViewRegistry.allValues) {
|
2015-02-20 04:10:52 +00:00
|
|
|
if (![rootView isReactRootView]) {
|
|
|
|
// This isn't a root view
|
|
|
|
continue;
|
|
|
|
}
|
2015-03-23 20:28:42 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
if (![rootView isTextDirty]) {
|
|
|
|
// No text processing to be done
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-11-03 22:45:46 +00:00
|
|
|
NSMutableArray<RCTShadowView *> *queue = [NSMutableArray arrayWithObject:rootView];
|
2015-08-24 10:14:33 +00:00
|
|
|
for (NSInteger i = 0; i < queue.count; i++) {
|
2015-02-20 04:10:52 +00:00
|
|
|
RCTShadowView *shadowView = queue[i];
|
|
|
|
RCTAssert([shadowView isTextDirty], @"Don't process any nodes that don't have dirty text");
|
|
|
|
|
|
|
|
if ([shadowView isKindOfClass:[RCTShadowText class]]) {
|
2015-08-24 10:14:33 +00:00
|
|
|
((RCTShadowText *)shadowView).fontSizeMultiplier = self.bridge.accessibilityManager.multiplier;
|
2015-05-29 17:27:14 +00:00
|
|
|
[(RCTShadowText *)shadowView recomputeText];
|
2016-05-31 17:18:37 +00:00
|
|
|
collectDirtyNonTextDescendants((RCTShadowText *)shadowView, queue);
|
2015-02-20 04:10:52 +00:00
|
|
|
} else if ([shadowView isKindOfClass:[RCTShadowRawText class]]) {
|
2015-05-27 01:39:37 +00:00
|
|
|
RCTLogError(@"Raw text cannot be used outside of a <Text> tag. Not rendering string: '%@'",
|
|
|
|
[(RCTShadowRawText *)shadowView text]);
|
2015-02-20 04:10:52 +00:00
|
|
|
} else {
|
|
|
|
for (RCTShadowView *child in [shadowView reactSubviews]) {
|
|
|
|
if ([child isTextDirty]) {
|
|
|
|
[queue addObject:child];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[shadowView setTextComputed];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 10:53:50 +00:00
|
|
|
return nil;
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 09:19:49 +00:00
|
|
|
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowText *)shadowView
|
2015-03-27 16:36:33 +00:00
|
|
|
{
|
|
|
|
NSNumber *reactTag = shadowView.reactTag;
|
|
|
|
UIEdgeInsets padding = shadowView.paddingAsInsets;
|
2015-04-07 09:19:49 +00:00
|
|
|
|
2015-11-14 18:25:00 +00:00
|
|
|
return ^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTText *> *viewRegistry) {
|
2015-04-29 08:29:00 +00:00
|
|
|
RCTText *text = viewRegistry[reactTag];
|
2015-04-07 09:19:49 +00:00
|
|
|
text.contentInset = padding;
|
2015-03-27 16:36:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
@end
|