Skip to content

Commit f74b853

Browse files
committed
fix: CircularButton.kt stability
use stable lambda instead of direct painter
1 parent 84dd73f commit f74b853

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

composeApp/src/commonMain/kotlin/components/CircularButton.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ import androidx.compose.ui.graphics.painter.Painter
1515
import androidx.compose.ui.unit.dp
1616

1717
@Composable
18-
internal fun CircularButton(image: Painter, onClick: () -> Unit) {
18+
internal fun CircularButton(
19+
modifier: Modifier = Modifier,
20+
painterProvider: @Composable () -> Painter,
21+
onClick: () -> Unit,
22+
) {
1923
Box(
20-
Modifier.size(40.dp).clip(CircleShape).background(Color(25, 25, 28, 180))
24+
modifier
25+
.size(40.dp)
26+
.clip(CircleShape)
27+
.background(Color(25, 25, 28, 180))
2128
.clickable { onClick() }, contentAlignment = Alignment.Center
2229
) {
2330
Image(
24-
image,
31+
painter = painterProvider(),
2532
contentDescription = null,
2633
modifier = Modifier.size(20.dp)
2734
)

composeApp/src/commonMain/kotlin/pages/Components.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ fun Components() {
5454
title = "Icon buttons",
5555
description = "Behold the mystical prowess of icon buttons, granting individuals the power to enact minor wonders with a mere touch – a spellbinding experience at the tip of your fingers."
5656
) {
57-
CircularButton(painterResource(Res.drawable.magic)) { }
58-
CircularButton(painterResource(Res.drawable.plus)) { }
57+
CircularButton(painterProvider = { painterResource(Res.drawable.magic) }) { }
58+
CircularButton(painterProvider = { painterResource(Res.drawable.plus) }) { }
5959
}
6060
ComponentsBlock(
6161
title = "Chips",

0 commit comments

Comments
 (0)