KotlinLeaner
01/31/2024, 7:12 PMKotlinLeaner
01/31/2024, 7:23 PMMyComposableCallback {
fun onEventOccurred(data: String)
}
@Composable
fun MyComposable(callback: MyComposableCallback) {
// Composable implementation
}
// Usage
val myCallback = object : MyComposableCallback {
override fun onEventOccurred(data: String) {
// Handle event
}
}
MyComposable(callback = myCallback)
As opposed to the more conventional lambda approach:
@Composable
fun MyComposable(onEventOccurred: (String) -> Unit) {
// Composable implementation
}
// Usage
MyComposable { data ->
// Handle event
}
Any insights on the pros and cons of each approach in terms of performance, readability, and adherence to Compose principles would be greatly appreciated.p-schneider
01/31/2024, 7:46 PMfun interface
-> https://kotlinlang.org/docs/fun-interfaces.html ?
I think this would allow you to have an additional variant to the two approaches you mentioned above.KotlinLeaner
01/31/2024, 10:53 PMfun interface.
Actually I prefer to use lambda but some of my friends are saying we don't need to pass the lambda function we can use the interface. So I just want pros and cons using the interface.Arjun Achatz
02/01/2024, 9:33 PMKotlinLeaner
02/01/2024, 9:57 PM