https://kotlinlang.org logo
#compose
Title
# compose
v

vide

10/16/2023, 3:50 PM
Is there a performance difference here? Should I always prefer the latter?
Copy code
fun Modifier.foo() = composed { this.then(FooElement(remember { Foo() })) }
Composable(Modifier.foo())

fun Modifier.foo(foo: Foo) = this.then(FooElement(foo))
Composable(Modifier.foo(remember { Foo() }))
z

Zach Klippenstein (he/him) [MOD]

10/16/2023, 4:35 PM
composed is generally bad for performance, yes. The new modifier node APIs are better to use (and also for other reasons)
v

vide

10/16/2023, 5:09 PM
That's what I thought, thanks for confirming. The API surface here is a bit clunky for the user, as they need to remember a value that the modifier only uses internally. Has there been any thought about how to do this in a cleaner way? (In this case
foo
is a BringIntoViewRequester --I cannot delegate to the node implementation because it's private)
z

Zach Klippenstein (he/him) [MOD]

10/16/2023, 6:43 PM
Does the caller of the modifier factory need to be able to call bringIntoView? If so, there’s no way to get around them creating it, since they need access to it. If not, just have your modifier node implement BringIntoViewRequesterNode
v

vide

10/16/2023, 9:43 PM
Nope, the parent doesn't need access to it. The issue here again is that
BringIntoViewRequesterNode
is currently internal, I'll try to push for that being publicised too
z

Zach Klippenstein (he/him) [MOD]

10/17/2023, 1:43 AM
Oh right. It needs a bit of refactoring but I’m pretty sure we can fix that