Saturday, 6 August 2022

What are differents between Composable function and normal function in Android?

I have read the official document about Composable functions

But I can't understand Composable functions.
For example, rememberWatchState() is a Composable function in Code A, but it doesn't define my app's UI just like a normal function.

What is the difference between the Composable function and the normal function in Android?

Code A

@Composable
fun ScreenHome_Watch(
    watchState:WatchState =  rememberWatchState()
){
    val density= watchState.density
}


@Composable
fun rememberWatchState(): WatchState {
    val context: Context = LocalContext.current
    val temp = loadDBWarningValueWithPreference(context)

    val watchState = WatchState(temp.toFloat(),LocalDensity.current)

    return remember {
        watchState    
    }
}

class WatchState(
    private val alarmValue:Float,
    val density: Density
){
    ...
}


fun drawDial(
    drawScope: DrawScope,
    watchState:WatchState
) {
   ...
}


from What are differents between Composable function and normal function in Android?

No comments:

Post a Comment