Repository navigation
Recommended Compose way to have multiple Balloons #491
Replies: 2 comments
|
The idiomatic Compose approach is to avoid Instead, hoist the Why For a walkthrough / onboarding sequence where balloons fire one-after-another, store the windows in a |
|
For anyone implementing this with Balloon 2.x, the API now lets the parent own both states directly, so you do not need to capture @Composable
fun TwoTips() {
val style = rememberBalloonBuilder {
setPadding(12.dp)
setBackgroundColor(Color(0xFF785EF0))
}
val first = rememberBalloonState(style)
val second = rememberBalloonState(style)
Column {
Balloon(
state = first,
balloonContent = { Text("Edit your profile", color = Color.White) },
) {
Button(onClick = {
second.dismiss()
first.showAlignTop()
}) { Text("First") }
}
Balloon(
state = second,
balloonContent = { Text("Another tip", color = Color.White) },
) {
Button(onClick = {
first.dismiss()
second.showAlignTop()
}) { Text("Second") }
}
}
}The Balloon imports in 2.x are from For an automatic sequence, the documented suspending calls wait for dismissal before continuing: LaunchedEffect(Unit) {
first.awaitAlignTop()
second.awaitAlignBottom()
}Place that effect at the parent level while both anchors are composed. Use a separate “tour started” key if the sequence should start from a user action. As with any Your original snippet uses the 1.x callback API; the example above requires migrating rather than mixing the two APIs. The migration guide and current README document the parent-owned state and await methods. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello Balloon community!
Loving this library so far, that said I have a question. What would be the recommended idiomatic Compose way to have multiple Balloons?
For example I can capture balloonWindow to a variable like this with lateinit var bw:
But I'm not sure if this is recommended. Would appreciate opinions on this :)
All reactions