From c77c329b81a4a220f7bb2eee7f0f28e814d53332 Mon Sep 17 00:00:00 2001
From: exav
Date: Tue, 19 Nov 2024 18:51:16 +0100
Subject: [PATCH] CMP-7095: migrate ios camera examples to manual layout
https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-ios-migration.html#onresize-parameter-removed
---
.../imageviewer/view/CameraView.ios.kt | 26 +++++++++----------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt b/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt
index 5499750fba6..52e4a8a49b5 100644
--- a/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt
+++ b/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt
@@ -8,8 +8,8 @@ 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.UIKitView
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.viewinterop.UIKitView
import example.imageviewer.IosStorableImage
import example.imageviewer.PlatformStorableImage
import example.imageviewer.createNewPhotoNameAndDescription
@@ -17,14 +17,14 @@ import example.imageviewer.icon.IconPhotoCamera
import example.imageviewer.model.GpsPosition
import example.imageviewer.model.PictureData
import example.imageviewer.model.createCameraPictureData
-import kotlinx.cinterop.CValue
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ObjCAction
+import kotlinx.cinterop.readValue
import kotlinx.cinterop.useContents
import platform.AVFoundation.*
import platform.AVFoundation.AVCaptureDeviceDiscoverySession.Companion.discoverySessionWithDeviceTypes
import platform.AVFoundation.AVCaptureDeviceInput.Companion.deviceInputWithDevice
-import platform.CoreGraphics.CGRect
+import platform.CoreGraphics.CGRectZero
import platform.CoreLocation.CLLocation
import platform.CoreLocation.CLLocationManager
import platform.CoreLocation.kCLLocationAccuracyBest
@@ -228,22 +228,22 @@ private fun BoxScope.RealDeviceCamera(
}
}
UIKitView(
- modifier = Modifier.fillMaxSize(),
- background = Color.Black,
+ modifier = Modifier.fillMaxSize().background(Color.Black),
factory = {
- val cameraContainer = UIView()
+ val cameraContainer = object: UIView(frame = CGRectZero.readValue()) {
+ override fun layoutSubviews() {
+ CATransaction.begin()
+ CATransaction.setValue(true, kCATransactionDisableActions)
+ layer.setFrame(frame)
+ cameraPreviewLayer.setFrame(frame)
+ CATransaction.commit()
+ }
+ }
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()
- },
)
CircularButton(
imageVector = IconPhotoCamera,