Skip to content
Draft
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
1 change: 1 addition & 0 deletions ios/EnrichedTextInputView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "InputParser.h"
#import "BaseStyleProtocol.h"
#import "InputTextView.h"
#import "RCTI18nUtil.h"

#ifndef EnrichedTextInputViewNativeComponent_h
#define EnrichedTextInputViewNativeComponent_h
Expand Down
18 changes: 17 additions & 1 deletion ios/EnrichedTextInputView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
defaultTypingAttributes[NSFontAttributeName] = [config primaryFont];
defaultTypingAttributes[NSUnderlineColorAttributeName] = [config primaryColor];
defaultTypingAttributes[NSStrikethroughColorAttributeName] = [config primaryColor];
defaultTypingAttributes[NSParagraphStyleAttributeName] = [[NSParagraphStyle alloc] init];
defaultTypingAttributes[NSParagraphStyleAttributeName] = [self prepareDefaultParagraphStyle];
textView.typingAttributes = defaultTypingAttributes;

// update the placeholder as well
Expand Down Expand Up @@ -522,6 +522,22 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
}
}

- (NSMutableParagraphStyle * )prepareDefaultParagraphStyle
{
NSMutableParagraphStyle *pStyle = [[NSMutableParagraphStyle alloc] init];

BOOL isRTL = [[RCTI18nUtil sharedInstance] isRTL];

if (isRTL) {
pStyle.baseWritingDirection = NSWritingDirectionRightToLeft;
} else {
pStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
}
pStyle.baseWritingDirection = NSWritingDirectionRightToLeft;

return pStyle;
}

- (void)setPlaceholderLabelShown:(BOOL)shown {
if(shown) {
[self refreshPlaceholderLabelStyles];
Expand Down
40 changes: 33 additions & 7 deletions ios/utils/LayoutManagerExtension.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ - (void)my_drawBackgroundForGlyphRange:(NSRange)glyphRange atPoint:(CGPoint)orig
NSRange paragraphGlyphRange = [self glyphRangeForCharacterRange:paragraphRange actualCharacterRange:nullptr];
[self enumerateLineFragmentsForGlyphRange:paragraphGlyphRange
usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer * _Nonnull textContainer, NSRange glyphRange, BOOL * _Nonnull stop) {
CGFloat paddingLeft = origin.x;
CGFloat paddingTop = origin.y;
CGFloat x = paddingLeft;
CGFloat y = paddingTop + rect.origin.y;
BOOL isRTL = [[RCTI18nUtil sharedInstance] isRTL];
CGFloat width = [typedInput->config blockquoteBorderWidth];
CGFloat height = rect.size.height;

CGFloat x = 0;
if (isRTL) {
x = origin.x + rect.size.width - width;
} else {
x = origin.x;
}
CGFloat y = origin.y + rect.origin.y;

CGRect lineRect = CGRectMake(x, y, width, height);
[[typedInput->config blockquoteBorderColor] setFill];
Expand Down Expand Up @@ -103,18 +108,34 @@ - (void)my_drawBackgroundForGlyphRange:(NSRange)glyphRange atPoint:(CGPoint)orig
[self enumerateLineFragmentsForGlyphRange:paragraphGlyphRange
usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer *container, NSRange lineGlyphRange, BOOL *stop) {
NSString *marker = [self markerForList:pStyle.textLists.firstObject charIndex:[self characterIndexForGlyphAtIndex:lineGlyphRange.location] input:typedInput];
BOOL isRTL = [[RCTI18nUtil sharedInstance] isRTL];

CGFloat textStartLeft = usedRect.origin.x;
CGFloat textEndRight = usedRect.origin.x + usedRect.size.width;

if(pStyle.textLists.firstObject.markerFormat == NSTextListMarkerDecimal) {
CGFloat gapWidth = [typedInput->config orderedListGapWidth];
CGFloat markerWidth = [marker sizeWithAttributes:markerAttributes].width;
CGFloat markerX = usedRect.origin.x - gapWidth - markerWidth/2;
CGFloat markerX = 0;

if (isRTL) {
markerX = textEndRight + gapWidth;
} else {
markerX = textStartLeft - gapWidth - markerWidth / 2;
}

[marker drawAtPoint:CGPointMake(markerX, usedRect.origin.y + origin.y) withAttributes:markerAttributes];
} else {
CGFloat gapWidth = [typedInput->config unorderedListGapWidth];
CGFloat bulletSize = [typedInput->config unorderedListBulletSize];
CGFloat bulletX = usedRect.origin.x - gapWidth - bulletSize/2;
CGFloat centerY = CGRectGetMidY(usedRect);
CGFloat bulletX = 0;

if (isRTL) {
bulletX = textEndRight + gapWidth + (bulletSize / 2.0);
} else {
bulletX = textStartLeft - gapWidth - (bulletSize / 2.0);
}

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context); {
Expand Down Expand Up @@ -161,8 +182,13 @@ - (NSString *)markerForList:(NSTextList *)list charIndex:(NSUInteger)index input

itemNumber = prevParagraphsCount + 1;
}
BOOL isRTL = [[RCTI18nUtil sharedInstance] isRTL];

return [NSString stringWithFormat:@"%ld.", (long)(itemNumber)];
if (isRTL) {
return [NSString stringWithFormat:@".%ld", (long)(itemNumber)];
} else {
return [NSString stringWithFormat:@"%ld.", (long)(itemNumber)];
}
} else {
return @"•";
}
Expand Down
Loading