vide
09/12/2023, 3:30 AMModifier.Node
? I have a custom modifier that is currently using composed
, it remembers a few values and reads some composition locals and applies some other compose-provided modifiers that are already implemented with Modifier.Node. Would it make any sense to migrate this modifier from composed to Modifier.Node, or would any performance benefits be negligible?Ben Trengrove [G]
09/12/2023, 3:46 AMvide
09/12/2023, 5:32 AMclickable
still uses this pattern to remember MutableInteractionSources, for example. Is there some way this could be optimized even further? Remember the value in the composable using the modifier?
composed {
val br = remember { BringIntoViewRequester() }
this.bringIntoViewRequester(br) then MyCustomElement(arg1, arg2, br, ...)
}
Ben Trengrove [G]
09/12/2023, 6:24 AMbr
?vide
09/12/2023, 6:25 AMvide
09/12/2023, 6:26 AMBen Trengrove [G]
09/12/2023, 6:26 AMvide
09/12/2023, 6:26 AMBen Trengrove [G]
09/12/2023, 6:50 AMAlbert Chang
09/12/2023, 7:55 AMremember
at all because the Modifier.Node
instance will never be recreated so the values you had to remember can just be the members of the class.
However, in this specific case, since the APIs behind Modifier.bringIntoViewRequester()
are all private or internal, I don't think you can create a custom Modifier.Node
with the functionality of Modifier.bringIntoViewRequester()
yet.Zach Klippenstein (he/him) [MOD]
09/12/2023, 3:30 PMvide
09/12/2023, 3:35 PMZach Klippenstein (he/him) [MOD]
09/12/2023, 3:41 PMvide
09/12/2023, 3:52 PMBen Trengrove [G]
09/14/2023, 1:09 AMDelegatingNode()
. There are lots of samples of it in https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]mpose/ui/samples/ModifierSamples.kt
It would end up looking something like (if we actually had a public implementation you could use)
class MyModifierNode: DelegatingNode() {
val br = BringIntoViewRequester()
val bringIntoViewNode = delegate(BringIntoViewModifierNode(br))
// other custom behaviour here
}