From 1c3a437d0ab5595d74a3fed4882d482d1a60a0d4 Mon Sep 17 00:00:00 2001 From: Sargun Vohra Date: Thu, 21 Nov 2024 23:34:12 -0800 Subject: [PATCH] some tweaks --- .editorconfig | 10 +---- .fleet/run.json | 44 +++++++++++++++++++ build.gradle.kts | 17 ++++++- demo-app/build.gradle.kts | 4 -- maplibre-compose/build.gradle.kts | 6 +-- .../maplibrecompose/compose/MaplibreMap.kt | 6 +-- .../maplibrecompose/compose/IosMapView.kt | 2 + .../sargunv/maplibrecompose/core/IosMap.kt | 6 +++ .../sargunv/maplibrecompose/core/util/util.kt | 7 ++- scripts/pre-commit | 7 +++ 10 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 .fleet/run.json create mode 100755 scripts/pre-commit diff --git a/.editorconfig b/.editorconfig index 6734b1cc..4ecf8bc1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,14 +4,6 @@ root = true end_of_line = lf insert_final_newline = true -[*.yml] -indent_style = space -indent_size = 2 - -[*.{kt,kts}] -indent_style = space -indent_size = 2 - -[*.{swift}] +[*.{yml,json,kt,kts,swift}] indent_style = space indent_size = 2 diff --git a/.fleet/run.json b/.fleet/run.json new file mode 100644 index 00000000..c07bf1e3 --- /dev/null +++ b/.fleet/run.json @@ -0,0 +1,44 @@ +{ + "configurations": [ + { + "name": "iOS-App", + "type": "xcode-app", + "workingDir": "$PROJECT_DIR$", + "buildTarget": { + "project": "iosApp", + "target": "iosApp" + }, + "configuration": "Debug" + }, + { + "name": "Android-App", + "type": "android-app", + "workingDir": "$PROJECT_DIR$", + "module": "root.demo-app.main" + }, + { + "name": "Reformat", + "type": "gradle", + "workingDir": "$PROJECT_DIR$", + "tasks": [ + "spotlessApply" + ], + }, + { + "name": "iOS-Test", + "type": "gradle", + "workingDir": "$PROJECT_DIR$", + "tasks": [ + "iosSimulatorArm64Test" + ], + }, + { + "name": "Android-Test", + "type": "gradle", + "workingDir": "$PROJECT_DIR$", + "tasks": [ + "connectedDebugAndroidTest" + ], + } + ] +} diff --git a/build.gradle.kts b/build.gradle.kts index 5bf7e795..1080ce1f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,6 +18,21 @@ subprojects { spotless { format("swift") { target("iosApp/iosApp/**/*.swift") - nativeCmd("swiftFormat","/usr/bin/env", listOf("swift", "format")) + nativeCmd("swiftFormat", "/usr/bin/env", listOf("swift", "format")) + } +} + +tasks.register("installGitHooks") { + doLast { + copy { + from("${rootProject.projectDir}/scripts/pre-commit") + into("${rootProject.projectDir}/.git/hooks") + } + } +} + +tasks.named("clean") { + doLast { + delete("${rootProject.projectDir}/.git/hooks/pre-commit") } } diff --git a/demo-app/build.gradle.kts b/demo-app/build.gradle.kts index 806d4ba4..411fc388 100644 --- a/demo-app/build.gradle.kts +++ b/demo-app/build.gradle.kts @@ -62,10 +62,6 @@ kotlin { add("-Xconsistent-data-class-copy-visibility") } } - languageSettings { - optIn("androidx.compose.material3.ExperimentalMaterial3Api") - optIn("org.jetbrains.compose.resources.ExperimentalResourceApi") - } } commonMain.dependencies { diff --git a/maplibre-compose/build.gradle.kts b/maplibre-compose/build.gradle.kts index cc573419..6c8d4737 100644 --- a/maplibre-compose/build.gradle.kts +++ b/maplibre-compose/build.gradle.kts @@ -56,11 +56,7 @@ kotlin { add("-Xconsistent-data-class-copy-visibility") } } - languageSettings { - optIn("androidx.compose.ui.ExperimentalComposeUiApi") - optIn("kotlinx.cinterop.ExperimentalForeignApi") - optIn("kotlinx.cinterop.BetaInteropApi") - } + languageSettings { optIn("kotlinx.cinterop.ExperimentalForeignApi") } } commonMain.dependencies { diff --git a/maplibre-compose/src/commonMain/kotlin/dev/sargunv/maplibrecompose/compose/MaplibreMap.kt b/maplibre-compose/src/commonMain/kotlin/dev/sargunv/maplibrecompose/compose/MaplibreMap.kt index 20fe7e78..53deb81e 100644 --- a/maplibre-compose/src/commonMain/kotlin/dev/sargunv/maplibrecompose/compose/MaplibreMap.kt +++ b/maplibre-compose/src/commonMain/kotlin/dev/sargunv/maplibrecompose/compose/MaplibreMap.kt @@ -1,10 +1,6 @@ package dev.sargunv.maplibrecompose.compose -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue +import androidx.compose.runtime.* import androidx.compose.ui.Modifier import co.touchlab.kermit.Logger import dev.sargunv.maplibrecompose.compose.engine.LayerNode diff --git a/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/compose/IosMapView.kt b/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/compose/IosMapView.kt index 3d3c72fb..58abdfed 100644 --- a/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/compose/IosMapView.kt +++ b/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/compose/IosMapView.kt @@ -10,6 +10,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue +import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.viewinterop.UIKitInteropInteractionMode @@ -42,6 +43,7 @@ internal actual fun ComposableMapView( ) } +@OptIn(ExperimentalComposeUiApi::class) @Composable internal fun IosMapView( modifier: Modifier, diff --git a/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/core/IosMap.kt b/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/core/IosMap.kt index aa5f207f..2a11cae4 100644 --- a/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/core/IosMap.kt +++ b/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/core/IosMap.kt @@ -37,6 +37,7 @@ import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine import kotlin.time.Duration import kotlin.time.DurationUnit +import kotlinx.cinterop.BetaInteropApi import kotlinx.cinterop.CValue import kotlinx.cinterop.ObjCAction import kotlinx.cinterop.useContents @@ -130,6 +131,7 @@ internal class IosMap( recognizer.addTarget(target = this, action = sel_registerName(::handleGesture.name + ":")) } + @OptIn(BetaInteropApi::class) @ObjCAction fun handleGesture(sender: UIGestureRecognizer) { @Suppress("UNCHECKED_CAST") action(sender as T) @@ -180,6 +182,7 @@ internal class IosMap( (uiPadding.calculateTopPadding().value - insetPadding.calculateTopPadding().value) .toDouble(), ) + MLNOrnamentPositionTopRight -> CGPointMake( (uiPadding.calculateRightPadding(layoutDir).value - @@ -188,6 +191,7 @@ internal class IosMap( (uiPadding.calculateTopPadding().value - insetPadding.calculateTopPadding().value) .toDouble(), ) + MLNOrnamentPositionBottomLeft -> CGPointMake( (uiPadding.calculateLeftPadding(layoutDir).value - @@ -196,6 +200,7 @@ internal class IosMap( (uiPadding.calculateBottomPadding().value - insetPadding.calculateBottomPadding().value) .toDouble(), ) + MLNOrnamentPositionBottomRight -> CGPointMake( (uiPadding.calculateRightPadding(layoutDir).value - @@ -204,6 +209,7 @@ internal class IosMap( (uiPadding.calculateBottomPadding().value - insetPadding.calculateBottomPadding().value) .toDouble(), ) + else -> error("Invalid ornament position") } } diff --git a/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/core/util/util.kt b/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/core/util/util.kt index 469c0f27..a561f83e 100644 --- a/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/core/util/util.kt +++ b/maplibre-compose/src/iosMain/kotlin/dev/sargunv/maplibrecompose/core/util/util.kt @@ -22,10 +22,7 @@ import dev.sargunv.maplibrecompose.core.expression.Point import io.github.dellisd.spatialk.geojson.Feature import io.github.dellisd.spatialk.geojson.GeoJson import io.github.dellisd.spatialk.geojson.Position -import kotlinx.cinterop.CValue -import kotlinx.cinterop.addressOf -import kotlinx.cinterop.useContents -import kotlinx.cinterop.usePinned +import kotlinx.cinterop.* import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonNull @@ -115,6 +112,7 @@ private fun normalizeJsonLike(value: Any?): Any? = blue = value.blue.toDouble(), alpha = value.alpha.toDouble(), ) + is Insets -> NSValue.valueWithUIEdgeInsets( UIEdgeInsetsMake( @@ -124,6 +122,7 @@ private fun normalizeJsonLike(value: Any?): Any? = right = value.right.toDouble(), ) ) + else -> throw IllegalArgumentException("Unsupported type: ${value::class}") } diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100755 index 00000000..515d815f --- /dev/null +++ b/scripts/pre-commit @@ -0,0 +1,7 @@ +#!/bin/sh + +# Run Spotless +./gradlew -q spotlessApply + +# Add any modified files back to the staging area +git add .