I making an app using compose multiplatform that h...
# compose-ios
m
I making an app using compose multiplatform that has a map view. when implementing the map view in iOS I’m using its interoperability capabilities to make a UI view containing a GMSMapView, while the map view is visible there’s a marker that moves based on a flow of locations, when I navigate to another screen and go back to the map view the marker initially moves to a random location that’s unrelated to where it initially was. In the MapView composable which wraps the UIKitView I initialize the GMSMapView, GMSCameraPosition, and GMSMarker, so is there a best practice for interoperability and using the UIKitView with native iOS views that depend on other native iOS objects, and more specifically is there a best practice for that use case? I'm using decompose and MVIKotlin for navigating between screens and handling the state respectively
👍 1
m
I'll take a look, thank you
b
@Dima Avdeev Those are all examples where the swift component is created from kotlin code. I'd love to see best practices for case where a view is created in swift, passed to kotlin, and then rendered using
UIKitView
. The pattern I am currently using for doing this is to pass a
() -> UIView
function from swift to kotlin at app startup, store the function in a singleton, and then use that function in various composables throughout the app when I want to generate a swift view to be used within a compose layout. I set and read from this function parameter only on the main thread. In the parts of the app I do this, I see spontaneous
EXC_BAD_ACCESS: Attempted to dereference garbage pointer
errors. Very hard to reproduce. I suspect these errors are from this pattern, but not 100% certain. My next step is to run an experiment on a very simple view where I'll expose 50% of users to code using this pattern, and 50% to not seeing this pattern.
actually I feel like an idiot, but I think I know what the problem is 🙂 Best practice often in ios is to pass
[weak self]
to callback. I was doing that in the function blocks I pass from swift to kotlin. I have a single UIViewController that launches compose, I need to pass
self.view.bounds
or
self.frame
for multiple views. I don't need the
self
reference to be weak; since I have a single ViewController on ios side, I can just strong reference it since it will always be around anyway.
c
@Brendan Weinstein @Dima Avdeev how would you go about rendering a custom marker/annotation icon on MKMapView instead of the default icons? For example in iOS, we would do this : assign a circle to the content lambda so the circle can be displayed at the given location coordinates
Map(coordinateRegion: $region, annotationItems: locations){ location *in*
MapAnnotation(coordinate: location.coordinate) {
Circle()
.stroke(.red, lineWidth: 3)
.frame(width: 44, height: 44)
}
}
How would one go about doing this in Compose through MKMapView ?