RCTTextAttributes.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <UIKit/UIKit.h>
  8. #import <React/RCTTextDecorationLineType.h>
  9. #import "RCTTextTransform.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. extern NSString *const RCTTextAttributesIsHighlightedAttributeName;
  12. extern NSString *const RCTTextAttributesTagAttributeName;
  13. /**
  14. * Represents knowledge about all supported *text* attributes
  15. * assigned to some text component such as <Text>, <VirtualText>,
  16. * and <TextInput>.
  17. */
  18. @interface RCTTextAttributes : NSObject <NSCopying>
  19. // Color
  20. @property (nonatomic, strong, nullable) UIColor *foregroundColor;
  21. @property (nonatomic, strong, nullable) UIColor *backgroundColor;
  22. @property (nonatomic, assign) CGFloat opacity;
  23. // Font
  24. @property (nonatomic, copy, nullable) NSString *fontFamily;
  25. @property (nonatomic, assign) CGFloat fontSize;
  26. @property (nonatomic, assign) CGFloat fontSizeMultiplier;
  27. @property (nonatomic, assign) CGFloat maxFontSizeMultiplier;
  28. @property (nonatomic, copy, nullable) NSString *fontWeight;
  29. @property (nonatomic, copy, nullable) NSString *fontStyle;
  30. @property (nonatomic, copy, nullable) NSArray<NSString *> *fontVariant;
  31. @property (nonatomic, assign) BOOL allowFontScaling;
  32. @property (nonatomic, assign) CGFloat letterSpacing;
  33. // Paragraph Styles
  34. @property (nonatomic, assign) CGFloat lineHeight;
  35. @property (nonatomic, assign) NSTextAlignment alignment;
  36. @property (nonatomic, assign) NSWritingDirection baseWritingDirection;
  37. // Decoration
  38. @property (nonatomic, strong, nullable) UIColor *textDecorationColor;
  39. @property (nonatomic, assign) NSUnderlineStyle textDecorationStyle;
  40. @property (nonatomic, assign) RCTTextDecorationLineType textDecorationLine;
  41. // Shadow
  42. @property (nonatomic, assign) CGSize textShadowOffset;
  43. @property (nonatomic, assign) CGFloat textShadowRadius;
  44. @property (nonatomic, strong, nullable) UIColor *textShadowColor;
  45. // Special
  46. @property (nonatomic, assign) BOOL isHighlighted;
  47. @property (nonatomic, strong, nullable) NSNumber *tag;
  48. @property (nonatomic, assign) UIUserInterfaceLayoutDirection layoutDirection;
  49. @property (nonatomic, assign) RCTTextTransform textTransform;
  50. #pragma mark - Inheritance
  51. - (void)applyTextAttributes:(RCTTextAttributes *)textAttributes;
  52. #pragma mark - Adapters
  53. /**
  54. * Text attributes in NSAttributedString terms.
  55. */
  56. - (NSDictionary<NSAttributedStringKey, id> *)effectiveTextAttributes;
  57. /**
  58. * Constructed paragraph style.
  59. */
  60. - (NSParagraphStyle *_Nullable)effectiveParagraphStyle;
  61. /**
  62. * Constructed font.
  63. */
  64. - (UIFont *)effectiveFont;
  65. /**
  66. * Font size multiplier reflects `allowFontScaling`, `fontSizeMultiplier`, and `maxFontSizeMultiplier`.
  67. */
  68. - (CGFloat)effectiveFontSizeMultiplier;
  69. /**
  70. * Foreground and background colors with opacity and right defaults.
  71. */
  72. - (UIColor *)effectiveForegroundColor;
  73. - (UIColor *)effectiveBackgroundColor;
  74. /**
  75. * Text transformed per 'none', 'uppercase', 'lowercase', 'capitalize'
  76. */
  77. - (NSString *)applyTextAttributesToText:(NSString *)text;
  78. @end
  79. NS_ASSUME_NONNULL_END