-
Notifications
You must be signed in to change notification settings - Fork 95
[iOS & Android] Enable borderRadius in all mention types #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
war-in
wants to merge
24
commits into
Expensify:main
Choose a base branch
from
war-in:war-in/add-mention-user-border-radius
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0986812
add border radius to mention user
war-in 195ad24
mention-user highlighting v2
war-in 1b26ad4
mention-user highlighting v3 - it finally works!
war-in 521e78c
rewrite code to enable new mentions in blockquotes & add border radiu…
war-in 9d04008
fix web styles test
war-in 5a7c73c
rename attribute & use custom objects instead of dict
war-in ddeba51
address review
war-in ac410ee
support rounded background on android
war-in 870b5da
move `RCTMarkdownTextBackground` & `RCTMarkdownTextBackgroundWithRang…
war-in 99cf1fb
rename cornerRadius to borderRadius
war-in 8b416a5
rename cornerRadius to borderRadius iOS
war-in 28b6a13
fix blockquote `\n` issue
war-in 98dafda
use StaticLayout to correctly calculate text position
war-in a105c10
create layout for the specific part of the text to improve performance
war-in db307b2
Merge branch 'main' into war-in/add-mention-user-border-radius
war-in 8d5e9b2
Merge branch 'refs/heads/main' into war-in/add-mention-user-border-ra…
war-in bd8aaf3
Merge branch 'refs/heads/main' into war-in/add-mention-user-border-ra…
war-in 2a5069e
feat: add support for rounded corners in singleline input on iOS
war-in cbab252
fix: rounded background issues on singeline input when mentions were …
war-in f1b8c74
fix: Android - wrap mentions tightly, don't highlight entire line height
war-in 46ad23f
fix: iOS - wrap mentions tightly, don't highlight entire line height
war-in fe24512
fix: iOS - highlighting multiline mentions
war-in 39e0318
fix: Android - apply density to borderRadius to align radius on all d…
war-in 0da8207
chore: improve the iOS algorithm
war-in File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #import <RNLiveMarkdown/RCTMarkdownUtils.h> | ||
| #import <RNLiveMarkdown/MarkdownFormatter.h> | ||
| #import <UIKit/UIKit.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @interface RCTMarkdownTextBackgroundWithRange : NSObject | ||
| @property (nonnull, atomic) RCTMarkdownTextBackground *textBackground; | ||
| @property NSRange range; | ||
| @end | ||
|
|
||
| API_AVAILABLE(ios(15.0)) | ||
| @interface MarkdownTextLayoutFragment : NSTextLayoutFragment | ||
|
|
||
| @property (nonnull, atomic) RCTMarkdownUtils *markdownUtils; | ||
|
|
||
| @property NSUInteger depth; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point we might wanna rename |
||
|
|
||
| @property NSMutableArray<RCTMarkdownTextBackgroundWithRange *> *mentions; | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| #import <RNLiveMarkdown/MarkdownTextLayoutFragment.h> | ||
|
|
||
| @implementation RCTMarkdownTextBackgroundWithRange | ||
| @end | ||
|
|
||
| @implementation MarkdownTextLayoutFragment | ||
|
|
||
| #pragma mark - overriding class methods | ||
|
|
||
| - (CGRect)renderingSurfaceBounds { | ||
| if (self.depth == 0) { | ||
| return [super renderingSurfaceBounds]; | ||
| } | ||
| return CGRectUnion(self.boundingRect, [super renderingSurfaceBounds]); | ||
| } | ||
|
|
||
| - (void)drawAtPoint:(CGPoint)point inContext:(CGContextRef)ctx { | ||
| if (self.textLineFragments.count == 0) { | ||
| [super drawAtPoint:point inContext:ctx]; | ||
| return; | ||
| } | ||
|
|
||
| [self drawBlockquoteRibbons]; | ||
| [self drawMentions]; | ||
|
|
||
| [super drawAtPoint:point inContext:ctx]; | ||
| } | ||
|
|
||
| #pragma mark - drawing custom elements | ||
|
|
||
| - (void)drawBlockquoteRibbons { | ||
| if (self.depth == 0) { | ||
| return; | ||
| } | ||
|
|
||
| CGFloat marginLeft = _markdownUtils.markdownStyle.blockquoteMarginLeft; | ||
| CGFloat borderWidth = _markdownUtils.markdownStyle.blockquoteBorderWidth; | ||
| CGFloat paddingLeft = _markdownUtils.markdownStyle.blockquotePaddingLeft; | ||
| CGFloat shift = marginLeft + borderWidth + paddingLeft; | ||
|
|
||
| [_markdownUtils.markdownStyle.blockquoteBorderColor setFill]; | ||
|
|
||
| CGRect boundingRect = self.boundingRect; | ||
| for (NSUInteger level = 0; level < _depth; ++level) { | ||
| CGFloat x = boundingRect.origin.x + level * shift; | ||
| CGRect ribbonRect = CGRectMake(x, boundingRect.origin.y, borderWidth, boundingRect.size.height); | ||
| UIRectFill(ribbonRect); | ||
| } | ||
| } | ||
|
|
||
| - (void)drawMentions { | ||
| if (self.mentions.count == 0) { | ||
| return; | ||
| } | ||
|
|
||
| [self.textLineFragments enumerateObjectsUsingBlock:^(NSTextLineFragment * _Nonnull lineFragment, NSUInteger idx, BOOL * _Nonnull stop) { | ||
| if (lineFragment.characterRange.length == 0) { | ||
| return; | ||
| } | ||
|
|
||
| CGRect lineBounds = lineFragment.typographicBounds; | ||
| for (RCTMarkdownTextBackgroundWithRange *mention in self.mentions) { | ||
| NSRange intersection = NSIntersectionRange(lineFragment.characterRange, mention.range); | ||
| if (intersection.length == 0) { | ||
| continue; | ||
| } | ||
|
|
||
| CGPoint startLocation = [lineFragment locationForCharacterAtIndex:intersection.location]; | ||
| CGPoint endLocation = [lineFragment locationForCharacterAtIndex:intersection.location + intersection.length]; | ||
| CGFloat width = endLocation.x - startLocation.x; | ||
|
|
||
| CGRect backgroundRect = CGRectMake(startLocation.x, | ||
| lineBounds.origin.y, | ||
| width, | ||
| lineBounds.size.height); | ||
|
|
||
| BOOL isStart = (intersection.location == mention.range.location); | ||
| BOOL isEnd = (NSMaxRange(intersection) == NSMaxRange(mention.range)); | ||
| UIRectCorner cornersToRound = 0; | ||
war-in marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (isStart) { | ||
| cornersToRound |= UIRectCornerTopLeft | UIRectCornerBottomLeft; | ||
| } | ||
| if (isEnd) { | ||
| cornersToRound |= UIRectCornerTopRight | UIRectCornerBottomRight; | ||
| } | ||
|
|
||
| UIBezierPath *linePath = (cornersToRound == 0) | ||
| ? [UIBezierPath bezierPathWithRect:backgroundRect] | ||
| : [UIBezierPath bezierPathWithRoundedRect:backgroundRect | ||
| byRoundingCorners:cornersToRound | ||
| cornerRadii:CGSizeMake(mention.textBackground.cornerRadius, | ||
| mention.textBackground.cornerRadius)]; | ||
|
|
||
| [mention.textBackground.color setFill]; | ||
| [linePath fill]; | ||
| } | ||
| }]; | ||
| } | ||
|
|
||
| #pragma mark - helper functions | ||
|
|
||
| - (CGRect)boundingRect { | ||
| CGRect fragmentTextBounds = CGRectNull; | ||
| for (NSTextLineFragment *lineFragment in self.textLineFragments) { | ||
| if (lineFragment.characterRange.length == 0) { | ||
| continue; | ||
| } | ||
| CGRect lineFragmentBounds = lineFragment.typographicBounds; | ||
| if (CGRectIsNull(fragmentTextBounds)) { | ||
| fragmentTextBounds = lineFragmentBounds; | ||
war-in marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| fragmentTextBounds = CGRectUnion(fragmentTextBounds, lineFragmentBounds); | ||
| } | ||
| } | ||
|
|
||
| CGFloat marginLeft = _markdownUtils.markdownStyle.blockquoteMarginLeft; | ||
| CGFloat borderWidth = _markdownUtils.markdownStyle.blockquoteBorderWidth; | ||
| CGFloat paddingLeft = _markdownUtils.markdownStyle.blockquotePaddingLeft; | ||
| CGFloat shift = marginLeft + borderWidth + paddingLeft; | ||
|
|
||
| fragmentTextBounds.origin.x -= (paddingLeft + borderWidth) + shift * (_depth - 1); | ||
| fragmentTextBounds.size.width = borderWidth + shift * (_depth - 1); | ||
|
|
||
| return fragmentTextBounds; | ||
| } | ||
|
|
||
| @end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
war-in marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
war-in marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.