Travis Griggs
10/11/2023, 9:01 PMremember { mutableStateOf() }
thing. For example, in one place I have a var visibleInterval by remember { mutableStateOf<ClosedRange<Duration>> }
and in another a var selections by remember { mutableStateOf<Set<Int>>(emptySet()) }
. Are either of these expressions problem prone?Ben Trengrove [G]
10/11/2023, 9:12 PMTravis Griggs
10/11/2023, 9:42 PMvar selections by remember { mutableStateOf<Set<Int>>(emptySet()) }
// LaunchedEffect(selections) {
// selections.logged("SELECTIONS CHANGED")
// }
SpansView(
plan = PlansRepo.rapidPrecisionPlan(),
selectAction = { op, arg -> selections = op.update(selections, arg) },
selections = selections,
modifier = Modifier.fillMaxSize()
)
}
As soon as that selectAction fires, the SpansView starts repeatedly composing. But the selectAction itself is not repeteadly firing.Pablichjenkov
10/11/2023, 9:42 PMTravis Griggs
10/11/2023, 9:46 PMPablichjenkov
10/11/2023, 9:48 PMBen Trengrove [G]
10/11/2023, 9:49 PMPablichjenkov
10/11/2023, 9:50 PMTravis Griggs
10/11/2023, 9:54 PMPablichjenkov
10/11/2023, 10:19 PMTravis Griggs
10/11/2023, 10:20 PMprivate fun SpanViewPreview() {
val plan = PlansRepo.rapidPrecisionPlan()
Box(modifier = Modifier.fillMaxSize()) {
var selections by remember { mutableStateOf<Set<Int>>(emptySet()) }
SpansView(
plan = plan,
selectAction = { op, arg -> selections = op.update(selections, arg) },
selections = selections,
modifier = Modifier.fillMaxSize()
)
}
}
but alas, this had no effect. Then, I remembered that Box is an inline function, so no real no composition nesting is actually happening there. So changing it to
private fun SpanViewPreview() {
val plan = PlansRepo.rapidPrecisionPlan()
Surface(modifier = Modifier.fillMaxSize()) {
var selections by remember { mutableStateOf<Set<Int>>(emptySet()) }
SpansView(
plan = plan,
selectAction = { op, arg -> selections = op.update(selections, arg) },
selections = selections,
modifier = Modifier.fillMaxSize()
)
}
}
suddenly works. Because, for the time being, apparently, Surface is not an inline function for its content.Pablichjenkov
10/11/2023, 10:23 PMTravis Griggs
10/11/2023, 10:27 PMPablichjenkov
10/11/2023, 10:50 PMBen Trengrove [G]
10/12/2023, 1:03 AM