mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
8bd3edec88
Reviewed By: aaronabramov Differential Revision: D33367752 fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
95 lines
2.7 KiB
Objective-C
95 lines
2.7 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>
|
|
|
|
#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];
|
|
}
|