nglauber / JetpackComposePlayground

41 stars 5 forks source link

Have you tried to make the speedometer live? #3

Closed 4rzumanyan closed 2 years ago

4rzumanyan commented 2 years ago

Is it possible to make the speedometer work more than once, but when the state changes, like a real car speedometer?

nglauber commented 2 years ago

@4rzumanyan if you do the change below, the speedometer will react in according to the Slider.

@Composable
fun SpeedometerScreen() {
    var targetValue by remember {
        mutableStateOf(0f)
    }
    val speed by remember {
        derivedStateOf {
            (targetValue * 55).toInt()
        }
    }
    //...
    Speedometer(speed) // << use the new state
} 
4rzumanyan commented 2 years ago

Thank you @nglauber, I already did that using "animateFloatAsState."