Is there an idiomatic way to have derivedStateOf to return current content and do not update the cal...
t
Is there an idiomatic way to have derivedStateOf to return current content and do not update the calculation based on some flag? For example given
val playlistItems by remember { derivedStateOf { playlistContent.toMutableList() } }
I'd like to ignore playlistContent changes in some cases. I can use another variable to store a copy of the actual value and return it, but I wonder if there's something more integrated.
a
Why do you want this? It sounds like there's probably a smoother way to accomplish the end result you're looking for.
t
The playlist content is a stateflow pushed from whatever renderer currently connected to. That playlist can be reordered, hence the derivated mutable list. During the drag and drop to avoid issues and wrong drops we do not want the state to update the mutable list
This is the same kind of issues with Slider and state flow we need to interrupt the update from the source and use the dragging position during the user drag.
Sliders end up with things like :
Copy code
var currentSliderPosition by remember { mutableStateOf(0f) }
        val source = remember { MutableInteractionSource() }
        val clicks by source.collectIsDraggedAsState()
        Slider(
            value = if (clicks) currentSliderPosition else currentPercentage.coerceIn(0.0, 1.0).toFloat(),
            onValueChange = {
                currentSliderPosition = it
            },
            onValueChangeFinished = {
                onSeek(currentSliderPosition)
            },
            interactionSource = source,
            modifier = Modifier
                .padding(horizontal = 8.dp)
                .weight(1f)
        )
Not very intuitive either.
So wondering if there's a cleaner way to do that for the playlist side (and eventually the slider if there's something obvious I missed)
@Adam Powell So am I missing something obvious about state handling? I'm still at the design experiment phase so any hints are greatly appreciated.