-
Notifications
You must be signed in to change notification settings - Fork 26
[Android] Add releaseOnDetach
parameter to EditorStyledText
#914
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
@@ -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`. |
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 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?
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.
You're right, thanks for double checking! I'll upload a fix.
}, | ||
onReset = { view: EditorStyledTextView -> | ||
view.setText("", TextView.BufferType.SPANNABLE) | ||
}.takeIf { releaseOnDetach }, |
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.
Or maybe you want to use takeUnless
here?
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.
👍
Adds a
releaseOnDetach
parameter so the view can be reused in Lazy composables when it's set tofalse
.