Fix camera size and resize behaviour
This commit is contained in:
@@ -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<CGRect> ->
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user