Search code examples
compose-multiplatform

How to force redrawing on recomposition on iOS?


I have a compose screen inside a UIViewControllerRepresentable inside a swiftui TabView, my screen has a state which I update from a different swiftui screen and then navigate back into this screen, I'm tracing recompositions and I can see that my composable is recomposed but its not actually rendered on the iphone screen until I touch the screen,

I'm vaguely aware of the mechanism in compose used to pause and unpause the redrawing on iOS, and it's by design that when the user touches the screen then the process is unpaused, which is exactly what's happening,

Does multiplatform compose have an api to "force unpause" the redrawing?

Here's reproducible code: https://github.com/curliq/kmp-compose-redraw-bug


Solution

  • This can be fixed by forcing the swiftui view to redraw, for example like this:

    @State private var refreshID = UUID()
    ...
    
    NavigationStack() {
        VStack {
            ComposeView(vm: vm)
                .id(refreshID)
                .onAppear {
                    refreshID = UUID()
                }
        }
    }