Comments (2)
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.
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)
- Compose 1.6.2 iOS ComposeContainer memory leak HOT 2
- TextField cannot input in ExposedDropdownMenuBox, when ExposedDropdownMenu is expanded HOT 4
- 🚀 Low-code tools to speed up and ease app development HOT 1
- java.lang.SecurityException: SHA-256 digest error for org/bouncycastle/operator/OperatorCreationException.class HOT 3
- [IOS-Simulator] TextField Text Cursor Jumps Around After Using CMD+A then Delete to clear all text preventing further text input.
- Using `ComposeScene`s with anything but `MainUIDispatcher` results in a deadlock HOT 19
- Generate XCFramework with UI, resources and dependencies HOT 2
- Remove compose ui fallback from LocalViewModelStoreOwner HOT 3
- Kotlin/Wasm responsive layout HOT 7
- Support text hyphenation HOT 1
- How to monitor finger position like touch_down\touch_move on Android platform?
- Brush.linearGradient don't work HOT 1
- Order of accessibility nodes is wrong HOT 1
- When targeting Android for a KMP project using `Coil 3.0.0-alpha06`, attempting to use `.toBitmap()` and `.asComposeImageBitmap()` results in `Unresolved reference` HOT 2
- Consider removing `Unconfined` dispatcher as default `CoroutineContext` for `ComposeScene` creation HOT 1
- Consider adding a boolean to disable `GlobalSnapshotManager.ensureStarted()` call during scene creation
- PressInteraction.Cancel is sent on mouse press and drag outside surface HOT 1
- Are there any good suggestions about using compose to generate UI through drag and drop and output the code to the local? HOT 5
- Erratic window focus behavior HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compose-multiplatform.