Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ static NSTextAlignment NSTextAlignmentFromTextAlign(NSString *textAlign, LayoutD
return paragraphStyle.alignment;
}

static NSParagraphStyle *ParagraphStyleFromLayoutDirection(std::optional<LayoutDirection> layoutDirection)
{
TextAttributes textAttributes;
textAttributes.layoutDirection = layoutDirection;

NSDictionary<NSAttributedStringKey, id> *attributes = RCTNSTextAttributesFromTextAttributes(textAttributes);
return attributes[NSParagraphStyleAttributeName];
}

static UIFont *FontFromSettings(std::optional<std::string> settings, std::optional<FontWeight> weight = std::nullopt)
{
TextAttributes textAttributes;
Expand Down Expand Up @@ -133,6 +142,22 @@ - (void)testTextAlignmentStartAndEndResolveWithLayoutDirection
XCTAssertEqual(NSTextAlignmentFromTextAlign(@"end", LayoutDirection::RightToLeft), NSTextAlignmentLeft);
}

- (void)testUndeclaredTextAlignmentResolvesWithLayoutDirection
{
NSParagraphStyle *leftToRight = ParagraphStyleFromLayoutDirection(LayoutDirection::LeftToRight);
XCTAssertNotNil(leftToRight);
XCTAssertEqual(leftToRight.alignment, NSTextAlignmentLeft);

NSParagraphStyle *rightToLeft = ParagraphStyleFromLayoutDirection(LayoutDirection::RightToLeft);
XCTAssertNotNil(rightToLeft);
XCTAssertEqual(rightToLeft.alignment, NSTextAlignmentRight);
}

- (void)testUndeclaredTextAlignmentWithoutLayoutDirectionStaysNatural
{
XCTAssertNil(ParagraphStyleFromLayoutDirection(std::nullopt));
}

- (void)testSamenessOfEmptyAttributedStrings
{
NSAttributedString *attributedString1 = [[NSAttributedString alloc] initWithString:@""];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
BOOL isParagraphStyleUsed = NO;
const bool isRTL = textAttributes.layoutDirection == LayoutDirection::RightToLeft;
if (textAttributes.alignment.has_value() || isRTL) {
if (textAttributes.alignment.has_value() || textAttributes.layoutDirection.has_value()) {
TextAlignment textAlignment =
RCTResolveTextAlignment(textAttributes.alignment.value_or(TextAlignment::Natural), isRTL);

Expand Down
Loading