Jonathan
05/09/2025, 1:14 PMCanvas {}
to draw a custom graph and I’d like to report the trig values (sin
, cos
, tan
, theta
) at which the graph was last interacted to calling code. My concern is invoking the callback to often even when the angle hasn’t changed (I do some rounding so tiny changes won’t be reflected). Is this a better use for custom state class to hold the values?Timo Drick
05/09/2025, 1:18 PMJonathan
05/09/2025, 1:19 PMTimo Drick
05/09/2025, 1:24 PMclass TouchState(initial: Int) {
var value: Int by mutableIntStateOf(initial)
private set
}
You can create an instance of this in the parent composable or in your viewmodel.
If you want to do it in the compose code make sure to use remember:
@Composable
fun rememberTouchState(initial: Int = 0): TouchState {
return remember {
TouchState(initial = initial)
}
}
Jonathan
05/09/2025, 1:25 PMJonathan
05/09/2025, 1:27 PMJonathan
05/09/2025, 1:29 PMTimo Drick
05/09/2025, 1:29 PMTimo Drick
05/09/2025, 1:30 PMTimo Drick
05/09/2025, 1:30 PMJonathan
05/09/2025, 1:31 PMTimo Drick
05/09/2025, 1:31 PMTimo Drick
05/09/2025, 1:32 PMTimo Drick
05/09/2025, 1:33 PMJonathan
05/09/2025, 1:36 PMTimo Drick
05/09/2025, 1:37 PMJonathan
05/09/2025, 1:37 PMTimo Drick
05/09/2025, 1:38 PMTimo Drick
05/09/2025, 1:38 PMJonathan
05/09/2025, 1:38 PMTimo Drick
05/09/2025, 1:44 PMJonathan
05/09/2025, 1:44 PMTimo Drick
05/09/2025, 1:49 PMclass TouchState() {
var value = mutableStateListOf<Int>()
}
Of ocurse instead of int you could use a custom data class with all your parametersTimo Drick
05/09/2025, 1:49 PMTimo Drick
05/09/2025, 1:50 PMTimo Drick
05/09/2025, 1:52 PMJonathan
05/09/2025, 1:53 PMTimo Drick
05/09/2025, 1:53 PMTimo Drick
05/09/2025, 1:53 PMJonathan
05/09/2025, 1:53 PMJonathan
05/09/2025, 1:54 PMTimo Drick
05/09/2025, 1:55 PMJonathan
05/09/2025, 1:55 PMTimo Drick
05/09/2025, 1:56 PM