Browse Source

add UIKit MKMapView to ImageViewer (#2841)

pull/2853/head
dima.avdeev 2 years ago committed by GitHub
parent
commit
4cf574cc34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      experimental/examples/imageviewer/gradle.properties
  2. 4
      experimental/examples/imageviewer/iosApp/iosApp/ContentView.swift
  3. 19
      experimental/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/LocationVisualizer.android.kt
  4. 7
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/LocationVisualizer.common.kt
  5. 25
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/MemoryScreen.kt
  6. 19
      experimental/examples/imageviewer/shared/src/desktopMain/kotlin/example/imageviewer/view/LocationVisualizer.desktop.kt
  7. 30
      experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/LocationVisualizer.ios.kt

2
experimental/examples/imageviewer/gradle.properties

@ -13,5 +13,5 @@ kotlin.native.useEmbeddableCompilerJar=true
kotlin.native.binary.memoryModel=experimental
kotlin.version=1.8.0
agp.version=7.1.3
compose.version=1.4.0-alpha01-dev954
compose.version=1.4.0-alpha01-dev968
ktor.version=2.2.1

4
experimental/examples/imageviewer/iosApp/iosApp/ContentView.swift

@ -15,7 +15,9 @@ let gradient = LinearGradient(
struct ComposeView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
Main_iosKt.MainViewController()
let controller = Main_iosKt.MainViewController()
controller.overrideUserInterfaceStyle = .light
return controller
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}

19
experimental/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/LocationVisualizer.android.kt

@ -0,0 +1,19 @@
package example.imageviewer.view
import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource
@OptIn(ExperimentalResourceApi::class)
@Composable
internal actual fun LocationVisualizer(modifier: Modifier) {
Image(
painter = painterResource("dummy_map.png"),
contentDescription = "Map",
contentScale = ContentScale.Crop,
modifier = modifier
)
}

7
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/LocationVisualizer.common.kt

@ -0,0 +1,7 @@
package example.imageviewer.view
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@Composable
internal expect fun LocationVisualizer(modifier: Modifier)

25
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/MemoryScreen.kt

@ -3,15 +3,12 @@ package example.imageviewer.view
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.*
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
@ -70,7 +67,14 @@ internal fun MemoryScreen(
Box(modifier = Modifier.background(MaterialTheme.colorScheme.background)) {
Column {
Headliner("Place")
LocationVisualizer()
val locationShape = RoundedCornerShape(10.dp)
LocationVisualizer(
Modifier.padding(horizontal = 12.dp)
.clip(locationShape)
.border(1.dp, Color.Gray, locationShape)
.fillMaxWidth()
.height(200.dp)
)
Headliner("Note")
Collapsible(
"""
@ -201,17 +205,6 @@ internal fun Headliner(s: String) {
)
}
@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun LocationVisualizer() {
Image(
painterResource("dummy_map.png"),
"Map",
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxWidth().height(200.dp)
)
}
@Composable
internal fun RelatedMemoriesVisualizer(
ps: List<GalleryEntryWithMetadata>,

19
experimental/examples/imageviewer/shared/src/desktopMain/kotlin/example/imageviewer/view/LocationVisualizer.desktop.kt

@ -0,0 +1,19 @@
package example.imageviewer.view
import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource
@OptIn(ExperimentalResourceApi::class)
@Composable
internal actual fun LocationVisualizer(modifier: Modifier) {
Image(
painter = painterResource("dummy_map.png"),
contentDescription = "Map",
contentScale = ContentScale.Crop,
modifier = modifier
)
}

30
experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/LocationVisualizer.ios.kt

@ -0,0 +1,30 @@
package example.imageviewer.view
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.interop.UIKitInteropView
import platform.CoreLocation.CLLocationCoordinate2DMake
import platform.MapKit.MKCoordinateRegionMakeWithDistance
import platform.MapKit.MKMapView
import platform.MapKit.MKPointAnnotation
@Composable
internal actual fun LocationVisualizer(modifier: Modifier) {
//todo get real geo coordinates
UIKitInteropView(
modifier = modifier,
factory = {
val mkMapView = MKMapView()
val cityAmsterdam = CLLocationCoordinate2DMake(52.3676, 4.9041)
mkMapView.setRegion(
MKCoordinateRegionMakeWithDistance(
centerCoordinate = cityAmsterdam,
5000.0, 5000.0
),
animated = false
)
mkMapView.addAnnotation(MKPointAnnotation(cityAmsterdam, title = null, subtitle = null))
mkMapView
},
)
}
Loading…
Cancel
Save