From 100a7f3f2dc41f91ae6467b6c790bd0523a91a46 Mon Sep 17 00:00:00 2001 From: Olof Hedman Date: Tue, 14 Oct 2025 20:07:18 +0200 Subject: [PATCH] Fix camera size and resize behaviour --- .../app/klottr/maps/MapContainer.ios.kt | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/shared/src/iosMain/kotlin/app/klottr/maps/MapContainer.ios.kt b/shared/src/iosMain/kotlin/app/klottr/maps/MapContainer.ios.kt index 1c9b2ff..212843e 100644 --- a/shared/src/iosMain/kotlin/app/klottr/maps/MapContainer.ios.kt +++ b/shared/src/iosMain/kotlin/app/klottr/maps/MapContainer.ios.kt @@ -5,6 +5,7 @@ package app.klottr.maps import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.interop.UIKitView +import androidx.compose.foundation.layout.fillMaxSize import cocoapods.GoogleMaps.GMSMapView import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.coroutines.channels.BufferOverflow @@ -17,6 +18,7 @@ import cocoapods.GoogleMaps.* // from GoogleMaps iOS SDK import kotlinx.cinterop.CValue import kotlinx.cinterop.readValue import kotlinx.cinterop.useContents +import platform.CoreGraphics.CGRect import platform.UIKit.UIView import platform.darwin.NSObject @@ -96,7 +98,7 @@ actual fun MapContainer( applyFeatures(mv, features) mv }, - modifier = Modifier, + modifier = Modifier.fillMaxSize(), update = { mv: UIView -> (mv as GMSMapView).let { map -> // update UI toggles @@ -117,7 +119,21 @@ actual fun MapContainer( }, onRelease = { mapViewRef = null - } + }, + onResize = { view: GMSMapView, rect: CValue -> + // Compose gives the new CGRect for this UIKitView slot. + view.setFrame(frame = rect) + + // Let Google Maps re-layout its subviews (compass, my-location, logo) after size changes. + view.setNeedsLayout() + view.layoutIfNeeded() + + // If you rely on content padding/insets, re-apply here. + // view.setPadding(UIEdgeInsetsZero.readValue()) + // Do not touch the camera to avoid jumps/flicker. + }, + interactive = true, + accessibilityEnabled = true ) // Expose controller once