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.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.interop.UIKitView
|
import androidx.compose.ui.interop.UIKitView
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import cocoapods.GoogleMaps.GMSMapView
|
import cocoapods.GoogleMaps.GMSMapView
|
||||||
import kotlinx.cinterop.ExperimentalForeignApi
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
import kotlinx.coroutines.channels.BufferOverflow
|
import kotlinx.coroutines.channels.BufferOverflow
|
||||||
@@ -17,6 +18,7 @@ import cocoapods.GoogleMaps.* // from GoogleMaps iOS SDK
|
|||||||
import kotlinx.cinterop.CValue
|
import kotlinx.cinterop.CValue
|
||||||
import kotlinx.cinterop.readValue
|
import kotlinx.cinterop.readValue
|
||||||
import kotlinx.cinterop.useContents
|
import kotlinx.cinterop.useContents
|
||||||
|
import platform.CoreGraphics.CGRect
|
||||||
import platform.UIKit.UIView
|
import platform.UIKit.UIView
|
||||||
import platform.darwin.NSObject
|
import platform.darwin.NSObject
|
||||||
|
|
||||||
@@ -96,7 +98,7 @@ actual fun MapContainer(
|
|||||||
applyFeatures(mv, features)
|
applyFeatures(mv, features)
|
||||||
mv
|
mv
|
||||||
},
|
},
|
||||||
modifier = Modifier,
|
modifier = Modifier.fillMaxSize(),
|
||||||
update = { mv: UIView ->
|
update = { mv: UIView ->
|
||||||
(mv as GMSMapView).let { map ->
|
(mv as GMSMapView).let { map ->
|
||||||
// update UI toggles
|
// update UI toggles
|
||||||
@@ -117,7 +119,21 @@ actual fun MapContainer(
|
|||||||
},
|
},
|
||||||
onRelease = {
|
onRelease = {
|
||||||
mapViewRef = null
|
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
|
// Expose controller once
|
||||||
|
|||||||
Reference in New Issue
Block a user