Thread
#compose
    Muhammad Zaryab Rafique

    Muhammad Zaryab Rafique

    1 year ago
    Hey Devs, how to recompose function after every ten seconds. Kindly guide me.
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    Recomposition in itself should be a noop unless something changed, since it should not contain side effects directly. Why do you want to force recomposition?
    Adam Powell

    Adam Powell

    1 year ago
    right, recomposition is a means, not an end
    Muhammad Zaryab Rafique

    Muhammad Zaryab Rafique

    1 year ago
    Because, my app use five types of theming. I calculate some function to switch theme based on time. I want to call this function after every time 10 second because when we open app and time changes and no theme switch, we will kill the app and run app again to calculate time.
    Adam Powell

    Adam Powell

    1 year ago
    store the current theme in a
    mutableStateOf
    , then change its value whenever is appropriate. Read the theme's value from that state object in your composition where you need it. Recomposition will naturally follow.
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    Eg You could use a loop and a delay in a coroutine (maybe using LaunchedEffect).
    Muhammad Zaryab Rafique

    Muhammad Zaryab Rafique

    1 year ago
    Lets try, Thanks All Devs for your guidance. @Zach Klippenstein (he/him) [MOD] @Adam Powell
    Colton Idle

    Colton Idle

    1 year ago
    Yeah. I was going to say that I don't think this has anything to do with compose. Just keep the current theme as some app state, and then whatever triggers that to change, a timer, a network call, a button press (whatever you want), then you update that app state, and a composable will just work ™️