Giter VIP home page Giter VIP logo

Comments (2)

FelixSubject211 avatar FelixSubject211 commented on May 24, 2024

I found a solution. It may well be that this isn't a bug at all. If so, I'm very sorry for the disruption!

You have to use the updateUIViewController in the calling UIViewControllerRepresentable.

I did it like this:

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
        let newViewController = SelectAppointmentViewControllerKt.SelectAppointmentViewController(
            bookAppointmentScreenModel: bookAppointmentScreenModel,
            appointmentBody: appointmentBody
        )
        
        uiViewController.willMove(toParent: nil)
        uiViewController.view.removeFromSuperview()
        uiViewController.removeFromParent()
        
        uiViewController.addChild(newViewController)
        newViewController.view.frame = uiViewController.view.frame
        uiViewController.view.addSubview(newViewController.view)
        newViewController.didMove(toParent: uiViewController)
 }

Felt a bit hacky but it worked

from compose-multiplatform.

elijah-semyonov avatar elijah-semyonov commented on May 24, 2024

Sorry, I'm not exactly following what you are trying to achieve.
Can you create a repro and describe what is the expected behavior?

There is too much information missing.
Your updateUIViewController will recreate SelectAppointmentViewControllerKt.SelectAppointmentViewController every time the value of UIViewControllerRepresentable structure changes, which I don't think is something desired.
Plus creating a UIViewController inside a UIViewControllerRepresentable context is a bit novel?
Why not just use another UIViewControllerRepresentable?

The problem occurs as soon as I call the SelectAppointmentCompose via the SelectAppointmentViewController in SwiftUI.

This function creates a new UIViewController, that draws Composable content inside. In your case the Composable content is SelectAppointmentCompose(bookAppointmentScreenModel, appointmentBody). It will recalculate itself using the rules of Compose whenever values that affect the compose and are coming from bookAppointmentScreenModel and appointmentBody change (and the implementation actually reads or writes it). The state in there must be represented as compose.runtime.State (using mutableStateOf APIs and similar) otherwise Compose will not see them changing and hence won't be reacting.

Then the compose is not redrawn with new calls, although SelectAppointmentViewController is called with new parameters

It's not exactly clear what's happening in here. Do you mean, that parameters used by UIViewControllerRepresentable structure changed, but the ComposeUIViewController did not redraw? SwiftUI will try not to call makeUIViewController of UIViewControllerRepresentable unless it indeeds needs to make a new one and will only call updateUIViewController so you can update your data. In your case models should be created on Kotlin side and changed from within this callback, this way Compose will see the change in State and redraw accordingly.

from compose-multiplatform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.