mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
11c8bf3137
Summary: This adds Dynamic Type support in iOS as described [here](https://github.com/react-native-community/discussions-and-proposals/issues/519). `Text` elements have a new prop, `dynamicTypeRamp`, that allows users to specify which font ramp a particular `Text` element should take on as the OS's accessibility setting for text size. The different types line up with different values of `UIFontTextStyle`. If not specified, we default to the current behavior. ~~For the moment, this change is only for Paper. I tried applying a corresponding change to Fabric by adding an additional field to [`facebook::react::TextAttributes`](https://github.com/facebook/react-native/blob/main/ReactCommon/react/renderer/attributedstring/TextAttributes.h) and changing [`RCTEffectiveFontSizeMultiplierFromTextAttributes`](https://github.com/facebook/react-native/blob/afb124dcf0cdf0db525acc7cfd2cea2742c64068/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm#L79-L84) to use that new field, but in the process I discovered that this function doesn't seem to ever get called, hence [this bug](https://github.com/facebook/react-native/issues/34990).~~ ## Changelog [iOS] [Added] - Dynamic Type support Pull Request resolved: https://github.com/facebook/react-native/pull/35017 Test Plan: Validated with a test page in RNTester. Screenshots follow: A) Default text size B) Largest non-accessibility text size C) Largest accessibility text size, split across two screenshots due to size | A | B | C | |-|-|-| |  |  |  | |||  | Reviewed By: sammy-SC Differential Revision: D40779346 Pulled By: NickGerleman fbshipit-source-id: efc7a8e9810a93afc82c5def97af15a2e8453d90
101 lines
3.2 KiB
Objective-C
101 lines
3.2 KiB
Objective-C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and 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/RCTDynamicTypeRamp.h>
|
|
#import <React/RCTTextDecorationLineType.h>
|
|
|
|
#import "RCTTextTransform.h"
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
extern NSString *const RCTTextAttributesIsHighlightedAttributeName;
|
|
extern NSString *const RCTTextAttributesTagAttributeName;
|
|
|
|
/**
|
|
* Represents knowledge about all supported *text* attributes
|
|
* assigned to some text component such as <Text>, <VirtualText>,
|
|
* and <TextInput>.
|
|
*/
|
|
@interface RCTTextAttributes : NSObject <NSCopying>
|
|
|
|
// Color
|
|
@property (nonatomic, strong, nullable) UIColor *foregroundColor;
|
|
@property (nonatomic, strong, nullable) UIColor *backgroundColor;
|
|
@property (nonatomic, assign) CGFloat opacity;
|
|
// Font
|
|
@property (nonatomic, copy, nullable) NSString *fontFamily;
|
|
@property (nonatomic, assign) CGFloat fontSize;
|
|
@property (nonatomic, assign) CGFloat fontSizeMultiplier;
|
|
@property (nonatomic, assign) CGFloat maxFontSizeMultiplier;
|
|
@property (nonatomic, copy, nullable) NSString *fontWeight;
|
|
@property (nonatomic, copy, nullable) NSString *fontStyle;
|
|
@property (nonatomic, copy, nullable) NSArray<NSString *> *fontVariant;
|
|
@property (nonatomic, assign) BOOL allowFontScaling;
|
|
@property (nonatomic, assign) RCTDynamicTypeRamp dynamicTypeRamp;
|
|
@property (nonatomic, assign) CGFloat letterSpacing;
|
|
// Paragraph Styles
|
|
@property (nonatomic, assign) CGFloat lineHeight;
|
|
@property (nonatomic, assign) NSTextAlignment alignment;
|
|
@property (nonatomic, assign) NSWritingDirection baseWritingDirection;
|
|
@property (nonatomic, assign) NSLineBreakStrategy lineBreakStrategy;
|
|
// Decoration
|
|
@property (nonatomic, strong, nullable) UIColor *textDecorationColor;
|
|
@property (nonatomic, assign) NSUnderlineStyle textDecorationStyle;
|
|
@property (nonatomic, assign) RCTTextDecorationLineType textDecorationLine;
|
|
// Shadow
|
|
@property (nonatomic, assign) CGSize textShadowOffset;
|
|
@property (nonatomic, assign) CGFloat textShadowRadius;
|
|
@property (nonatomic, strong, nullable) UIColor *textShadowColor;
|
|
// Special
|
|
@property (nonatomic, assign) BOOL isHighlighted;
|
|
@property (nonatomic, strong, nullable) NSNumber *tag;
|
|
@property (nonatomic, assign) UIUserInterfaceLayoutDirection layoutDirection;
|
|
@property (nonatomic, assign) RCTTextTransform textTransform;
|
|
|
|
#pragma mark - Inheritance
|
|
|
|
- (void)applyTextAttributes:(RCTTextAttributes *)textAttributes;
|
|
|
|
#pragma mark - Adapters
|
|
|
|
/**
|
|
* Text attributes in NSAttributedString terms.
|
|
*/
|
|
- (NSDictionary<NSAttributedStringKey, id> *)effectiveTextAttributes;
|
|
|
|
/**
|
|
* Constructed paragraph style.
|
|
*/
|
|
- (NSParagraphStyle *_Nullable)effectiveParagraphStyle;
|
|
|
|
/**
|
|
* Constructed font.
|
|
*/
|
|
- (UIFont *)effectiveFont;
|
|
|
|
/**
|
|
* Font size multiplier reflects `allowFontScaling`, `fontSizeMultiplier`, and `maxFontSizeMultiplier`.
|
|
*/
|
|
- (CGFloat)effectiveFontSizeMultiplier;
|
|
|
|
/**
|
|
* Foreground and background colors with opacity and right defaults.
|
|
*/
|
|
- (UIColor *)effectiveForegroundColor;
|
|
- (UIColor *)effectiveBackgroundColor;
|
|
|
|
/**
|
|
* Text transformed per 'none', 'uppercase', 'lowercase', 'capitalize'
|
|
*/
|
|
- (NSString *)applyTextAttributesToText:(NSString *)text;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|