https://kotlinlang.org logo
#compose-ios
Title
# compose-ios
ł

Łukasz Lendzion

03/25/2024, 1:31 PM
Hello, after upgrade compose from 1.5.12 -> 1.6.0 my ios screens are not recomposing correctly. jetbrains compose: 1.6.0 compose: 1.6.3 kotlin: 1.9.21
🧵 1
iOS Code snippet:
Copy code
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()
    }
  }
}
Copy code
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)
    }
}
Copy code
struct ComposeViewControllerToSwiftUI: UIViewControllerRepresentable {
    let factory: UIViewController
    func makeUIViewController(context: Context) -> UIViewController {
        factory
    }
    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
    }
}
Kotlin code:
Copy 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")
        }
    }
}
3 Views