-
Notifications
You must be signed in to change notification settings - Fork 23
[Android] Add support for mentions to the Compose library #854
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #854 +/- ##
==========================================
- Coverage 89.50% 89.34% -0.17%
==========================================
Files 116 86 -30
Lines 16801 15247 -1554
Branches 633 0 -633
==========================================
- Hits 15038 13622 -1416
+ Misses 1740 1625 -115
+ Partials 23 0 -23
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
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.
Looks good! Just one comment about a potential performance issue with the composable
platforms/android/example-compose/src/main/java/io/element/wysiwyg/compose/MainActivity.kt
Show resolved
Hide resolved
if (style != previousStyle) { | ||
view.setStyleConfig(style.toStyleConfig(view.context)) |
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 don't think this should be necessary because the update
block should only run when one of the variables used inside it is changed. When I tested it looks like there issue causing the update
method to fire every time the state is changed which is a problem.
Are you able to check and see if there is a stability issue using the compose compiler reports tool?
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.
MentionDisplayHandler
is an interface, so I think it's impossible for compose to check if it has changed. Maybe that's what's causing the unnecessary recompositions.
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 wrapped the mentionDisplayHandler
parameter in a lambda to make it stable and prevent recompositions, but there's still some weird issue with style
and textStyleTypeface
, where they won't cause recompositions when the code is build from a clean state, but if anything in the code changes and we re-build, the update
block will recompose with every change in the composer.
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.
@jonnyandrew could you double check if you can also reproduce the issue above? If not, it might just be an issue on my side and we can assume this is fixed.
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.
Very odd - I can reproduce this unfortunately.
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.
Now that we have a bit more time to work with, is there any way we can eliminate these workarounds (remember
and previousStyle
)?
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.
It depends on whether we want to avoid creating a new HtmlConverter
every time anything changes in this component or not. The remember
makes the update more predictable, but it will still be triggered when any of its params change.
The current AndroidHtmlConverter
is quite light-weight since it only creates a lambda, so we could allow this, or even create the converter on demand whenever it's supposed to be used, but this might not be the case for future or alternative implementations.
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 was hoping we could try to remove the remember
altogether if we can find out why update
is being called in an unpredictable way 😅
In terms of the HtmlConverter
, I don't see to much problem with doing this in update
, given it should only be called infrequently in practice.
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.
Ok, I'll remove the previousStyle
check, but the remember
will have to stay for now, I don't really see what's causing the lambda to be re-created...
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.
Actually, previousStyle
has already been removed 😅 . I completely forgot about that.
...d/library-compose/src/main/java/io/element/android/wysiwyg/compose/RichTextEditorDefaults.kt
Outdated
Show resolved
Hide resolved
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.
Thanks for the changes! I had a few comments
...s/android/library-compose/src/main/java/io/element/android/wysiwyg/compose/RichTextEditor.kt
Outdated
Show resolved
Hide resolved
...ms/android/library/src/main/java/io/element/android/wysiwyg/display/MentionDisplayHandler.kt
Outdated
Show resolved
Hide resolved
platforms/android/library/src/main/java/io/element/android/wysiwyg/utils/HtmlToSpansParser.kt
Outdated
Show resolved
Hide resolved
Also solve theming issues.
I don't like the way we need to provide the |
The UI tests do work locally, btw. It seems like the project has had issues running these tests for a while, from what I've seen in the results of run actions for other PRs. |
…ons. Also: - Add missing `mentionDetector` lambda to `StyledHtmlConverter`. - Add optimizations for recompositions in `EditorStyledText`.
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.
Thanks for the changes! Sorry it's taking so long to merge this. I've added a few more comments.
...oid/example-compose/src/main/java/io/element/wysiwyg/compose/DefaultMentionDisplayHandler.kt
Outdated
Show resolved
Hide resolved
...ew/src/main/java/io/element/android/wysiwyg/poc/matrix/MatrixMentionMentionDisplayHandler.kt
Outdated
Show resolved
Hide resolved
...android/library-compose/src/main/java/io/element/android/wysiwyg/compose/EditorStyledText.kt
Outdated
Show resolved
Hide resolved
...s/android/library-compose/src/main/java/io/element/android/wysiwyg/compose/RichTextEditor.kt
Outdated
Show resolved
Hide resolved
...s/android/library-compose/src/main/java/io/element/android/wysiwyg/compose/RichTextEditor.kt
Outdated
Show resolved
Hide resolved
platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorEditText.kt
Outdated
Show resolved
Hide resolved
platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorStyledTextView.kt
Outdated
Show resolved
Hide resolved
platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorStyledTextView.kt
Outdated
Show resolved
Hide resolved
...droid/library/src/main/java/io/element/android/wysiwyg/internal/viewmodel/EditorViewModel.kt
Outdated
Show resolved
Hide resolved
platforms/android/library/src/main/java/io/element/android/wysiwyg/utils/HtmlToSpansParser.kt
Outdated
Show resolved
Hide resolved
Yeah indeed, I think there must be a caching issue because the tests seem to pass fairly reliably on the second CI run. |
return resolveRoomMentionDisplay?.invoke() ?: TextDisplay.Plain | ||
} | ||
|
||
}, update = remember(style, typeface, mentionDisplayHandler) { |
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.
This workaround seems to work, thank you! Please could you add some comments to explain the problem and why this is needed? I've created an issue to link to as well #856. Please feel free to add more detail that could help us in future.
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.
(friendly reminder to please link to the issue in the code comments)
}, update = remember(style != previousStyle, typeface, mentionDisplayHandler, text) { | ||
{ view -> | ||
if (style != previousStyle) { | ||
view.styleConfig = style.toStyleConfig(view.context) | ||
view.applyStyleInCompose(style) | ||
previousStyle = style | ||
} |
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.
Same as above, thanks for the workaround! Please could you add some comments explaining the problem and why this is needed, linking to the GH issue?
...android/library-compose/src/main/java/io/element/android/wysiwyg/compose/EditorStyledText.kt
Outdated
Show resolved
Hide resolved
Also, unify setting the `StyleConfig` and `MentionDisplayHandler` with a new `setupHtmlConverter` method.
…del` when trying to generate a spanned text from HTML
All mentioned issues should have been fixed. |
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.
Thanks for the changes! I have a few more comments as there are quite a few more changes. I've made a few suggestions - Ii'd be great to address the public API issues to minimise breaking changes that we'd need to release in order to fix them.
...s/android/library-compose/src/main/java/io/element/android/wysiwyg/compose/RichTextEditor.kt
Outdated
Show resolved
Hide resolved
...oid/example-compose/src/main/java/io/element/wysiwyg/compose/DefaultMentionDisplayHandler.kt
Outdated
Show resolved
Hide resolved
...s/android/library-compose/src/main/java/io/element/android/wysiwyg/compose/RichTextEditor.kt
Outdated
Show resolved
Hide resolved
...rary-compose/src/main/java/io/element/android/wysiwyg/compose/internal/FakeViewConnection.kt
Outdated
Show resolved
Hide resolved
platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorEditText.kt
Outdated
Show resolved
Hide resolved
platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorEditText.kt
Outdated
Show resolved
Hide resolved
platforms/android/library/src/main/java/io/element/android/wysiwyg/EditorStyledTextView.kt
Outdated
Show resolved
Hide resolved
platforms/android/library/src/main/java/io/element/android/wysiwyg/utils/HtmlToSpansParser.kt
Outdated
Show resolved
Hide resolved
…ionText` or `ViewAction.InsertMentionAtSuggestion` are used in `FakeViewConnection`.
…n `@mentionText` or a proper link.
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.
There are some mentions related tests failing when I run them locally - please can you fix those?
After that I think we are OK to merge this in its current state and unblock the work on mentions.
I think the last issues should have been fixed in ac1c05f (it seems like when I paused this work I forgot to migrate the mention detection logic). The tests work locally for me with those changes, but I can't make them work in the CI. |
Kudos, SonarCloud Quality Gate passed! |
Thanks again for the latest changes, I was over complicating things quite a bit 😅 . Should this be ready to merge now? |
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.
Nice work, let's keep an eye out for any issues around #856
Expose
replaceSuggestion
andsetLinkSuggestion
insertMentionAtSuggestion
inRichTextEditorState
. Also add suggestions UI to the compose example.Also added
MentionDetector
to replace the client-side parsing of mentions with something from the RTE library.