Files
react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTTextPrimitivesConversions.h
T
bang9 048194849b feat(iOS): added lineBreakStrategy attribute to Text/TextInput (#31272)
Summary:
iOS did not support the implementation of Korean word-wrap(line-break) before iOS14.
If the attribute applied, the word-wrap of Korean will works.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[iOS] [Added] -  Line break strategy for Text and TextInput components

Pull Request resolved: https://github.com/facebook/react-native/pull/31272

Test Plan:
1. Test build and run on above iOS 14.
2. Test it does not affect existing text components when set default(none) strategy.
3. Test whether word-wrap works with Korean when set hangul-word strategy.

<img src="https://user-images.githubusercontent.com/26326015/112963967-d7f70c00-9182-11eb-9a34-8c758b80c219.png" width="300" height="" style="max-width:100%;">

Reviewed By: javache

Differential Revision: D39824809

Pulled By: lunaleaps

fbshipit-source-id: 42cb0385221a38c84e80d3494d1bfc1934ecf32b
2022-10-17 13:14:17 -07:00

117 lines
3.4 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 NSLineBreakStrategy RCTNSLineBreakStrategyFromLineBreakStrategy(LineBreakStrategy lineBreakStrategy)
{
switch (lineBreakStrategy) {
case LineBreakStrategy::None:
return NSLineBreakStrategyNone;
case LineBreakStrategy::PushOut:
return NSLineBreakStrategyPushOut;
case LineBreakStrategy::HangulWordPriority:
if (@available(iOS 14.0, *)) {
return NSLineBreakStrategyHangulWordPriority;
} else {
return NSLineBreakStrategyNone;
}
case LineBreakStrategy::Standard:
if (@available(iOS 14.0, *)) {
return NSLineBreakStrategyStandard;
} else {
return NSLineBreakStrategyNone;
}
}
}
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];
}