Invoking MapView method with multiple parameters #24
Unanswered
josephktcheung
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Referring to the example
MapView
, I'd like to ask how can we support setting a map region withanimated
parameter not default totrue
https://github.com/pointfreeco/composable-core-location/blob/main/Examples/LocationManager/Common/MapView.swift#L55.Why I ask this is recently we face an issue of interoperating UIKit view and SwiftUI view. We want the SwiftUI view to be able to call UIKit view method e.g.
setRegion
with multiple parameters. One school of thought is to add asetRegionAnimated
variable toMapView
like this:Then in
LocationManagerView
:However this would make the view to be flooded with variables and we may forget to update the state (let's say we turned off animation temporarily but forget to turn it back on). Also one would argue that
animated
parameter is a transient state which should not be stored as binding / persisted state / variable likeregion
.An alternative is to create a
PassthroughSubject
to communicate parameter changes between SwiftUI and UIKit view:Then in
LocationManagerView
:However this approach doesn't utilise viewStore's binding and feels like an alien to TCA.
I think this question is common when integrating a UIKit view into SwiftUI. How would one design a bridging view API interface so that it can be consumed easily using TCA when we want to allow library users to invoke UIKit view methods that take multiple parameters (some may better be binding / persisted state e.g.
region
, while some are just one-off e.g.animated
).Thanks,
Joseph
Beta Was this translation helpful? Give feedback.
All reactions