JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.92k stars 1.16k forks source link

Bad recomposition after upgrade 1.5.12 -> 1.6.0 #4547

Closed Lukaszz112 closed 5 months ago

Lukaszz112 commented 5 months ago

After compose upgrade from 1.5.12 to 1.6.0 my iOS screens are not recomposing correctly.

Versions

To Reproduce iOS Code snippet:

struct ContactView {
  @State var isGoingToSubjectSearchView = false
  @Environment(\.presentationMode) private var presentationMode
}
extension ContactView: View {
  var body: some View {
    VStack {
      ComposeViewControllerToSwiftUI(factory: ContactUiViewControllerKt
        .ContactUiViewController(
          navigateBackAction: {
            presentationMode.wrappedValue.dismiss()
          },
          navigateToTopicSearchAction: {
            isGoingToSubjectSearchView = true
          }
        )
      )
    }.navigationBarBackButtonHidden(true)
      .ignoresSafeArea(.all, edges: .bottom)
    NavigationLink(isActive: $isGoingToSubjectSearchView) {
      ContactSubjectSearchView()
    } label: {
      EmptyView()
    }
  }
}
struct ContactSubjectSearchView {
    @Environment(\.presentationMode) private var presentationMode
}
extension ContactSubjectSearchView: View {
    var body: some View {
        VStack {
            ComposeViewControllerToSwiftUI(factory: ContactSearchSubjectUiViewControllerKt
                .ContactSearchSubjectUiViewController(
                    navigateBackAction: {
                        presentationMode.wrappedValue.dismiss()
                    }
                )
            )
        }.navigationBarBackButtonHidden(true)
    }
}
struct ComposeViewControllerToSwiftUI: UIViewControllerRepresentable {
    let factory: UIViewController
    func makeUIViewController(context: Context) -> UIViewController {
        factory
    }
    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
    }
}

Kotlin code:

fun ContactUiViewController(
    navigateBackAction: () -> Unit,
    navigateToSubjectSearchAction: () -> Unit
): UIViewController = ComposeUIViewController {
    println("hello ComposeUIViewController")
    CompositionLocalProvider(LocalAppDimensions provides phoneDimens) {
        println("hello provider")
        MyTheme {
            println("hello theme")
            UserProfileContactScreen(
                viewModel = getViewModel { getUserProfileContactViewModeliOSExt() },
                navigateToSubjectSearchAction = navigateToSubjectSearchAction,
                onBackAction = navigateBackAction,
            )
            println("hello Done")
        }
    }
}

Expected behavior Screens are recomposing correctly

Video below

https://github.com/JetBrains/compose-multiplatform/assets/93291505/40972827-c364-44bf-b2d8-f43ff5f96428

elijah-semyonov commented 5 months ago

@Lukaszz112 Hi, thanks for the report. I struggle to recognise the problem. What did you specifically expect to happen, recomposition on navigating back to the second ViewController?

Lukaszz112 commented 5 months ago

@elijah-semyonov I want to relaunch ViewController. There are some logs, look on thier behavior. After navigating back to the previous viewController its not recomposing, and viewModel onStart method isnt called. It was working on 1.5.12

elijah-semyonov commented 5 months ago

It was a bug of 1.5.12, it was not supposed to recompose, the state didn't change. If you need to perform some logic on appearance of ComposeUIViewController, check the ComposeUIViewControllerDelegate API

Lukaszz112 commented 5 months ago

okay thanks ill check

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.