@@ -28,7 +28,9 @@ import androidx.compose.material3.Scaffold
2828import androidx.compose.material3.Text
2929import androidx.compose.material3.TopAppBar
3030import androidx.compose.runtime.Composable
31+ import androidx.compose.runtime.getValue
3132import androidx.compose.runtime.remember
33+ import androidx.compose.runtime.rememberUpdatedState
3234import androidx.compose.ui.Modifier
3335import androidx.compose.ui.graphics.painter.Painter
3436import androidx.compose.ui.hapticfeedback.HapticFeedbackType
@@ -37,6 +39,8 @@ import androidx.compose.ui.res.painterResource
3739import androidx.compose.ui.res.stringResource
3840import androidx.compose.ui.text.AnnotatedString
3941import androidx.compose.ui.text.style.TextOverflow
42+ import kotlinx.collections.immutable.ImmutableList
43+ import kotlinx.collections.immutable.persistentListOf
4044import org.librefit.R
4145
4246
@@ -72,11 +76,11 @@ import org.librefit.R
7276fun LibreFitScaffold (
7377 title : AnnotatedString ? = null,
7478 navigateBack : (() -> Unit )? = null,
75- actions : List <() -> Unit > = listOf (),
76- actionsEnabled : List <Boolean > = listOf (),
77- actionsDescription : List <String ?> = listOf (),
78- actionsIcons : List <Painter > = listOf (),
79- actionsElevated : List <Boolean > = listOf (),
79+ actions : ImmutableList <() -> Unit > = persistentListOf (),
80+ actionsEnabled : ImmutableList <Boolean > = persistentListOf (),
81+ actionsDescription : ImmutableList <String ?> = persistentListOf (),
82+ actionsIcons : ImmutableList <Painter > = persistentListOf (),
83+ actionsElevated : ImmutableList <Boolean > = persistentListOf (),
8084 fabAction : (() -> Unit )? = null,
8185 fabIcon : Painter ? = null,
8286 fabDescription : String? = null,
@@ -115,7 +119,7 @@ fun LibreFitScaffold(
115119 val haptic = LocalHapticFeedback .current
116120
117121 val interactionSources =
118- remember(actions.size ) { List (actions.size) { MutableInteractionSource () } }
122+ remember(actions) { List (actions.size) { MutableInteractionSource () } }
119123 ButtonGroup (
120124 overflowIndicator = {},
121125 ) {
@@ -130,14 +134,15 @@ fun LibreFitScaffold(
130134
131135 customItem(
132136 buttonGroupContent = {
137+ val currentAction by rememberUpdatedState(action)
133138 if (icon != null ) {
134139 IconButton (
135140 modifier = interactionSources.getOrNull(index)
136141 ?.let { Modifier .animateWidth(it) }
137142 ? : Modifier ,
138143 onClick = {
139144 haptic.performHapticFeedback(HapticFeedbackType .ContextClick )
140- action ()
145+ currentAction ()
141146 },
142147 shapes = IconButtonDefaults .shapes(),
143148 interactionSource = interactionSources.getOrNull(
@@ -161,7 +166,7 @@ fun LibreFitScaffold(
161166 ? : Modifier ,
162167 onClick = {
163168 haptic.performHapticFeedback(HapticFeedbackType .ContextClick )
164- action ()
169+ currentAction ()
165170 },
166171 shapes = ButtonDefaults .shapes(),
167172 interactionSource = interactionSources.getOrNull(
0 commit comments