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"
|
|
|
|
|
2015-07-31 14:37:12 +00:00
|
|
|
#import "RCTAccessibilityManager.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTAssert.h"
|
|
|
|
#import "RCTConvert.h"
|
|
|
|
#import "RCTLog.h"
|
|
|
|
#import "RCTShadowRawText.h"
|
|
|
|
#import "RCTShadowText.h"
|
|
|
|
#import "RCTSparseArray.h"
|
|
|
|
#import "RCTText.h"
|
2015-03-26 09:58:06 +00:00
|
|
|
#import "UIView+React.h"
|
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
|
|
|
|
{
|
|
|
|
return [[RCTText alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (RCTShadowView *)shadowView
|
|
|
|
{
|
|
|
|
return [[RCTShadowText alloc] init];
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
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)
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(shadowOffset, CGSize)
|
|
|
|
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-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(RCTSparseArray *)shadowViewRegistry
|
|
|
|
{
|
|
|
|
for (RCTShadowView *rootView in shadowViewRegistry.allObjects) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableArray *queue = [NSMutableArray arrayWithObject:rootView];
|
|
|
|
for (NSInteger i = 0; i < [queue count]; i++) {
|
|
|
|
RCTShadowView *shadowView = queue[i];
|
|
|
|
RCTAssert([shadowView isTextDirty], @"Don't process any nodes that don't have dirty text");
|
|
|
|
|
|
|
|
if ([shadowView isKindOfClass:[RCTShadowText class]]) {
|
2015-07-31 14:37:12 +00:00
|
|
|
[(RCTShadowText *)shadowView setFontSizeMultiplier:self.bridge.accessibilityManager.multiplier];
|
2015-05-29 17:27:14 +00:00
|
|
|
[(RCTShadowText *)shadowView recomputeText];
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 17:27:14 +00:00
|
|
|
return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {};
|
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-03-27 16:36:33 +00:00
|
|
|
return ^(RCTUIManager *uiManager, RCTSparseArray *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
|