8000 Add iOS SwiftUI sample by avdim · Pull Request #1 · avdim/compose-mapview · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add iOS SwiftUI sample #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include-config/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ kotlin {
js(IR) {
browser()
}
ios {
binaries {
framework {
baseName = "config"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
Expand Down
2 changes: 1 addition & 1 deletion include-mapview/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ kotlin {
implementation("com.map:model:1.0-SNAPSHOT")
implementation("com.map:tile-image:1.0-SNAPSHOT")
implementation(compose.runtime)
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt")
}
}
val androidMain by getting {
Expand Down
9 changes: 8 additions & 1 deletion include-model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ kotlin {
js(IR) {
browser()
}
ios {
binaries {
framework {
baseName = "model"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.map:config:1.0-SNAPSHOT")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt")
}
}
val jsMain by getting {
Expand Down
3 changes: 0 additions & 3 deletions include-model/src/jsMain/kotlin/com/map/Time_js.kt

This file was deleted.

7 changes: 7 additions & 0 deletions include-secret/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ kotlin {
js(IR) {
browser()
}
ios {
binaries {
framework {
baseName = "secret"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
Expand Down
18 changes: 16 additions & 2 deletions include-tile-image/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,43 @@ kotlin {
js(IR) {
browser()
}
ios {
binaries {
framework {
baseName = "tileimage"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.map:config:1.0-SNAPSHOT")
api(compose.runtime)
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt")
}
}
val androidMain by getting {
dependencies {
api(compose.foundation)
api(compose.runtime)
}
}
val desktopMain by getting {
dependencies {
api(compose.foundation)
api(compose.runtime)
}
}
val jsMain by getting {
dependencies {
api(compose.runtime)
implementation(npm("colors", "=1.4.0"))//temp vulnerability fix, use strict version 1.4.0
}
}
val iosMain by getting {
dependencies {

}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlin.math.max

/**
* Из кэша найти графику для нужного тайла.
* Если нужной графики нету, то можно тайли tile с меньшим zoom и вырезать из него кусочек.
* Если нужной графики нету, то можно найти tile с меньшим zoom и вырезать из него кусочек.
*/
fun Map<Tile, TileImage>.searchOrCrop(tile: Tile): TileImage? {
val img1 = get(tile)
Expand Down
25 changes: 25 additions & 0 deletions include-tile-image/src/iosMain/kotlin/com/map/TileImage_ios.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.map

import platform.CoreGraphics.*
import platform.Foundation.*
import platform.UIKit.*
import platform.posix.*


//typealias ImageIos = CGImage
typealias ImageIos = UIImage

actual class TileImage(
val platformSpecificData: ImageIos,
actual val offsetX: Int = 0,
actual val offsetY: Int = 0,
actual val cropSize: Int = TILE_SIZE,
) {
actual fun lightweightDuplicate(offsetX: Int, offsetY: Int, cropSize: Int): TileImage =
TileImage(
platformSpecificData,
offsetX = offsetX,
offsetY = offsetY,
cropSize = cropSize
)
}
3 changes: 3 additions & 0 deletions include-ui-browser/src/jsMain/kotlin/com/map/Time_js.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.map

inline fun timeMs(): Long = kotlin.js.Date.now().toLong()
41 changes: 41 additions & 0 deletions ioshelper/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
kotlin("multiplatform")
}

repositories {
google()
mavenCentral()
}

kotlin {
// android()
ios {
binaries {
framework {
baseName = "ioshelper"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.map:config:1.0-SNAPSHOT")
implementation("com.map:model:1.0-SNAPSHOT")
implementation("com.map:tile-image:1.0-SNAPSHOT")
implementation("com.map:secret:1.0-SNAPSHOT")//todo bad
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val iosMain by getting {
dependencies {
implementation("com.soywiz.korlibs.korim:korim:2.2.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt")
}
}
val iosTest by getting
}
}
33 changes: 33 additions & 0 deletions ioshelper/src/iosMain/kotlin/com/map/MapStoreAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.map

import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch

class MapStoreAdapter(val sideEffectHandler: (Store<MapState<TileImage>, MapIntent<TileImage>>, MapSideEffect) -> Unit) {
val scope = MainScope()
val store: Store<MapState<TileImage>, MapIntent<TileImage>> = scope.createMapStore(
latitude = 0.0,
longitude = 0.0,
startScale = 1.0,
searchOrCropOrNull = { searchOrCrop(it) },
) { store, sideEffect ->
sideEffectHandler(store, sideEffect)
}

fun sendIntent(intent: MapIntent<TileImage>) {
store.send(intent)
}

fun getLastState(): MapState<TileImage> {
return store.stateFlow.value
}

fun addListener(listener: (MapState<TileImage>) -> Unit) {
scope.launch {
store.stateFlow.collectLatest {
listener(it)
}
}
}
}
27 changes: 27 additions & 0 deletions ioshelper/src/iosMain/kotlin/com/map/SwiftHelpers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.map

import platform.CoreGraphics.*

fun sideEffectAsLoadTile(effect: MapSideEffect): MapSideEffect.LoadTile? {
return when (effect) {
is MapSideEffect.LoadTile -> effect
else -> null
}
}

fun createIntentTileLoaded(tile: Tile, imageIos: ImageIos /*CGImage*/) = MapIntent.TileImageLoaded<TileImage>(
tile = tile,
image = TileImage(
platformSpecificData = imageIos,
)
)

fun createIntentMove(x: Int, y: Int) = MapIntent.Input.Move<TileImage>(Pt(x, y))
fun createIntentZoom(x: Int, y: Int, delta: Float) = MapIntent.Input.Zoom<TileImage>(Pt(x, y), delta.toDouble())
fun createIntentSetSize(width:Int, height:Int) = MapIntent.Input.SetSize<TileImage>(width, height)

fun createTileUrl(tile: Tile): String {
return Config.createTileUrl(tile.zoom, tile.x, tile.y, mapTilerSecretKey = MAPTILER_SECRET_KEY)
}

fun extract(tileImage: TileImage) = tileImage.platformSpecificData
22 changes: 22 additions & 0 deletions sample-ios/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id("org.jetbrains.gradle.apple.applePlugin") version "212.4638.14-0.14"
}

apple {
iosApp {
productName = "mapviewios"

sceneDelegateClass = "SceneDelegate"
launchStoryboard = "LaunchScreen"

//productInfo["NSAppTransportSecurity"] = mapOf("NSAllowsArbitraryLoads" to true)
//buildSettings.OTHER_LDFLAGS("")

dependencies {
implementation("com.map:config:1.0-SNAPSHOT")
implementation("com.map:model:1.0-SNAPSHOT")
implementation("com.map:tile-image:1.0-SNAPSHOT")
implementation(project(":ioshelper"))
}
}
}
16 changes: 16 additions & 0 deletions sample-ios/src/iosAppMain/apple/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
6 changes: 6 additions & 0 deletions sample-ios/src/iosAppMain/apple/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
0