-
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
27
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 all commits
Commits
Show all changes
27 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 48830e5
Merge branch 'refs/heads/main' into war-in/add-mention-user-border-ra…
war-in 6665f83
chore: iOS - apply review
war-in c556257
chore: Android - apply review
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,15 +40,15 @@ test.describe('markdown content styling', () => { | |
| }); | ||
|
|
||
| test('mention-here', async ({page}) => { | ||
| await testMarkdownContentStyle({testContent: 'here', style: 'color: green; background-color: lime;', page}); | ||
| await testMarkdownContentStyle({testContent: 'here', style: 'color: green; background-color: lime; border-radius: 5px;', page}); | ||
| }); | ||
|
|
||
| test('mention-user', async ({page}) => { | ||
| await testMarkdownContentStyle({testContent: '[email protected]', style: 'color: blue; background-color: cyan;', page}); | ||
| await testMarkdownContentStyle({testContent: '[email protected]', style: 'color: blue; background-color: cyan; border-radius: 5px;', page}); | ||
| }); | ||
|
|
||
| test('mention-report', async ({page}) => { | ||
| await testMarkdownContentStyle({testContent: 'mention-report', style: 'color: red; background-color: pink;', page}); | ||
| await testMarkdownContentStyle({testContent: 'mention-report', style: 'color: red; background-color: pink; border-radius: 5px;', page}); | ||
| }); | ||
|
|
||
| test('blockquote', async ({page, browserName}) => { | ||
|
|
||
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
94 changes: 94 additions & 0 deletions
94
android/src/main/java/com/expensify/livemarkdown/spans/MarkdownBackgroundSpan.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package com.expensify.livemarkdown.spans; | ||
|
|
||
| import android.graphics.Canvas; | ||
| import android.graphics.Paint; | ||
| import android.graphics.Path; | ||
| import android.graphics.RectF; | ||
| import android.text.StaticLayout; | ||
| import android.text.TextPaint; | ||
| 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 borderRadius; | ||
|
|
||
| private StaticLayout layout; | ||
| private Path backgroundPath; | ||
|
|
||
| public MarkdownBackgroundSpan(@ColorInt int backgroundColor, float borderRadius, int mentionStart, int mentionEnd) { | ||
| this.backgroundColor = backgroundColor; | ||
| this.borderRadius = borderRadius; | ||
| this.mentionStart = mentionStart; | ||
| this.mentionEnd = mentionEnd; | ||
| this.backgroundPath = new Path(); | ||
| } | ||
|
|
||
| @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 | ||
| ) { | ||
| CharSequence lineText = text.subSequence(start, end); | ||
| if (layout == null || layout.getText() != lineText || layout.getWidth() != right || layout.getLineEnd(0) != lineText.length()) { | ||
| int currentLineStart = 0; | ||
| int currentLineEnd = lineText.length(); | ||
| // Create layout for the current line only | ||
| layout = StaticLayout.Builder.obtain(lineText, currentLineStart, currentLineEnd, (TextPaint) paint, right).build(); | ||
|
|
||
| int relativeMentionStart = mentionStart - start; | ||
| int relativeMentionEnd = mentionEnd - start; | ||
|
|
||
| boolean mentionStartsInCurrentLine = currentLineStart <= relativeMentionStart; | ||
| boolean mentionEndsInCurrentLine = currentLineEnd >= relativeMentionEnd; | ||
|
|
||
| float startX = layout.getPrimaryHorizontal(mentionStartsInCurrentLine ? relativeMentionStart: currentLineStart); | ||
| float endX = layout.getPrimaryHorizontal(mentionEndsInCurrentLine ? relativeMentionEnd : currentLineEnd); | ||
|
|
||
| Paint.FontMetrics fm = paint.getFontMetrics(); | ||
| float startY = baseline + fm.ascent; | ||
| float endY = baseline + fm.descent; | ||
|
|
||
| RectF lineRect = new RectF(startX, startY, endX, endY); | ||
| backgroundPath.reset(); | ||
| backgroundPath.addRoundRect(lineRect, createRadii(mentionStartsInCurrentLine, mentionEndsInCurrentLine), Path.Direction.CW); | ||
| } | ||
|
|
||
| int originalColor = paint.getColor(); | ||
| paint.setColor(backgroundColor); | ||
|
|
||
| canvas.drawPath(backgroundPath, paint); | ||
|
|
||
| paint.setColor(originalColor); | ||
| } | ||
|
|
||
| private float[] createRadii(boolean roundedLeft, boolean roundedRight) { | ||
| float[] radii = new float[8]; | ||
|
|
||
| if (roundedLeft) { | ||
| radii[0] = radii[1] = borderRadius; // top-left | ||
| radii[6] = radii[7] = borderRadius; // bottom-left | ||
| } | ||
|
|
||
| if (roundedRight) { | ||
| radii[2] = radii[3] = borderRadius; // top-right | ||
| radii[4] = radii[5] = borderRadius; // 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
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/RCTMarkdownTextBackgroundWithRange.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; | ||
war-in marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @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.
I'd rather keep the original value of
borderRadiusinMarkdownStyleand multiply it byscreenDensitynear the drawing logic.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.
I tried that but context is not available in span so I had to pass it down and the code looked messy
We can do that but this approach is much cleaner