Hey guys, How to replace multiple lambda () -> ...
# compose-android
k
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
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
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
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
Okk now got it. Thanks for clarification