mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
3b31e69e28
Summary: Changelog: [General] [Fixed] - License header cleanup Reviewed By: yungsters Differential Revision: D17952694 fbshipit-source-id: 17c87de7ebb271fa2ac8d00af72a4d1addef8bd0
100 lines
2.9 KiB
Objective-C
100 lines
2.9 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 <React/RCTTextViewManager.h>
|
|
|
|
#import <React/RCTShadowView+Layout.h>
|
|
#import <React/RCTShadowView.h>
|
|
#import <React/RCTUIManager.h>
|
|
#import <React/RCTUIManagerUtils.h>
|
|
#import <React/RCTUIManagerObserverCoordinator.h>
|
|
|
|
#import <React/RCTTextShadowView.h>
|
|
#import <React/RCTTextView.h>
|
|
|
|
@interface RCTTextViewManager () <RCTUIManagerObserver>
|
|
|
|
@end
|
|
|
|
@implementation RCTTextViewManager
|
|
{
|
|
NSHashTable<RCTTextShadowView *> *_shadowViews;
|
|
}
|
|
|
|
RCT_EXPORT_MODULE(RCTText)
|
|
|
|
RCT_REMAP_SHADOW_PROPERTY(numberOfLines, maximumNumberOfLines, NSInteger)
|
|
RCT_REMAP_SHADOW_PROPERTY(ellipsizeMode, lineBreakMode, NSLineBreakMode)
|
|
RCT_REMAP_SHADOW_PROPERTY(adjustsFontSizeToFit, adjustsFontSizeToFit, BOOL)
|
|
RCT_REMAP_SHADOW_PROPERTY(minimumFontScale, minimumFontScale, CGFloat)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(onTextLayout, RCTDirectEventBlock)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(selectable, BOOL)
|
|
|
|
- (void)setBridge:(RCTBridge *)bridge
|
|
{
|
|
[super setBridge:bridge];
|
|
_shadowViews = [NSHashTable weakObjectsHashTable];
|
|
|
|
[bridge.uiManager.observerCoordinator addObserver:self];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(handleDidUpdateMultiplierNotification)
|
|
name:@"RCTAccessibilityManagerDidUpdateMultiplierNotification"
|
|
object:[bridge moduleForName:@"AccessibilityManager"
|
|
lazilyLoadIfNecessary:YES]];
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
}
|
|
|
|
- (UIView *)view
|
|
{
|
|
return [RCTTextView new];
|
|
}
|
|
|
|
- (RCTShadowView *)shadowView
|
|
{
|
|
RCTTextShadowView *shadowView = [[RCTTextShadowView alloc] initWithBridge:self.bridge];
|
|
shadowView.textAttributes.fontSizeMultiplier = [[[self.bridge moduleForName:@"AccessibilityManager"]
|
|
valueForKey:@"multiplier"] floatValue];
|
|
[_shadowViews addObject:shadowView];
|
|
return shadowView;
|
|
}
|
|
|
|
#pragma mark - RCTUIManagerObserver
|
|
|
|
- (void)uiManagerWillPerformMounting:(__unused RCTUIManager *)uiManager
|
|
{
|
|
for (RCTTextShadowView *shadowView in _shadowViews) {
|
|
[shadowView uiManagerWillPerformMounting];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Font Size Multiplier
|
|
|
|
- (void)handleDidUpdateMultiplierNotification
|
|
{
|
|
CGFloat fontSizeMultiplier = [[[self.bridge moduleForName:@"AccessibilityManager"]
|
|
valueForKey:@"multiplier"] floatValue];
|
|
|
|
NSHashTable<RCTTextShadowView *> *shadowViews = _shadowViews;
|
|
RCTExecuteOnUIManagerQueue(^{
|
|
for (RCTTextShadowView *shadowView in shadowViews) {
|
|
shadowView.textAttributes.fontSizeMultiplier = fontSizeMultiplier;
|
|
[shadowView dirtyLayout];
|
|
}
|
|
|
|
[self.bridge.uiManager setNeedsLayout];
|
|
});
|
|
}
|
|
|
|
@end
|