https://kotlinlang.org logo
#compose-android
Title
# compose-android
k

KotlinLeaner

02/26/2024, 10:58 AM
Hey guys, How to replace multiple lambda () -> Unit in a composable in Jetpack compose android
Copy code
@Composable fun ChatMessageDisplay (
    authorName: String,
    author ImageUrl: String,
    dateSent: String,
    messages: List<Content>,
    likeCounts: List<Int>,
    onLikeClick: (Int) -> Unit,
    onMessageClick: (Int) -> Unit,
    onMessageLongClick: (Int) -> Unit,
    onUserPhotoClick: () -> Unit,
    onVisibleOnScreen: (Int) -> Unit,
    onShareClick: (Int) -> Unit,
    onEditClick: (Int) -> Unit,
    )
I have above composable Which requires multiple lambda () -> Unit how can we replace them with a single lambda () -> Unit or any simple method to reduce multiple lambda () -> Units
c

curioustechizen

02/26/2024, 11:02 AM
See discussion here: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1691125765234639 The solutions offered have their pros and cons so see what applies to your situation.
🌟 1
k

KotlinLeaner

02/26/2024, 3:20 PM
Thanks for sharing information regarding to use sealed interface in top level composables. I got the point in here. I have another doubt regarding Stability in Compose. I was reading in stack overflow question that interface and classes are unstable. Does sealed interface is also unstable? Do I need to add annotation on there? I am new in sealed interface so I don't know. Thanks
b

Ben Trengrove [G]

02/27/2024, 2:09 AM
Your composable would already be not skippable because of using List
I think you might have misunderstood that stack overflow question as well. Interfaces and classes are unstable based on their contents, or if they come from a module where the compose compiler hasn't been run. A sealed interface is no different
I wouldn't worry about this, we are currently testing strong skipping mode which will make composables with unstable parameters able to be skipped as well. More details here https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/compiler/design/strong-skipping.md
k

KotlinLeaner

02/27/2024, 8:57 AM
Okk now got it. Thanks for clarification
5 Views