-
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 9 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 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
87 changes: 87 additions & 0 deletions
87
android/src/main/java/com/expensify/livemarkdown/spans/MarkdownBackgroundSpan.java
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,87 @@ | ||
| package com.expensify.livemarkdown.spans; | ||
|
|
||
| import android.graphics.Canvas; | ||
| import android.graphics.Paint; | ||
| import android.graphics.Path; | ||
| import android.graphics.RectF; | ||
| import android.text.Spanned; | ||
| import android.text.style.LeadingMarginSpan; | ||
| import android.text.style.LineBackgroundSpan; | ||
|
|
||
| import androidx.annotation.ColorInt; | ||
| import androidx.annotation.NonNull; | ||
|
|
||
| public class MarkdownBackgroundSpan implements MarkdownSpan, LineBackgroundSpan { | ||
|
|
||
| private final int backgroundColor; | ||
| private final int mentionStart; | ||
| private final int mentionEnd; | ||
| private final float cornerRadius; | ||
war-in marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public MarkdownBackgroundSpan(@ColorInt int backgroundColor, float borderRadius, int mentionStart, int mentionEnd) { | ||
| this.backgroundColor = backgroundColor; | ||
| this.cornerRadius = borderRadius; | ||
| this.mentionStart = mentionStart; | ||
| this.mentionEnd = mentionEnd; | ||
| } | ||
|
|
||
| @Override | ||
| public void drawBackground( | ||
| @NonNull Canvas canvas, | ||
| @NonNull Paint paint, | ||
| int left, | ||
| int right, | ||
| int top, | ||
| int baseline, | ||
| int bottom, | ||
| @NonNull CharSequence text, | ||
| int start, | ||
| int end, | ||
| int lnum | ||
| ) { | ||
| int leadingMargin = getLeadingMargin(text, start, end); | ||
|
|
||
| boolean mentionStarts = start <= mentionStart; | ||
| boolean mentionEnds = end >= mentionEnd; | ||
|
|
||
| float startX = leadingMargin + (mentionStarts ? paint.measureText(text, start, mentionStart) : 0); | ||
| float endX = leadingMargin + paint.measureText(text, start, mentionEnds ? mentionEnd : end); | ||
|
|
||
| int originalColor = paint.getColor(); | ||
| paint.setColor(backgroundColor); | ||
|
|
||
| RectF lineRect = new RectF(startX, top, endX, bottom); | ||
| Path backgroundPath = new Path(); | ||
| backgroundPath.addRoundRect(lineRect, createRadii(mentionStarts, mentionEnds), Path.Direction.CW); | ||
| canvas.drawPath(backgroundPath, paint); | ||
|
|
||
| paint.setColor(originalColor); | ||
| } | ||
|
|
||
| private int getLeadingMargin(@NonNull CharSequence text, int start, int end) { | ||
| int leadingMargin = 0; | ||
| if (text instanceof Spanned spanned) { | ||
| LeadingMarginSpan[] marginSpans = spanned.getSpans(start, end, LeadingMarginSpan.class); | ||
| for (LeadingMarginSpan marginSpan : marginSpans) { | ||
| leadingMargin += marginSpan.getLeadingMargin(true); | ||
| } | ||
| } | ||
| return leadingMargin; | ||
| } | ||
|
|
||
| private float[] createRadii(boolean roundedLeft, boolean roundedRight) { | ||
| float[] radii = new float[8]; | ||
|
|
||
| if (roundedLeft) { | ||
| radii[0] = radii[1] = cornerRadius; // top-left | ||
| radii[6] = radii[7] = cornerRadius; // bottom-left | ||
| } | ||
|
|
||
| if (roundedRight) { | ||
| radii[2] = radii[3] = cornerRadius; // top-right | ||
| radii[4] = radii[5] = cornerRadius; // bottom-right | ||
| } | ||
|
|
||
| return radii; | ||
| } | ||
| } | ||
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
5 changes: 4 additions & 1 deletion
5
apple/BlockquoteTextLayoutFragment.h → apple/MarkdownTextLayoutFragment.h
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 |
|---|---|---|
| @@ -1,15 +1,18 @@ | ||
| #import <RNLiveMarkdown/RCTMarkdownUtils.h> | ||
| #import <RNLiveMarkdown/RCTMarkdownTextBackgroundUtils.h> | ||
| #import <UIKit/UIKit.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| API_AVAILABLE(ios(15.0)) | ||
| @interface BlockquoteTextLayoutFragment : NSTextLayoutFragment | ||
| @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 | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The amount of different start and end variables is a bit overwhelming there 😓. Maybe let's add some general comments or something?