From 1c5da4c3324421766b2380eb69802b0be78bf677 Mon Sep 17 00:00:00 2001 From: "dima.avdeev" <99798741+dima-avdeev-jb@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:51:52 +0300 Subject: [PATCH] change old UIKitInteropView to UIKitView (#2968) --- .../examples/imageviewer/gradle.properties | 2 +- .../imageviewer/view/CameraView.ios.kt | 21 ++++++++++--------- .../view/LocationVisualizer.ios.kt | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/experimental/examples/imageviewer/gradle.properties b/experimental/examples/imageviewer/gradle.properties index 6c1b836856..a99fa81d2b 100644 --- a/experimental/examples/imageviewer/gradle.properties +++ b/experimental/examples/imageviewer/gradle.properties @@ -13,4 +13,4 @@ kotlin.native.useEmbeddableCompilerJar=true kotlin.native.binary.memoryModel=experimental kotlin.version=1.8.10 agp.version=7.1.3 -compose.version=1.4.0-alpha01-dev1004 +compose.version=1.4.0-alpha01-dev1008 diff --git a/experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt b/experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt index 9fcefbfc6f..5ffca19fe7 100644 --- a/experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt +++ b/experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt @@ -9,7 +9,7 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.interop.UIKitInteropView +import androidx.compose.ui.interop.UIKitView import androidx.compose.ui.unit.dp import example.imageviewer.IosStorableImage import example.imageviewer.LocalLocalization @@ -226,23 +226,24 @@ private fun BoxScope.RealDeviceCamera( ) } } - UIKitInteropView( + UIKitView( modifier = Modifier.fillMaxSize(), background = Color.Black, - resize = { view: UIView, rect: CValue -> + factory = { + val cameraContainer = UIView() + cameraContainer.layer.addSublayer(cameraPreviewLayer) + cameraPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill + captureSession.startRunning() + cameraContainer + }, + onResize = { view: UIView, rect: CValue -> CATransaction.begin() CATransaction.setValue(true, kCATransactionDisableActions) view.layer.setFrame(rect) cameraPreviewLayer.setFrame(rect) CATransaction.commit() }, - ) { - val cameraContainer = UIView() - cameraContainer.layer.addSublayer(cameraPreviewLayer) - cameraPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill - captureSession.startRunning() - cameraContainer - } + ) Button( modifier = Modifier.align(Alignment.BottomCenter).padding(44.dp), enabled = !capturePhotoStarted, diff --git a/experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/LocationVisualizer.ios.kt b/experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/LocationVisualizer.ios.kt index 5cc8453ad2..f1df91b27a 100644 --- a/experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/LocationVisualizer.ios.kt +++ b/experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/LocationVisualizer.ios.kt @@ -3,7 +3,7 @@ package example.imageviewer.view import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.interop.UIKitInteropView +import androidx.compose.ui.interop.UIKitView import example.imageviewer.model.GpsPosition import platform.CoreLocation.CLLocationCoordinate2DMake import platform.MapKit.MKCoordinateRegionMakeWithDistance @@ -22,7 +22,7 @@ internal actual fun LocationVisualizer(modifier: Modifier, gps: GpsPosition, tit } val mkMapView = remember { MKMapView().apply { addAnnotation(annotation) } } annotation.setTitle(title) - UIKitInteropView( + UIKitView( modifier = modifier, factory = { mkMapView