Browse Source

change old UIKitInteropView to UIKitView (#2968)

pull/2853/merge
dima.avdeev 2 years ago committed by GitHub
parent
commit
1c5da4c332
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      experimental/examples/imageviewer/gradle.properties
  2. 21
      experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt
  3. 4
      experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/LocationVisualizer.ios.kt

2
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

21
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<CGRect> ->
factory = {
val cameraContainer = UIView()
cameraContainer.layer.addSublayer(cameraPreviewLayer)
cameraPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
captureSession.startRunning()
cameraContainer
},
onResize = { view: UIView, rect: CValue<CGRect> ->
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,

4
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

Loading…
Cancel
Save