Files
react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTTextPrimitivesConversions.h
T
Rob Hogan 61755aced1 Merge textDecoration(LineStyle|LinePattern) into textDecorationStyle
Summary:
The [first implementation of `TextAttributes` in Fabric](https://github.com/facebook/react-native/commit/62576bcb7832e08c6fd9f9482285882c37a2ece5) included two separate props instead of `textDecorationStyle`: `textDecorationLineStyle` (single, double, ...) and `textDecorationLinePattern` (dot, dash, dotdash, ...). These two props were implemented in C++ and iOS but never supported in JS.

Pre-Fabric (and CSS) on the other hand use a single prop `textDecorationStyle: 'solid' | 'double' | 'dotted' | 'dashed'`.

This diff implements this same API in Fabric, and removes the unused `textDecorationLineStyle` and `textDecorationLinePattern` props.

Changelog:
[iOS][Fixed] - Implement `textDecorationStyle` on iOS and remove unused `textDecorationLineStyle` and `textDecorationLinePattern` from Fabric.

Reviewed By: dmitryrykun

Differential Revision: D31617598

fbshipit-source-id: f5173e7ecdd31aafa0e5f0e50137eefa0505e007
2021-10-18 02:16:03 -07:00

95 lines
2.7 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 <UIKit/UIKit.h>
#include <react/renderer/textlayoutmanager/RCTFontProperties.h>
#include <react/renderer/textlayoutmanager/RCTFontUtils.h>
using namespace facebook::react;
inline static NSTextAlignment RCTNSTextAlignmentFromTextAlignment(TextAlignment textAlignment)
{
switch (textAlignment) {
case TextAlignment::Natural:
return NSTextAlignmentNatural;
case TextAlignment::Left:
return NSTextAlignmentLeft;
case TextAlignment::Right:
return NSTextAlignmentRight;
case TextAlignment::Center:
return NSTextAlignmentCenter;
case TextAlignment::Justified:
return NSTextAlignmentJustified;
}
}
inline static NSWritingDirection RCTNSWritingDirectionFromWritingDirection(WritingDirection writingDirection)
{
switch (writingDirection) {
case WritingDirection::Natural:
return NSWritingDirectionNatural;
case WritingDirection::LeftToRight:
return NSWritingDirectionLeftToRight;
case WritingDirection::RightToLeft:
return NSWritingDirectionRightToLeft;
}
}
inline static RCTFontStyle RCTFontStyleFromFontStyle(FontStyle fontStyle)
{
switch (fontStyle) {
case FontStyle::Normal:
return RCTFontStyleNormal;
case FontStyle::Italic:
return RCTFontStyleItalic;
case FontStyle::Oblique:
return RCTFontStyleOblique;
}
}
inline static RCTFontVariant RCTFontVariantFromFontVariant(FontVariant fontVariant)
{
return (RCTFontVariant)fontVariant;
}
inline static NSUnderlineStyle RCTNSUnderlineStyleFromTextDecorationStyle(TextDecorationStyle textDecorationStyle)
{
switch (textDecorationStyle) {
case TextDecorationStyle::Solid:
return NSUnderlineStyleSingle;
case TextDecorationStyle::Double:
return NSUnderlineStyleDouble;
case TextDecorationStyle::Dashed:
return NSUnderlinePatternDash | NSUnderlineStyleSingle;
case TextDecorationStyle::Dotted:
return NSUnderlinePatternDot | NSUnderlineStyleSingle;
}
}
inline static UIColor *RCTUIColorFromSharedColor(const SharedColor &sharedColor)
{
if (!sharedColor) {
return nil;
}
if (*facebook::react::clearColor() == *sharedColor) {
return [UIColor clearColor];
}
if (*facebook::react::blackColor() == *sharedColor) {
return [UIColor blackColor];
}
if (*facebook::react::whiteColor() == *sharedColor) {
return [UIColor whiteColor];
}
auto components = facebook::react::colorComponentsFromColor(sharedColor);
return [UIColor colorWithRed:components.red green:components.green blue:components.blue alpha:components.alpha];
}