Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

[Android] Add releaseOnDetach parameter to EditorStyledText #914

Merged
merged 3 commits into from
Dec 28, 2023

Conversation

jmartinesp
Copy link
Contributor

@jmartinesp jmartinesp commented Dec 27, 2023

Adds a releaseOnDetach parameter so the view can be reused in Lazy composables when it's set to false.

@jmartinesp jmartinesp requested a review from a team December 27, 2023 08:37
@jmartinesp jmartinesp mentioned this pull request Dec 27, 2023
@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e9e9048) 87.47% compared to head (d8e7540) 89.43%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #914      +/-   ##
============================================
+ Coverage     87.47%   89.43%   +1.95%     
============================================
  Files           166       86      -80     
  Lines         19006    15358    -3648     
  Branches       1032        0    -1032     
============================================
- Hits          16625    13735    -2890     
+ Misses         2078     1623     -455     
+ Partials        303        0     -303     
Flag Coverage Δ
uitests ?
uitests-android ?
uitests-ios ?
unittests 89.43% <ø> (+3.88%) ⬆️
unittests-android ?
unittests-ios ?
unittests-rust 89.43% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@@ -27,6 +27,8 @@ import io.element.android.wysiwyg.display.TextDisplay
* @param resolveMentionDisplay A function to resolve the [TextDisplay] of a mention.
* @param resolveRoomMentionDisplay A function to resolve the [TextDisplay] of an `@room` mention.
* @param style The styles to use for any customisable elements.
* @param releaseOnDetach Whether to release the view when the composable is detached from the composition or not.
* Setting this to `false` is specially useful in Lazy composables that need to reuse these views. Defaults to `true`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reading the documentation of AndroidView.onReset:

onReset - A callback invoked as a signal that the view is about to be attached to the composition hierarchy in a different context than its original creation. This callback is invoked before update and should prepare the view for general reuse. If null or not specified, the AndroidView instance will not support reuse, and the View instance will always be discarded whenever the AndroidView is moved or removed from the composition hierarchy.

So I understand that passing true for releaseOnDetach will allow the re-usage of the View, which is the opposite of the documentation here, and the description of the PR. Maybe I miss something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks for double checking! I'll upload a fix.

},
onReset = { view: EditorStyledTextView ->
view.setText("", TextView.BufferType.SPANNABLE)
}.takeIf { releaseOnDetach },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe you want to use takeUnless here?

@jmartinesp jmartinesp requested a review from bmarty December 28, 2023 13:20
Copy link
Contributor

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jmartinesp jmartinesp enabled auto-merge (squash) December 28, 2023 13:23
@jmartinesp jmartinesp merged commit 734dd4c into main Dec 28, 2023
4 of 5 checks passed
@jmartinesp jmartinesp deleted the fix/jme/make-editorstyledtext-reusable branch December 28, 2023 14:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants