From d9d43d272f14e160919147e162aeb0a7766909f4 Mon Sep 17 00:00:00 2001 From: rinekri Date: Mon, 9 Nov 2026 15:36:40 +0000 Subject: [PATCH 1/3] Migrate uikit to Kotlin Multiplatform (0.4.0) Publish uikit-core, uikit-components and uikit-components-foundation for android, iosArm64, iosSimulatorArm64, jvm, js and wasmJs. - Material3 backend: androidx material3 1.4.0 on Android, Compose Multiplatform material3 elsewhere; foundation backend stays pure Foundation. - Breaking: dates use kotlinx.datetime.LocalDate; date picker *Res: Int config fields become composable lambdas. - PlatformDates expect/actual (@InternalUikitApi) for localized date text; foundation sheet window setup moved behind expect/actual. - AGP 9 KMP library plugin, CMP 1.11.1; iosX64 dropped (not published by CMP). - CI: release on macOS, pre-merge adds macOS iOS job and jvmTest. --- .github/workflows/pre-merge.yaml | 30 +++++- .github/workflows/release.yml | 3 +- CHANGELOG.md | 32 +++++++ README.md | 32 ++++++- build.gradle.kts | 11 +-- gradle.properties | 2 +- gradle/libs.versions.toml | 16 +++- .../uikit/sample/PreviewUikitConfiguration.kt | 16 ++-- .../sample/previews/DatePickerPreviews.kt | 4 +- uikit-components-foundation/build.gradle.kts | 59 +++++++----- .../components/internal/Platform.android.kt | 28 ++++++ .../kotlin/ru/kode/uikit/components/Button.kt | 0 .../ru/kode/uikit/components/Checkbox.kt | 0 .../ru/kode/uikit/components/DatePicker.kt | 95 ++++++++++--------- .../kode/uikit/components/ModalBottomSheet.kt | 20 +--- .../ru/kode/uikit/components/RadioButton.kt | 0 .../kotlin/ru/kode/uikit/components/Slider.kt | 0 .../internal/FoundationPrimitives.kt | 0 .../uikit/components/internal/Platform.kt | 15 +++ .../src/main/AndroidManifest.xml | 1 - .../internal/Platform.nonAndroid.kt | 15 +++ uikit-components/build.gradle.kts | 52 +++++----- .../kotlin/ru/kode/uikit/components/Button.kt | 0 .../ru/kode/uikit/components/Checkbox.kt | 0 .../ru/kode/uikit/components/DatePicker.kt | 42 ++++---- .../kode/uikit/components/ModalBottomSheet.kt | 0 .../ru/kode/uikit/components/RadioButton.kt | 0 .../kotlin/ru/kode/uikit/components/Slider.kt | 0 uikit-components/src/main/AndroidManifest.xml | 1 - uikit-core/build.gradle.kts | 69 +++++++++----- .../core/internal/PlatformDates.android.kt | 6 ++ .../components/BottomSheetConfiguration.kt | 0 .../uikit/components/ButtonConfiguration.kt | 0 .../uikit/components/CheckboxConfiguration.kt | 0 .../kode/uikit/components/DatePickerState.kt | 24 ++--- .../ru/kode/uikit/components/PageIndicator.kt | 0 .../components/RadioButtonConfiguration.kt | 0 .../ru/kode/uikit/components/SliderState.kt | 0 .../ru/kode/uikit/components/TextField.kt | 0 .../ru/kode/uikit/components/TextFieldArea.kt | 0 .../configuration/UikitConfiguration.kt | 0 .../uikit/components/shimmer/Placeholder.kt | 0 .../shimmer/PlaceholderHighlight.kt | 0 .../kode/uikit/components/shimmer/Shimmer.kt | 0 .../components/shimmer/ShimmerModifiers.kt | 0 .../uikit/core/internal/InternalUikitApi.kt | 10 ++ .../kode/uikit/core/internal/PlatformDates.kt | 19 ++++ .../uikit/core/internal/PlatformDatesTest.kt | 32 +++++++ .../uikit/core/internal/PlatformDates.ios.kt | 40 ++++++++ .../core/internal/PlatformDates.jvmAndroid.kt | 30 ++++++ .../uikit/core/internal/PlatformDates.jvm.kt | 6 ++ uikit-core/src/main/AndroidManifest.xml | 1 - .../uikit/core/internal/PlatformDates.web.kt | 44 +++++++++ 53 files changed, 553 insertions(+), 202 deletions(-) create mode 100644 uikit-components-foundation/src/androidMain/kotlin/ru/kode/uikit/components/internal/Platform.android.kt rename uikit-components-foundation/src/{main => commonMain}/kotlin/ru/kode/uikit/components/Button.kt (100%) rename uikit-components-foundation/src/{main => commonMain}/kotlin/ru/kode/uikit/components/Checkbox.kt (100%) rename uikit-components-foundation/src/{main => commonMain}/kotlin/ru/kode/uikit/components/DatePicker.kt (89%) rename uikit-components-foundation/src/{main => commonMain}/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt (89%) rename uikit-components-foundation/src/{main => commonMain}/kotlin/ru/kode/uikit/components/RadioButton.kt (100%) rename uikit-components-foundation/src/{main => commonMain}/kotlin/ru/kode/uikit/components/Slider.kt (100%) rename uikit-components-foundation/src/{main => commonMain}/kotlin/ru/kode/uikit/components/internal/FoundationPrimitives.kt (100%) create mode 100644 uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/internal/Platform.kt delete mode 100644 uikit-components-foundation/src/main/AndroidManifest.xml create mode 100644 uikit-components-foundation/src/nonAndroidMain/kotlin/ru/kode/uikit/components/internal/Platform.nonAndroid.kt rename uikit-components/src/{main => commonMain}/kotlin/ru/kode/uikit/components/Button.kt (100%) rename uikit-components/src/{main => commonMain}/kotlin/ru/kode/uikit/components/Checkbox.kt (100%) rename uikit-components/src/{main => commonMain}/kotlin/ru/kode/uikit/components/DatePicker.kt (92%) rename uikit-components/src/{main => commonMain}/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt (100%) rename uikit-components/src/{main => commonMain}/kotlin/ru/kode/uikit/components/RadioButton.kt (100%) rename uikit-components/src/{main => commonMain}/kotlin/ru/kode/uikit/components/Slider.kt (100%) delete mode 100644 uikit-components/src/main/AndroidManifest.xml create mode 100644 uikit-core/src/androidMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.android.kt rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/BottomSheetConfiguration.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/ButtonConfiguration.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/CheckboxConfiguration.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/DatePickerState.kt (85%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/PageIndicator.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/RadioButtonConfiguration.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/SliderState.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/TextField.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/TextFieldArea.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/configuration/UikitConfiguration.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/shimmer/Placeholder.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/shimmer/PlaceholderHighlight.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/shimmer/Shimmer.kt (100%) rename uikit-core/src/{main => commonMain}/kotlin/ru/kode/uikit/components/shimmer/ShimmerModifiers.kt (100%) create mode 100644 uikit-core/src/commonMain/kotlin/ru/kode/uikit/core/internal/InternalUikitApi.kt create mode 100644 uikit-core/src/commonMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.kt create mode 100644 uikit-core/src/commonTest/kotlin/ru/kode/uikit/core/internal/PlatformDatesTest.kt create mode 100644 uikit-core/src/iosMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.ios.kt create mode 100644 uikit-core/src/jvmAndroidMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvmAndroid.kt create mode 100644 uikit-core/src/jvmMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvm.kt delete mode 100644 uikit-core/src/main/AndroidManifest.xml create mode 100644 uikit-core/src/webMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.web.kt diff --git a/.github/workflows/pre-merge.yaml b/.github/workflows/pre-merge.yaml index 67c440e..ad2e9c0 100644 --- a/.github/workflows/pre-merge.yaml +++ b/.github/workflows/pre-merge.yaml @@ -26,7 +26,12 @@ jobs: uses: gradle/actions/setup-gradle@v4 - name: Check formatting and assemble - run: ./gradlew spotlessCheck :uikit-core:assembleRelease :uikit-components:assembleRelease :uikit-components-foundation:assembleRelease --continue + run: >- + ./gradlew spotlessCheck --continue + :uikit-core:assemble :uikit-components:assemble :uikit-components-foundation:assemble + + - name: Test (JVM) + run: ./gradlew :uikit-core:jvmTest # Both flavors compare against the same goldens in sample/src/test/snapshots. - name: Verify screenshots (Material3 backend) @@ -45,3 +50,26 @@ jobs: **/build/reports/ sample/build/outputs/roborazzi/ if-no-files-found: warn + + ios: + runs-on: macos-latest + if: ${{ !contains(github.event.head_commit.message, 'ci skip') }} + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Compile iOS and run iOS tests + run: >- + ./gradlew + :uikit-core:iosSimulatorArm64Test + :uikit-components:compileKotlinIosSimulatorArm64 + :uikit-components-foundation:compileKotlinIosSimulatorArm64 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e781bac..6a10985 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,8 @@ permissions: jobs: publish-library: - runs-on: ubuntu-latest + # iOS klibs only build on macOS. + runs-on: macos-latest environment: release if: ${{ !contains(github.event.head_commit.message, 'ci skip') }} steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d7f2b0..3f8d462 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,38 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.4.0 + +### Added +- Kotlin Multiplatform: all three artifacts now publish for Android, iOS (`iosArm64`, `iosSimulatorArm64`), + JVM desktop, `js` and `wasmJs`. Android consumers keep the same coordinates; Gradle module metadata picks the + Android variant. +- The Material3 backend uses androidx Material3 1.4.0 on Android (unchanged) and JetBrains Compose + Multiplatform Material3 on the other targets. The foundation backend is pure Compose Foundation everywhere. + +### Changed (breaking) +- Dates are `kotlinx.datetime.LocalDate` instead of `java.time.LocalDate`: `rememberDatePickerState`, + `DatePickerState.selectedDate`, `onDateConfirm`, the `headline` slot and `UikitDatePickerDefaults.Headline`. +- Android resource ids in the date picker configuration are replaced by composable lambdas: + `TextFieldDatePickerConfiguration.leadingIcon/trailingIcon/errorIcon`, `InlineDatePickerConfiguration.icon` + (`@Composable () -> Painter`) and `ModalDatePickerConfiguration.title/confirmButtonText/cancelButtonText` + (`@Composable () -> String`). Migration: + ```kotlin + // before + TextFieldDatePickerConfiguration(leadingIconRes = R.drawable.ic_calendar, /* … */) + ModalDatePickerConfiguration(titleRes = R.string.pick_date, /* … */) + rememberDatePickerState(initialSelectedDate = java.time.LocalDate.of(2026, 1, 15)) + // after + TextFieldDatePickerConfiguration(leadingIcon = { painterResource(R.drawable.ic_calendar) }, /* … */) + ModalDatePickerConfiguration(title = { stringResource(R.string.pick_date) }, /* … */) + rememberDatePickerState(initialSelectedDate = kotlinx.datetime.LocalDate(2026, 1, 15)) + ``` + +### Notes +- The libraries no longer enable core library desugaring themselves. kotlinx-datetime uses `java.time` on + Android, so apps with `minSdk < 26` need `coreLibraryDesugaring` enabled. +- No `iosX64` (Intel simulator) target: Compose Multiplatform 1.11 no longer publishes it. + ## 0.3.0 ### Added diff --git a/README.md b/README.md index ceeef00..57cd1ed 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,27 @@ [![Maven Central][mavenbadge-svg]][mavencentral] -A library of commonly used UI components built on [Jetpack Compose](https://developer.android.com/compose). +A library of commonly used UI components built on [Jetpack Compose](https://developer.android.com/compose) +and [Compose Multiplatform](https://www.jetbrains.com/compose-multiplatform/). + +| Target | Compose | Material3 backend uses | +|---|---|---| +| Android | Jetpack Compose | androidx Material3 | +| iOS (`iosArm64`, `iosSimulatorArm64`) | Compose Multiplatform | Compose Multiplatform Material3 | +| JVM desktop | Compose Multiplatform | Compose Multiplatform Material3 | +| Web (`js`, `wasmJs`) | Compose Multiplatform | Compose Multiplatform Material3 | ## Usage -Add the dependency for **one** backend (see [Choose a backend](#choose-a-backend)): +Add the dependency for **one** backend (see [Choose a backend](#choose-a-backend)) — to an Android module's +`dependencies`, or to `commonMain.dependencies` in a Kotlin Multiplatform module: ```groovy implementation "ru.kode.uikit:uikit-components:$version" // Material3 backend // or implementation "ru.kode.uikit:uikit-components-foundation:$version" // Compose Foundation backend ``` +Android apps with `minSdk < 26` need [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) +enabled: dates are `kotlinx.datetime.LocalDate`, which uses `java.time` on Android. Set up the configuration. It's best to do this as high in the component hierarchy as possible (app theme, Activity): ```kotlin @@ -26,13 +37,24 @@ CompositionLocalProvider( ``` That completes the setup — you can now use any of the components. +Icons and texts in the date picker configuration are composable lambdas, so they work with any resource system: +```kotlin +// Android resources +TextFieldDatePickerConfiguration(leadingIcon = { painterResource(R.drawable.ic_calendar) }, /* … */) +ModalDatePickerConfiguration(title = { stringResource(R.string.pick_date) }, /* … */) +// Compose Multiplatform resources (org.jetbrains.compose.resources) +TextFieldDatePickerConfiguration(leadingIcon = { painterResource(Res.drawable.ic_calendar) }, /* … */) +ModalDatePickerConfiguration(title = { stringResource(Res.string.pick_date) }, /* … */) +``` +The library itself does not depend on Compose Multiplatform resources. + ## Choose a backend The library ships as three artifacts: | Artifact | Contains | Depends on | |---|---|---| -| `uikit-core` | configuration, shared state types, `TextField`, `TextFieldArea`, `PageIndicator`, shimmer | Compose UI/Foundation | -| `uikit-components` | Material3 backend: `Button`, `Checkbox`, `RadioButton`, sliders, `DatePicker`, `ModalBottomSheet` | `uikit-core`, Material3 | +| `uikit-core` | configuration, shared state types, `TextField`, `TextFieldArea`, `PageIndicator`, shimmer | Compose UI/Foundation, kotlinx-datetime | +| `uikit-components` | Material3 backend: `Button`, `Checkbox`, `RadioButton`, sliders, `DatePicker`, `ModalBottomSheet` | `uikit-core`, Material3 (androidx on Android, Compose Multiplatform elsewhere) | | `uikit-components-foundation` | the same components, drawn with Compose Foundation | `uikit-core`, `material-ripple` | Both backends expose the same API in `ru.kode.uikit.components`, so switching is a one-line dependency change. @@ -97,7 +119,7 @@ Releases run automatically through GitHub Actions (`.github/workflows/release.ym git tag 0.1.3 git push origin 0.1.3 ``` -The workflow runs `./gradlew publishAndReleaseToMavenCentral`. It requires the following secrets in the +The workflow runs `./gradlew publishAndReleaseToMavenCentral` on macOS (iOS klibs only build there). It requires the following secrets in the `release` environment: `NEXUS_USERTOKEN_NAME`, `NEXUS_USERTOKEN_PASSWORD`, `SIGNING_KEY_ID`, `SIGNING_PASSWORD`, `SIGNING_SECRET_KEY_RING_FILE_BASE64`. diff --git a/build.gradle.kts b/build.gradle.kts index 08b7605..a64cb4f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,9 @@ import com.vanniktech.maven.publish.MavenPublishBaseExtension -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { alias(libs.plugins.kotlinCompose) apply false - alias(libs.plugins.androidLibrary) apply false + alias(libs.plugins.kotlinMultiplatform) apply false + alias(libs.plugins.androidKmpLibrary) apply false alias(libs.plugins.androidApplication) apply false alias(libs.plugins.ksp) apply false alias(libs.plugins.vanniktech.maven.publish) apply false @@ -55,12 +54,6 @@ spotless { } subprojects { - tasks.withType { - compilerOptions { - jvmTarget.set(JvmTarget.JVM_17) - } - } - pluginManager.withPlugin("com.vanniktech.maven.publish") { configure { publishToMavenCentral() diff --git a/gradle.properties b/gradle.properties index e094696..d0e0460 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ android.useAndroidX=true org.gradle.parallel=true org.gradle.caching=true -versionName=0.3.0 +versionName=0.4.0 pomGroupId=ru.kode.uikit pomDescription=Shared UI-kit components pomUrl=https://github.com/appKODE/uikit diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2982b06..b3e3f7b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,6 +4,11 @@ agp = "9.2.1" coroutines = "1.11.0" compose = "1.11.4" composeMaterial3 = "1.4.0" +# JetBrains Compose Multiplatform 1.11.x = Jetpack Compose 1.11; CMP material3 1.9.0 = androidx material3 1.4.0. +cmp = "1.11.1" +cmpMaterial3 = "1.9.0" +kotlinxDatetime = "0.7.1" +androidxAnnotation = "1.9.1" spotless = "8.8.0" ktlint = "1.8.0" androidJdkDesugar = "2.1.5" @@ -24,6 +29,14 @@ compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = " compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" } compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "composeMaterial3" } compose-material-ripple = { module = "androidx.compose.material:material-ripple", version.ref = "compose" } +cmp-ui = { module = "org.jetbrains.compose.ui:ui", version.ref = "cmp" } +cmp-runtime = { module = "org.jetbrains.compose.runtime:runtime", version.ref = "cmp" } +cmp-foundation = { module = "org.jetbrains.compose.foundation:foundation", version.ref = "cmp" } +cmp-material-ripple = { module = "org.jetbrains.compose.material:material-ripple", version.ref = "cmp" } +cmp-material3 = { module = "org.jetbrains.compose.material3:material3", version.ref = "cmpMaterial3" } +kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" } +androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidxAnnotation" } +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } android-jdk-desugar = { module = "com.android.tools:desugar_jdk_libs", version.ref = "androidJdkDesugar" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" } showkase = { module = "com.airbnb.android:showkase", version.ref = "showkase" } @@ -47,8 +60,9 @@ compose = [ ] [plugins] +kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +androidKmpLibrary = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" } kotlinCompose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } -androidLibrary = { id = "com.android.library", version.ref = "agp" } androidApplication = { id = "com.android.application", version.ref = "agp" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } diff --git a/sample/src/main/kotlin/ru/kode/uikit/sample/PreviewUikitConfiguration.kt b/sample/src/main/kotlin/ru/kode/uikit/sample/PreviewUikitConfiguration.kt index 84e7ba6..0312824 100644 --- a/sample/src/main/kotlin/ru/kode/uikit/sample/PreviewUikitConfiguration.kt +++ b/sample/src/main/kotlin/ru/kode/uikit/sample/PreviewUikitConfiguration.kt @@ -5,6 +5,8 @@ import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.DpSize @@ -211,9 +213,9 @@ private fun previewSliderConfiguration() = SliderConfiguration( private fun previewDatePickerConfiguration() = DatePickerConfiguration( textField = TextFieldDatePickerConfiguration( - leadingIconRes = android.R.drawable.ic_menu_my_calendar, - trailingIconRes = android.R.drawable.arrow_down_float, - errorIconRes = android.R.drawable.ic_dialog_alert, + leadingIcon = { painterResource(android.R.drawable.ic_menu_my_calendar) }, + trailingIcon = { painterResource(android.R.drawable.arrow_down_float) }, + errorIcon = { painterResource(android.R.drawable.ic_dialog_alert) }, shape = PreviewTokens.fieldShape, contentPadding = PaddingValues(horizontal = 16.dp, vertical = 14.dp), textStyle = PreviewTokens.bodyStyle, @@ -241,7 +243,7 @@ private fun previewDatePickerConfiguration() = DatePickerConfiguration( disabledTrailingIconColor = PreviewTokens.disabled, ), inline = InlineDatePickerConfiguration( - iconRes = android.R.drawable.ic_menu_my_calendar, + icon = { painterResource(android.R.drawable.ic_menu_my_calendar) }, textStyle = PreviewTokens.bodyStyle, textColor = PreviewTokens.onSurface, disabledTextColor = PreviewTokens.disabled, @@ -249,9 +251,9 @@ private fun previewDatePickerConfiguration() = DatePickerConfiguration( disabledIconColor = PreviewTokens.disabled, ), modal = ModalDatePickerConfiguration( - titleRes = android.R.string.untitled, - confirmButtonTextRes = android.R.string.ok, - cancelButtonTextRes = android.R.string.cancel, + title = { stringResource(android.R.string.untitled) }, + confirmButtonText = { stringResource(android.R.string.ok) }, + cancelButtonText = { stringResource(android.R.string.cancel) }, bottomButtonsTextStyle = PreviewTokens.labelStyle, containerColor = PreviewTokens.surface, titleContentColor = PreviewTokens.onSurfaceVariant, diff --git a/sample/src/main/kotlin/ru/kode/uikit/sample/previews/DatePickerPreviews.kt b/sample/src/main/kotlin/ru/kode/uikit/sample/previews/DatePickerPreviews.kt index 53c431b..2f1bc4e 100644 --- a/sample/src/main/kotlin/ru/kode/uikit/sample/previews/DatePickerPreviews.kt +++ b/sample/src/main/kotlin/ru/kode/uikit/sample/previews/DatePickerPreviews.kt @@ -6,15 +6,15 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.airbnb.android.showkase.annotation.ShowkaseComposable +import kotlinx.datetime.LocalDate import ru.kode.uikit.components.TextFieldDatePicker import ru.kode.uikit.components.rememberDatePickerState import ru.kode.uikit.sample.PreviewTheme -import java.time.LocalDate private const val GROUP = "Date" // Fixed date keeps screenshots stable across days. -internal val PreviewDate: LocalDate = LocalDate.of(2026, 1, 15) +internal val PreviewDate: LocalDate = LocalDate(2026, 1, 15) @ShowkaseComposable(name = "TextFieldDatePicker — states", group = GROUP) @Preview diff --git a/uikit-components-foundation/build.gradle.kts b/uikit-components-foundation/build.gradle.kts index ad32dac..2c8d557 100644 --- a/uikit-components-foundation/build.gradle.kts +++ b/uikit-components-foundation/build.gradle.kts @@ -1,39 +1,48 @@ +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl + plugins { + alias(libs.plugins.kotlinMultiplatform) + alias(libs.plugins.androidKmpLibrary) alias(libs.plugins.kotlinCompose) - alias(libs.plugins.androidLibrary) alias(libs.plugins.vanniktech.maven.publish) } -android { - namespace = "ru.kode.uikit.components.foundation" - compileSdk = 36 +kotlin { + jvmToolchain(17) - defaultConfig { + android { + namespace = "ru.kode.uikit.components.foundation" + compileSdk = 36 minSdk = 21 - aarMetadata { - minCompileSdk = 21 - } - val versionName: String by project - version = versionName } + jvm() + iosArm64() + iosSimulatorArm64() + js { browser { testTask { enabled = false } } } - buildFeatures { - compose = true - } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { browser { testTask { enabled = false } } } - compileOptions { - isCoreLibraryDesugaringEnabled = true - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + // Every non-Android target shares the plain sheet dialog (nonAndroidMain). + applyDefaultHierarchyTemplate { + common { + group("nonAndroid") { + withJvm() + withIos() + withJs() + withWasmJs() + } + } } - kotlin { - jvmToolchain(17) + sourceSets { + commonMain.dependencies { + api(project(":uikit-core")) + implementation(libs.cmp.material.ripple) + implementation(libs.androidx.annotation) + } + androidMain.dependencies { + implementation(libs.compose.material.ripple) + } } } - -dependencies { - api(project(":uikit-core")) - implementation(libs.compose.material.ripple) - coreLibraryDesugaring(libs.android.jdk.desugar) -} diff --git a/uikit-components-foundation/src/androidMain/kotlin/ru/kode/uikit/components/internal/Platform.android.kt b/uikit-components-foundation/src/androidMain/kotlin/ru/kode/uikit/components/internal/Platform.android.kt new file mode 100644 index 0000000..2df2195 --- /dev/null +++ b/uikit-components-foundation/src/androidMain/kotlin/ru/kode/uikit/components/internal/Platform.android.kt @@ -0,0 +1,28 @@ +package ru.kode.uikit.components.internal + +import android.view.ViewGroup.LayoutParams.MATCH_PARENT +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.text.PlatformTextStyle +import androidx.compose.ui.window.DialogProperties +import androidx.compose.ui.window.DialogWindowProvider + +@Suppress("DEPRECATION") +internal actual val NoFontPaddingTextStyle: PlatformTextStyle? = PlatformTextStyle(includeFontPadding = false) + +internal actual fun sheetDialogProperties() = DialogProperties( + usePlatformDefaultWidth = false, + dismissOnClickOutside = false, + decorFitsSystemWindows = false, +) + +// Match the Material3 sheet window: full-screen, no platform dim (the sheet's scrim is the only dim). +@Composable +internal actual fun SheetDialogWindowSetup() { + val dialogWindow = (LocalView.current.parent as? DialogWindowProvider)?.window + SideEffect { + dialogWindow?.setDimAmount(0f) + dialogWindow?.setLayout(MATCH_PARENT, MATCH_PARENT) + } +} diff --git a/uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/Button.kt b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Button.kt similarity index 100% rename from uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/Button.kt rename to uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Button.kt diff --git a/uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/Checkbox.kt b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Checkbox.kt similarity index 100% rename from uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/Checkbox.kt rename to uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Checkbox.kt diff --git a/uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/DatePicker.kt b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/DatePicker.kt similarity index 89% rename from uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/DatePicker.kt rename to uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/DatePicker.kt index 2de6478..b756c52 100644 --- a/uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/DatePicker.kt +++ b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/DatePicker.kt @@ -1,6 +1,7 @@ +@file:OptIn(InternalUikitApi::class) + package ru.kode.uikit.components -import android.text.format.DateFormat import androidx.compose.foundation.Canvas import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -43,9 +44,6 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.PathBuilder import androidx.compose.ui.graphics.vector.path import androidx.compose.ui.graphics.vector.rememberVectorPainter -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.PlatformTextStyle import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight @@ -57,18 +55,27 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties +import kotlinx.datetime.DatePeriod +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate +import kotlinx.datetime.TimeZone +import kotlinx.datetime.YearMonth +import kotlinx.datetime.atStartOfDayIn +import kotlinx.datetime.isoDayNumber +import kotlinx.datetime.minusMonth +import kotlinx.datetime.number +import kotlinx.datetime.plus +import kotlinx.datetime.plusMonth +import kotlinx.datetime.todayIn +import kotlinx.datetime.yearMonth import ru.kode.uikit.components.configuration.LocalUikitConfiguration +import ru.kode.uikit.components.internal.NoFontPaddingTextStyle import ru.kode.uikit.components.internal.UikitIcon import ru.kode.uikit.components.internal.UikitText import ru.kode.uikit.components.internal.uikitRipple -import java.time.DayOfWeek -import java.time.LocalDate -import java.time.YearMonth -import java.time.ZoneId -import java.time.format.DateTimeFormatter -import java.time.temporal.WeekFields -import java.util.Locale -import java.time.format.TextStyle as JavaTextStyle +import ru.kode.uikit.core.internal.InternalUikitApi +import ru.kode.uikit.core.internal.PlatformDates +import kotlin.time.Clock @Composable fun TextFieldDatePicker( @@ -147,9 +154,9 @@ fun TextFieldDatePicker( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), ) { - configurationInternal.textField.leadingIconRes?.let { + configurationInternal.textField.leadingIcon?.let { UikitIcon( - painter = painterResource(it), + painter = it(), contentDescription = null, tint = remember(enabled, configurationInternal.textField) { if (enabled) { @@ -161,7 +168,7 @@ fun TextFieldDatePicker( ) } val formattedDate = remember(state.selectedDate) { - state.selectedDate.format(DateTimeFormatter.ofPattern(DAY_MONTH_YEAR_TIME_PATTERN)) + PlatformDates.format(state.selectedDate, DAY_MONTH_YEAR_TIME_PATTERN) } UikitText( modifier = Modifier.weight(1f), @@ -170,7 +177,7 @@ fun TextFieldDatePicker( color = textColor, ) UikitIcon( - painter = painterResource(configurationInternal.textField.trailingIconRes), + painter = configurationInternal.textField.trailingIcon(), contentDescription = null, tint = remember(enabled, configurationInternal.textField) { if (enabled) { @@ -182,7 +189,7 @@ fun TextFieldDatePicker( ) if (error) { UikitIcon( - painter = painterResource(configurationInternal.textField.errorIconRes), + painter = configurationInternal.textField.errorIcon(), contentDescription = null, tint = configurationInternal.textField.errorIconColor, ) @@ -251,7 +258,7 @@ private fun InlineDatePicker( horizontalArrangement = Arrangement.spacedBy(4.dp), ) { val formattedDate = remember(state.selectedDate) { - state.selectedDate.format(DateTimeFormatter.ofPattern(DAY_MONTH_YEAR_TIME_PATTERN)) + PlatformDates.format(state.selectedDate, DAY_MONTH_YEAR_TIME_PATTERN) } UikitText( text = formattedDate, @@ -260,7 +267,7 @@ private fun InlineDatePicker( ) UikitIcon( modifier = Modifier.size(24.dp), - painter = painterResource(configurationInternal.inline.iconRes), + painter = configurationInternal.inline.icon(), contentDescription = null, tint = remember(enabled, configurationInternal.inline) { if (enabled) { @@ -299,8 +306,7 @@ private fun ModalDatePicker( title: @Composable (ModalDatePickerConfiguration) -> Unit = { UikitDatePickerDefaults.Title(it) }, headline: @Composable (LocalDate) -> Unit = { UikitDatePickerDefaults.Headline(it) }, ) { - val locale = Locale.getDefault() - var displayedMonth by remember { mutableStateOf(YearMonth.from(date)) } + var displayedMonth by remember { mutableStateOf(date.yearMonth) } var showYearPicker by remember { mutableStateOf(false) } Dialog( @@ -327,21 +333,19 @@ private fun ModalDatePicker( } } MonthsNavigation( - text = displayedMonth.format( - DateTimeFormatter.ofPattern(DateFormat.getBestDateTimePattern(locale, "yMMMM"), locale), - ), + text = PlatformDates.monthYear(displayedMonth.year, displayedMonth.month.number), yearPickerVisible = showYearPicker, - previousAvailable = displayedMonth > YearMonth.of(yearRange.first, 1), - nextAvailable = displayedMonth < YearMonth.of(yearRange.last, 12), + previousAvailable = displayedMonth > YearMonth(yearRange.first, 1), + nextAvailable = displayedMonth < YearMonth(yearRange.last, 12), color = configuration.navigationContentColor, onYearPickerClick = { showYearPicker = !showYearPicker }, - onPreviousClick = { displayedMonth = displayedMonth.minusMonths(1) }, - onNextClick = { displayedMonth = displayedMonth.plusMonths(1) }, + onPreviousClick = { displayedMonth = displayedMonth.minusMonth() }, + onNextClick = { displayedMonth = displayedMonth.plusMonth() }, ) Box { - val firstDayOfWeek = WeekFields.of(locale).firstDayOfWeek + val firstDayOfWeek = PlatformDates.firstDayOfWeek() Column(Modifier.padding(horizontal = 12.dp)) { - WeekDays(firstDayOfWeek, locale, configuration.weekdayContentColor) + WeekDays(firstDayOfWeek, configuration.weekdayContentColor) Month(displayedMonth, firstDayOfWeek, date, selectableDates, configuration, onDateConfirm) } if (showYearPicker) { @@ -353,7 +357,7 @@ private fun ModalDatePicker( selectableDates = selectableDates, configuration = configuration, onYearSelected = { - displayedMonth = displayedMonth.withYear(it) + displayedMonth = YearMonth(it, displayedMonth.month) showYearPicker = false }, ) @@ -371,7 +375,7 @@ private fun ModalDatePicker( fun UikitDatePickerDefaults.Title(configuration: ModalDatePickerConfiguration) { UikitText( modifier = Modifier.padding(start = 24.dp, end = 12.dp, top = 16.dp), - text = stringResource(configuration.titleRes), + text = configuration.title(), style = TitleTextStyle, color = Color(0xFF000000).copy(alpha = 0.7f), ) @@ -382,7 +386,7 @@ fun UikitDatePickerDefaults.Title(configuration: ModalDatePickerConfiguration) { fun UikitDatePickerDefaults.Headline(date: LocalDate) { UikitText( modifier = Modifier.padding(start = 24.dp, end = 12.dp, bottom = 12.dp), - text = date.format(DateTimeFormatter.ofPattern(MODAL_HEADLINE_TIME_PATTERN)), + text = PlatformDates.format(date, MODAL_HEADLINE_TIME_PATTERN), style = HeadlineTextStyle, color = Color(0xFF000000), ) @@ -479,7 +483,7 @@ private fun NavButton(icon: ImageVector, color: Color, enabled: Boolean, onClick } @Composable -private fun WeekDays(firstDayOfWeek: DayOfWeek, locale: Locale, color: Color) { +private fun WeekDays(firstDayOfWeek: DayOfWeek, color: Color) { Row( modifier = Modifier.defaultMinSize(minHeight = MinTouchSize).fillMaxWidth(), horizontalArrangement = Arrangement.SpaceEvenly, @@ -488,7 +492,7 @@ private fun WeekDays(firstDayOfWeek: DayOfWeek, locale: Locale, color: Color) { repeat(DAYS_IN_WEEK) { Box(Modifier.size(MinTouchSize), contentAlignment = Alignment.Center) { UikitText( - text = firstDayOfWeek.plus(it.toLong()).getDisplayName(JavaTextStyle.NARROW_STANDALONE, locale), + text = PlatformDates.narrowWeekdayName(DayOfWeek((firstDayOfWeek.isoDayNumber - 1 + it) % DAYS_IN_WEEK + 1)), modifier = Modifier.wrapContentSize(), style = BodyLargeCenteredTextStyle, color = color, @@ -507,8 +511,9 @@ private fun Month( configuration: ModalDatePickerConfiguration, onDaySelected: (LocalDate) -> Unit, ) { - val leadingBlanks = (month.atDay(1).dayOfWeek.value - firstDayOfWeek.value + DAYS_IN_WEEK) % DAYS_IN_WEEK - val today = LocalDate.now() + val leadingBlanks = + (month.firstDay.dayOfWeek.isoDayNumber - firstDayOfWeek.isoDayNumber + DAYS_IN_WEEK) % DAYS_IN_WEEK + val today = today() Column( modifier = Modifier.requiredHeight(MinTouchSize * MAX_CALENDAR_ROWS), verticalArrangement = Arrangement.SpaceEvenly, @@ -521,10 +526,10 @@ private fun Month( ) { for (day in 0 until DAYS_IN_WEEK) { val dayOfMonth = week * DAYS_IN_WEEK + day - leadingBlanks + 1 - if (dayOfMonth !in 1..month.lengthOfMonth()) { + if (dayOfMonth !in 1..month.numberOfDays) { Spacer(Modifier.size(MinTouchSize)) } else { - val cellDate = month.atDay(dayOfMonth) + val cellDate = month.firstDay.plus(DatePeriod(days = dayOfMonth - 1)) DayCell( date = cellDate, selected = cellDate == selectedDate, @@ -585,7 +590,7 @@ private fun DayCell( .requiredSize(40.dp), contentAlignment = Alignment.Center, ) { - UikitText(text = date.dayOfMonth.toString(), style = BodyLargeCenteredTextStyle, color = contentColor) + UikitText(text = date.day.toString(), style = BodyLargeCenteredTextStyle, color = contentColor) } } } @@ -612,7 +617,7 @@ private fun YearPicker( val contentColor = when { !selectable -> configuration.disabledYearContentColor selected -> configuration.selectedYearContentColor - year == LocalDate.now().year -> configuration.currentYearContentColor + year == today().year -> configuration.currentYearContentColor else -> configuration.yearContentColor } Box(contentAlignment = Alignment.Center) { @@ -636,7 +641,9 @@ private fun YearPicker( } } -private fun LocalDate.toUtcMillis(): Long = atStartOfDay(defaultZoneId).toInstant().toEpochMilli() +private fun LocalDate.toUtcMillis(): Long = atStartOfDayIn(TimeZone.UTC).toEpochMilliseconds() + +private fun today(): LocalDate = Clock.System.todayIn(TimeZone.currentSystemDefault()) private fun materialIcon(name: String, pathBuilder: PathBuilder.() -> Unit): ImageVector = ImageVector.Builder(name, 24.dp, 24.dp, 24f, 24f, autoMirror = true) @@ -687,9 +694,8 @@ private val HeadlineTextStyle = TextStyle( ) // M3 typography defaults (tokens/TypographyTokens.kt). -@Suppress("DEPRECATION") private val M3DefaultTextStyle = TextStyle( - platformStyle = PlatformTextStyle(includeFontPadding = false), + platformStyle = NoFontPaddingTextStyle, lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None), fontFamily = FontFamily.SansSerif, ) @@ -707,6 +713,5 @@ private val LabelLargeTextStyle = M3DefaultTextStyle.copy( letterSpacing = 0.1.sp, ) -private val defaultZoneId = ZoneId.of("UTC") private const val DAY_MONTH_YEAR_TIME_PATTERN = "dd.MM.yyyy" private const val MODAL_HEADLINE_TIME_PATTERN = "MMM d, yyyy" diff --git a/uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt similarity index 89% rename from uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt rename to uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt index ddb80b4..64ef9d9 100644 --- a/uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt +++ b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt @@ -1,6 +1,5 @@ package ru.kode.uikit.components -import android.view.ViewGroup.LayoutParams.MATCH_PARENT import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.tween import androidx.compose.foundation.background @@ -22,7 +21,6 @@ import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.layout.windowInsetsBottomHeight import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableStateOf @@ -34,13 +32,12 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.layout.onSizeChanged -import androidx.compose.ui.platform.LocalView import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.window.Dialog -import androidx.compose.ui.window.DialogProperties -import androidx.compose.ui.window.DialogWindowProvider import kotlinx.coroutines.launch import ru.kode.uikit.components.configuration.LocalUikitConfiguration +import ru.kode.uikit.components.internal.SheetDialogWindowSetup +import ru.kode.uikit.components.internal.sheetDialogProperties import kotlin.math.roundToInt @Composable @@ -66,18 +63,9 @@ fun ModalBottomSheet( Dialog( onDismissRequest = onDismissRequest, - properties = DialogProperties( - usePlatformDefaultWidth = false, - dismissOnClickOutside = false, - decorFitsSystemWindows = false, - ), + properties = sheetDialogProperties(), ) { - // Match the Material3 sheet window: full-screen, no platform dim (the scrim below is the only dim). - val dialogWindow = (LocalView.current.parent as? DialogWindowProvider)?.window - SideEffect { - dialogWindow?.setDimAmount(0f) - dialogWindow?.setLayout(MATCH_PARENT, MATCH_PARENT) - } + SheetDialogWindowSetup() val sheetShape = RoundedCornerShape( topStart = configurationInternal.cornerRadius, topEnd = configurationInternal.cornerRadius, diff --git a/uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/RadioButton.kt b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/RadioButton.kt similarity index 100% rename from uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/RadioButton.kt rename to uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/RadioButton.kt diff --git a/uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/Slider.kt b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Slider.kt similarity index 100% rename from uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/Slider.kt rename to uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Slider.kt diff --git a/uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/internal/FoundationPrimitives.kt b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/internal/FoundationPrimitives.kt similarity index 100% rename from uikit-components-foundation/src/main/kotlin/ru/kode/uikit/components/internal/FoundationPrimitives.kt rename to uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/internal/FoundationPrimitives.kt diff --git a/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/internal/Platform.kt b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/internal/Platform.kt new file mode 100644 index 0000000..989d7de --- /dev/null +++ b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/internal/Platform.kt @@ -0,0 +1,15 @@ +package ru.kode.uikit.components.internal + +import androidx.compose.runtime.Composable +import androidx.compose.ui.text.PlatformTextStyle +import androidx.compose.ui.window.DialogProperties + +/** Full-width sheet dialog that doesn't dismiss on outside clicks (the sheet's own scrim handles that). */ +internal expect fun sheetDialogProperties(): DialogProperties + +/** Platform window tweaks for the sheet dialog; call inside the Dialog content. */ +@Composable +internal expect fun SheetDialogWindowSetup() + +/** M3 typography's `includeFontPadding = false` (Android-only knob; null elsewhere). */ +internal expect val NoFontPaddingTextStyle: PlatformTextStyle? diff --git a/uikit-components-foundation/src/main/AndroidManifest.xml b/uikit-components-foundation/src/main/AndroidManifest.xml deleted file mode 100644 index 227314e..0000000 --- a/uikit-components-foundation/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/uikit-components-foundation/src/nonAndroidMain/kotlin/ru/kode/uikit/components/internal/Platform.nonAndroid.kt b/uikit-components-foundation/src/nonAndroidMain/kotlin/ru/kode/uikit/components/internal/Platform.nonAndroid.kt new file mode 100644 index 0000000..15758de --- /dev/null +++ b/uikit-components-foundation/src/nonAndroidMain/kotlin/ru/kode/uikit/components/internal/Platform.nonAndroid.kt @@ -0,0 +1,15 @@ +package ru.kode.uikit.components.internal + +import androidx.compose.runtime.Composable +import androidx.compose.ui.text.PlatformTextStyle +import androidx.compose.ui.window.DialogProperties + +internal actual val NoFontPaddingTextStyle: PlatformTextStyle? = null + +internal actual fun sheetDialogProperties() = DialogProperties( + usePlatformDefaultWidth = false, + dismissOnClickOutside = false, +) + +@Composable +internal actual fun SheetDialogWindowSetup() = Unit diff --git a/uikit-components/build.gradle.kts b/uikit-components/build.gradle.kts index ddb3a96..e087dd0 100644 --- a/uikit-components/build.gradle.kts +++ b/uikit-components/build.gradle.kts @@ -1,39 +1,37 @@ +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl + plugins { + alias(libs.plugins.kotlinMultiplatform) + alias(libs.plugins.androidKmpLibrary) alias(libs.plugins.kotlinCompose) - alias(libs.plugins.androidLibrary) alias(libs.plugins.vanniktech.maven.publish) } -android { - namespace = "ru.kode.uikit.components" - compileSdk = 36 +kotlin { + jvmToolchain(17) - defaultConfig { + android { + namespace = "ru.kode.uikit.components" + compileSdk = 36 minSdk = 21 - aarMetadata { - minCompileSdk = 21 - } - val versionName: String by project - version = versionName } + jvm() + iosArm64() + iosSimulatorArm64() + js { browser { testTask { enabled = false } } } - buildFeatures { - compose = true - } - - compileOptions { - isCoreLibraryDesugaringEnabled = true - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { browser { testTask { enabled = false } } } - kotlin { - jvmToolchain(17) + sourceSets { + commonMain.dependencies { + api(project(":uikit-core")) + implementation(libs.cmp.material3) + implementation(libs.androidx.annotation) + } + androidMain.dependencies { + // CMP material3 already resolves to androidx material3 on Android; pin it explicitly. + implementation(libs.compose.material3) + } } } - -dependencies { - api(project(":uikit-core")) - implementation(libs.compose.material3) - coreLibraryDesugaring(libs.android.jdk.desugar) -} diff --git a/uikit-components/src/main/kotlin/ru/kode/uikit/components/Button.kt b/uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/Button.kt similarity index 100% rename from uikit-components/src/main/kotlin/ru/kode/uikit/components/Button.kt rename to uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/Button.kt diff --git a/uikit-components/src/main/kotlin/ru/kode/uikit/components/Checkbox.kt b/uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/Checkbox.kt similarity index 100% rename from uikit-components/src/main/kotlin/ru/kode/uikit/components/Checkbox.kt rename to uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/Checkbox.kt diff --git a/uikit-components/src/main/kotlin/ru/kode/uikit/components/DatePicker.kt b/uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/DatePicker.kt similarity index 92% rename from uikit-components/src/main/kotlin/ru/kode/uikit/components/DatePicker.kt rename to uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/DatePicker.kt index 57720e6..dce0674 100644 --- a/uikit-components/src/main/kotlin/ru/kode/uikit/components/DatePicker.kt +++ b/uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/DatePicker.kt @@ -1,4 +1,4 @@ -@file:OptIn(ExperimentalMaterial3Api::class) +@file:OptIn(ExperimentalMaterial3Api::class, InternalUikitApi::class) package ru.kode.uikit.components @@ -32,8 +32,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.TextUnit @@ -41,11 +39,14 @@ import androidx.compose.ui.unit.TextUnitType import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.window.DialogProperties +import kotlinx.datetime.LocalDate +import kotlinx.datetime.TimeZone +import kotlinx.datetime.atStartOfDayIn +import kotlinx.datetime.toLocalDateTime import ru.kode.uikit.components.configuration.LocalUikitConfiguration -import java.time.Instant -import java.time.LocalDate -import java.time.ZoneId -import java.time.format.DateTimeFormatter +import ru.kode.uikit.core.internal.InternalUikitApi +import ru.kode.uikit.core.internal.PlatformDates +import kotlin.time.Instant @Composable fun TextFieldDatePicker( @@ -126,9 +127,9 @@ fun TextFieldDatePicker( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), ) { - configurationInternal.textField.leadingIconRes?.let { + configurationInternal.textField.leadingIcon?.let { Icon( - painter = painterResource(it), + painter = it(), contentDescription = null, tint = remember(enabled, configurationInternal.textField) { if (enabled) { @@ -140,7 +141,7 @@ fun TextFieldDatePicker( ) } val formattedDate = remember(state.selectedDate) { - state.selectedDate.format(DateTimeFormatter.ofPattern(DAY_MONTH_YEAR_TIME_PATTERN)) + PlatformDates.format(state.selectedDate, DAY_MONTH_YEAR_TIME_PATTERN) } Text( modifier = Modifier.weight(1f), @@ -149,7 +150,7 @@ fun TextFieldDatePicker( color = textColor, ) Icon( - painter = painterResource(configurationInternal.textField.trailingIconRes), + painter = configurationInternal.textField.trailingIcon(), contentDescription = null, tint = remember(enabled, configurationInternal.textField) { if (enabled) { @@ -161,7 +162,7 @@ fun TextFieldDatePicker( ) if (error) { Icon( - painter = painterResource(configurationInternal.textField.errorIconRes), + painter = configurationInternal.textField.errorIcon(), contentDescription = null, tint = configurationInternal.textField.errorIconColor, ) @@ -232,7 +233,7 @@ private fun InlineDatePicker( horizontalArrangement = Arrangement.spacedBy(4.dp), ) { val formattedDate = remember(state.selectedDate) { - state.selectedDate.format(DateTimeFormatter.ofPattern(DAY_MONTH_YEAR_TIME_PATTERN)) + PlatformDates.format(state.selectedDate, DAY_MONTH_YEAR_TIME_PATTERN) } Text( text = formattedDate, @@ -241,7 +242,7 @@ private fun InlineDatePicker( ) Icon( modifier = Modifier.size(24.dp), - painter = painterResource(configurationInternal.inline.iconRes), + painter = configurationInternal.inline.icon(), contentDescription = null, tint = remember(enabled, configurationInternal.inline) { if (enabled) { @@ -280,7 +281,7 @@ private fun ModalDatePicker( headline: @Composable (LocalDate) -> Unit = { UikitDatePickerDefaults.Headline(it) }, ) { val state = androidx.compose.material3.rememberDatePickerState( - initialSelectedDateMillis = date.atStartOfDay(defaultZoneId).toInstant().toEpochMilli(), + initialSelectedDateMillis = date.atStartOfDayIn(TimeZone.UTC).toEpochMilliseconds(), yearRange = yearRange, selectableDates = remember(selectableDates) { selectableDates.toMaterial() }, ) @@ -317,7 +318,7 @@ private fun ModalDatePicker( fun UikitDatePickerDefaults.Title(configuration: ModalDatePickerConfiguration) { Text( modifier = Modifier.padding(start = 24.dp, end = 12.dp, top = 16.dp), - text = stringResource(configuration.titleRes), + text = configuration.title(), style = TextStyle( fontWeight = FontWeight.Normal, fontSize = 12.sp, @@ -333,7 +334,7 @@ fun UikitDatePickerDefaults.Title(configuration: ModalDatePickerConfiguration) { fun UikitDatePickerDefaults.Headline(date: LocalDate) { Text( modifier = Modifier.padding(start = 24.dp, end = 12.dp, bottom = 12.dp), - text = date.format(DateTimeFormatter.ofPattern(MODAL_HEADLINE_TIME_PATTERN)), + text = PlatformDates.format(date, MODAL_HEADLINE_TIME_PATTERN), style = TextStyle( fontWeight = FontWeight.SemiBold, fontSize = 28.sp, @@ -383,11 +384,6 @@ private fun SelectableDates.toMaterial() = object : androidx.compose.material3.S override fun isSelectableYear(year: Int) = this@toMaterial.isSelectableYear(year) } -private fun Long.toLocalDate() = Instant - .ofEpochMilli(this) - .atZone(defaultZoneId) - .toLocalDate() - -private val defaultZoneId = ZoneId.of("UTC") +private fun Long.toLocalDate() = Instant.fromEpochMilliseconds(this).toLocalDateTime(TimeZone.UTC).date private const val DAY_MONTH_YEAR_TIME_PATTERN = "dd.MM.yyyy" private const val MODAL_HEADLINE_TIME_PATTERN = "MMM d, yyyy" diff --git a/uikit-components/src/main/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt b/uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt similarity index 100% rename from uikit-components/src/main/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt rename to uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/ModalBottomSheet.kt diff --git a/uikit-components/src/main/kotlin/ru/kode/uikit/components/RadioButton.kt b/uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/RadioButton.kt similarity index 100% rename from uikit-components/src/main/kotlin/ru/kode/uikit/components/RadioButton.kt rename to uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/RadioButton.kt diff --git a/uikit-components/src/main/kotlin/ru/kode/uikit/components/Slider.kt b/uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/Slider.kt similarity index 100% rename from uikit-components/src/main/kotlin/ru/kode/uikit/components/Slider.kt rename to uikit-components/src/commonMain/kotlin/ru/kode/uikit/components/Slider.kt diff --git a/uikit-components/src/main/AndroidManifest.xml b/uikit-components/src/main/AndroidManifest.xml deleted file mode 100644 index 227314e..0000000 --- a/uikit-components/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/uikit-core/build.gradle.kts b/uikit-core/build.gradle.kts index 9fa3e5e..a38f2db 100644 --- a/uikit-core/build.gradle.kts +++ b/uikit-core/build.gradle.kts @@ -1,40 +1,59 @@ +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType + plugins { + alias(libs.plugins.kotlinMultiplatform) + alias(libs.plugins.androidKmpLibrary) alias(libs.plugins.kotlinCompose) - alias(libs.plugins.androidLibrary) alias(libs.plugins.vanniktech.maven.publish) } -android { - namespace = "ru.kode.uikit.core" - compileSdk = 36 +kotlin { + jvmToolchain(17) - defaultConfig { + android { + namespace = "ru.kode.uikit.core" + compileSdk = 36 minSdk = 21 - aarMetadata { - minCompileSdk = 21 - } - val versionName: String by project - version = versionName } + jvm() + iosArm64() + iosSimulatorArm64() + js { browser { testTask { enabled = false } } } - buildFeatures { - compose = true - } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { browser { testTask { enabled = false } } } - compileOptions { - isCoreLibraryDesugaringEnabled = true - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + // android + jvm share the java.time-based PlatformDates actual (jvmAndroidMain). + applyDefaultHierarchyTemplate { + common { + group("jvmAndroid") { + withJvm() + withCompilations { it.platformType == KotlinPlatformType.androidJvm } + } + } } - kotlin { - jvmToolchain(17) + compilerOptions { + freeCompilerArgs.add("-Xexpect-actual-classes") } -} -dependencies { - api(libs.compose.ui) - api(libs.compose.runtime) - api(libs.compose.foundation) - coreLibraryDesugaring(libs.android.jdk.desugar) + sourceSets { + commonMain.dependencies { + api(libs.cmp.ui) + api(libs.cmp.runtime) + api(libs.cmp.foundation) + api(libs.kotlinx.datetime) + implementation(libs.androidx.annotation) + } + androidMain.dependencies { + // Pin the exact Jetpack Compose version Android consumers got before the KMP move. + api(libs.compose.ui) + api(libs.compose.runtime) + api(libs.compose.foundation) + } + commonTest.dependencies { + implementation(libs.kotlin.test) + } + } } diff --git a/uikit-core/src/androidMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.android.kt b/uikit-core/src/androidMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.android.kt new file mode 100644 index 0000000..132a48c --- /dev/null +++ b/uikit-core/src/androidMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.android.kt @@ -0,0 +1,6 @@ +package ru.kode.uikit.core.internal + +import android.text.format.DateFormat +import java.util.Locale + +internal actual fun monthYearPattern(locale: Locale): String = DateFormat.getBestDateTimePattern(locale, "yMMMM") diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/BottomSheetConfiguration.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/BottomSheetConfiguration.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/BottomSheetConfiguration.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/BottomSheetConfiguration.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/ButtonConfiguration.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/ButtonConfiguration.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/ButtonConfiguration.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/ButtonConfiguration.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/CheckboxConfiguration.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/CheckboxConfiguration.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/CheckboxConfiguration.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/CheckboxConfiguration.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/DatePickerState.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/DatePickerState.kt similarity index 85% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/DatePickerState.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/DatePickerState.kt index 0882206..a2f8d59 100644 --- a/uikit-core/src/main/kotlin/ru/kode/uikit/components/DatePickerState.kt +++ b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/DatePickerState.kt @@ -1,7 +1,5 @@ package ru.kode.uikit.components -import androidx.annotation.DrawableRes -import androidx.annotation.StringRes import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable @@ -9,12 +7,16 @@ import androidx.compose.runtime.Stable import androidx.compose.runtime.remember import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.text.TextStyle -import java.time.LocalDate +import kotlinx.datetime.LocalDate +import kotlinx.datetime.TimeZone +import kotlinx.datetime.todayIn +import kotlin.time.Clock @Composable fun rememberDatePickerState( - initialSelectedDate: LocalDate = LocalDate.now(), + initialSelectedDate: LocalDate = Clock.System.todayIn(TimeZone.currentSystemDefault()), yearRange: IntRange = UikitDatePickerDefaults.YearRange, selectableDates: SelectableDates = UikitDatePickerDefaults.AllDates, ): DatePickerState = remember { @@ -53,9 +55,9 @@ data class DatePickerConfiguration( @Immutable data class TextFieldDatePickerConfiguration( - @DrawableRes val leadingIconRes: Int?, - @DrawableRes val trailingIconRes: Int, - @DrawableRes val errorIconRes: Int, + val leadingIcon: (@Composable () -> Painter)?, + val trailingIcon: @Composable () -> Painter, + val errorIcon: @Composable () -> Painter, val shape: Shape, val contentPadding: PaddingValues, val textStyle: TextStyle, @@ -85,7 +87,7 @@ data class TextFieldDatePickerConfiguration( @Immutable data class InlineDatePickerConfiguration( - @DrawableRes val iconRes: Int, + val icon: @Composable () -> Painter, val textStyle: TextStyle, val textColor: Color, val disabledTextColor: Color, @@ -95,9 +97,9 @@ data class InlineDatePickerConfiguration( @Immutable data class ModalDatePickerConfiguration( - @StringRes val titleRes: Int, - @StringRes val confirmButtonTextRes: Int, - @StringRes val cancelButtonTextRes: Int, + val title: @Composable () -> String, + val confirmButtonText: @Composable () -> String, + val cancelButtonText: @Composable () -> String, val bottomButtonsTextStyle: TextStyle, val containerColor: Color, val titleContentColor: Color, diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/PageIndicator.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/PageIndicator.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/PageIndicator.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/PageIndicator.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/RadioButtonConfiguration.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/RadioButtonConfiguration.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/RadioButtonConfiguration.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/RadioButtonConfiguration.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/SliderState.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/SliderState.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/SliderState.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/SliderState.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/TextField.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/TextField.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/TextField.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/TextField.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/TextFieldArea.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/TextFieldArea.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/TextFieldArea.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/TextFieldArea.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/configuration/UikitConfiguration.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/configuration/UikitConfiguration.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/configuration/UikitConfiguration.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/configuration/UikitConfiguration.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/shimmer/Placeholder.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/shimmer/Placeholder.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/shimmer/Placeholder.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/shimmer/Placeholder.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/shimmer/PlaceholderHighlight.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/shimmer/PlaceholderHighlight.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/shimmer/PlaceholderHighlight.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/shimmer/PlaceholderHighlight.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/shimmer/Shimmer.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/shimmer/Shimmer.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/shimmer/Shimmer.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/shimmer/Shimmer.kt diff --git a/uikit-core/src/main/kotlin/ru/kode/uikit/components/shimmer/ShimmerModifiers.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/shimmer/ShimmerModifiers.kt similarity index 100% rename from uikit-core/src/main/kotlin/ru/kode/uikit/components/shimmer/ShimmerModifiers.kt rename to uikit-core/src/commonMain/kotlin/ru/kode/uikit/components/shimmer/ShimmerModifiers.kt diff --git a/uikit-core/src/commonMain/kotlin/ru/kode/uikit/core/internal/InternalUikitApi.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/core/internal/InternalUikitApi.kt new file mode 100644 index 0000000..6255268 --- /dev/null +++ b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/core/internal/InternalUikitApi.kt @@ -0,0 +1,10 @@ +package ru.kode.uikit.core.internal + +/** Shared between the uikit backends; not a stable public API. */ +@RequiresOptIn( + message = "Internal uikit API shared between backends. It may change without notice.", + level = RequiresOptIn.Level.WARNING, +) +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) +annotation class InternalUikitApi diff --git a/uikit-core/src/commonMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.kt b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.kt new file mode 100644 index 0000000..5259bdb --- /dev/null +++ b/uikit-core/src/commonMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.kt @@ -0,0 +1,19 @@ +package ru.kode.uikit.core.internal + +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate + +/** Locale-aware date text for the date pickers, using the platform's current locale. */ +@InternalUikitApi +expect object PlatformDates { + /** Formats [date] with an ICU/java.time-style [pattern]; supports `d`, `dd`, `MM`, `MMM`, `MMMM`, `yyyy`. */ + fun format(date: LocalDate, pattern: String): String + + /** Localized month + year title, the `yMMMM` skeleton (e.g. "January 2026"). [month] is 1-based. */ + fun monthYear(year: Int, month: Int): String + + fun firstDayOfWeek(): DayOfWeek + + /** Narrow standalone weekday name (e.g. "M"). */ + fun narrowWeekdayName(dayOfWeek: DayOfWeek): String +} diff --git a/uikit-core/src/commonTest/kotlin/ru/kode/uikit/core/internal/PlatformDatesTest.kt b/uikit-core/src/commonTest/kotlin/ru/kode/uikit/core/internal/PlatformDatesTest.kt new file mode 100644 index 0000000..ff75d6e --- /dev/null +++ b/uikit-core/src/commonTest/kotlin/ru/kode/uikit/core/internal/PlatformDatesTest.kt @@ -0,0 +1,32 @@ +package ru.kode.uikit.core.internal + +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +@OptIn(InternalUikitApi::class) +class PlatformDatesTest { + private val date = LocalDate(2026, 1, 15) + + @Test + fun numericPattern() = assertEquals("15.01.2026", PlatformDates.format(date, "dd.MM.yyyy")) + + @Test + fun monthNamePatternKeepsDayAndYear() { + val text = PlatformDates.format(date, "MMM d, yyyy") + assertTrue(text.contains("15") && text.contains("2026"), text) + } + + @Test + fun monthYearContainsYear() = assertTrue(PlatformDates.monthYear(2026, 1).contains("2026")) + + @Test + fun firstDayOfWeekIsValid() = assertTrue(PlatformDates.firstDayOfWeek() in DayOfWeek.entries) + + @Test + fun narrowWeekdayNamesAreNonBlank() = DayOfWeek.entries.forEach { + assertTrue(PlatformDates.narrowWeekdayName(it).isNotBlank(), it.name) + } +} diff --git a/uikit-core/src/iosMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.ios.kt b/uikit-core/src/iosMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.ios.kt new file mode 100644 index 0000000..0bcb847 --- /dev/null +++ b/uikit-core/src/iosMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.ios.kt @@ -0,0 +1,40 @@ +package ru.kode.uikit.core.internal + +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate +import kotlinx.datetime.TimeZone +import kotlinx.datetime.atStartOfDayIn +import kotlinx.datetime.isoDayNumber +import platform.Foundation.NSCalendar +import platform.Foundation.NSDate +import platform.Foundation.NSDateFormatter +import platform.Foundation.NSLocale +import platform.Foundation.NSTimeZone +import platform.Foundation.currentLocale +import platform.Foundation.dateWithTimeIntervalSince1970 +import platform.Foundation.timeZoneWithName + +@InternalUikitApi +actual object PlatformDates { + actual fun format(date: LocalDate, pattern: String): String = + formatter().apply { dateFormat = pattern }.stringFromDate(date.toNSDate()) + + actual fun monthYear(year: Int, month: Int): String = formatter().apply { + setLocalizedDateFormatFromTemplate("yMMMM") + }.stringFromDate(LocalDate(year, month, 1).toNSDate()) + + // NSCalendar.firstWeekday: 1 = Sunday ... 7 = Saturday. + actual fun firstDayOfWeek(): DayOfWeek = DayOfWeek((NSCalendar.currentCalendar.firstWeekday.toInt() + 5) % 7 + 1) + + // Symbols are indexed from Sunday. + actual fun narrowWeekdayName(dayOfWeek: DayOfWeek): String = + formatter().veryShortStandaloneWeekdaySymbols[dayOfWeek.isoDayNumber % 7] as String + + private fun formatter() = NSDateFormatter().apply { + locale = NSLocale.currentLocale + timeZone = NSTimeZone.timeZoneWithName("UTC")!! + } + + private fun LocalDate.toNSDate(): NSDate = + NSDate.dateWithTimeIntervalSince1970(atStartOfDayIn(TimeZone.UTC).epochSeconds.toDouble()) +} diff --git a/uikit-core/src/jvmAndroidMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvmAndroid.kt b/uikit-core/src/jvmAndroidMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvmAndroid.kt new file mode 100644 index 0000000..8e2dd65 --- /dev/null +++ b/uikit-core/src/jvmAndroidMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvmAndroid.kt @@ -0,0 +1,30 @@ +package ru.kode.uikit.core.internal + +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate +import kotlinx.datetime.isoDayNumber +import kotlinx.datetime.toJavaLocalDate +import java.time.YearMonth +import java.time.format.DateTimeFormatter +import java.time.format.TextStyle +import java.time.temporal.WeekFields +import java.util.Locale + +/** Best `yMMMM` pattern for [locale]; Android asks the platform, plain JVM falls back to a fixed pattern. */ +internal expect fun monthYearPattern(locale: Locale): String + +@InternalUikitApi +actual object PlatformDates { + actual fun format(date: LocalDate, pattern: String): String = + date.toJavaLocalDate().format(DateTimeFormatter.ofPattern(pattern)) + + actual fun monthYear(year: Int, month: Int): String { + val locale = Locale.getDefault() + return YearMonth.of(year, month).format(DateTimeFormatter.ofPattern(monthYearPattern(locale), locale)) + } + + actual fun firstDayOfWeek(): DayOfWeek = DayOfWeek(WeekFields.of(Locale.getDefault()).firstDayOfWeek.value) + + actual fun narrowWeekdayName(dayOfWeek: DayOfWeek): String = + java.time.DayOfWeek.of(dayOfWeek.isoDayNumber).getDisplayName(TextStyle.NARROW_STANDALONE, Locale.getDefault()) +} diff --git a/uikit-core/src/jvmMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvm.kt b/uikit-core/src/jvmMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvm.kt new file mode 100644 index 0000000..fb59fb2 --- /dev/null +++ b/uikit-core/src/jvmMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvm.kt @@ -0,0 +1,6 @@ +package ru.kode.uikit.core.internal + +import java.util.Locale + +// ponytail: fixed pattern; Java 19+ DateTimeFormatter.ofLocalizedPattern("yMMMM") once the toolchain moves past 17. +internal actual fun monthYearPattern(locale: Locale): String = "LLLL yyyy" diff --git a/uikit-core/src/main/AndroidManifest.xml b/uikit-core/src/main/AndroidManifest.xml deleted file mode 100644 index 227314e..0000000 --- a/uikit-core/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/uikit-core/src/webMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.web.kt b/uikit-core/src/webMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.web.kt new file mode 100644 index 0000000..9af5a07 --- /dev/null +++ b/uikit-core/src/webMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.web.kt @@ -0,0 +1,44 @@ +package ru.kode.uikit.core.internal + +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate +import kotlinx.datetime.isoDayNumber +import kotlinx.datetime.number + +@InternalUikitApi +actual object PlatformDates { + actual fun format(date: LocalDate, pattern: String): String = Regex("y+|M+|d+").replace(pattern) { + val token = it.value + when { + token == "MMMM" -> intlMonth(date.year, date.month.number, "long") + token == "MMM" -> intlMonth(date.year, date.month.number, "short") + token.startsWith("M") -> date.month.number.toString().padStart(token.length, '0') + token.startsWith("d") -> date.day.toString().padStart(token.length, '0') + else -> date.year.toString().padStart(token.length, '0') + } + } + + actual fun monthYear(year: Int, month: Int): String = intlMonthYear(year, month) + + actual fun firstDayOfWeek(): DayOfWeek = DayOfWeek(intlFirstDayOfWeek()) + + actual fun narrowWeekdayName(dayOfWeek: DayOfWeek): String = intlNarrowWeekday(dayOfWeek.isoDayNumber) +} + +private fun intlMonth(year: Int, month: Int, style: String): String = js( + "new Intl.DateTimeFormat(undefined, { month: style, timeZone: 'UTC' }).format(new Date(Date.UTC(year, month - 1, 1)))", +) + +private fun intlMonthYear(year: Int, month: Int): String = js( + "new Intl.DateTimeFormat(undefined, { year: 'numeric', month: 'long', timeZone: 'UTC' }).format(new Date(Date.UTC(year, month - 1, 1)))", +) + +// 2024-01-01 is a Monday, so ISO day n is January n. +private fun intlNarrowWeekday(isoDay: Int): String = js( + "new Intl.DateTimeFormat(undefined, { weekday: 'narrow', timeZone: 'UTC' }).format(new Date(Date.UTC(2024, 0, isoDay)))", +) + +// Intl.Locale weekInfo (getWeekInfo() in newer engines) uses ISO numbering; default to Monday where unsupported. +private fun intlFirstDayOfWeek(): Int = js( + "(function () { try { var l = new Intl.Locale(Intl.DateTimeFormat().resolvedOptions().locale); var w = l.getWeekInfo ? l.getWeekInfo() : l.weekInfo; return (w && w.firstDay) || 1; } catch (e) { return 1; } })()", +) From 1a668712f8b07f67ae0c7f418838350ef0c6c044 Mon Sep 17 00:00:00 2001 From: rinekri Date: Mon, 9 Nov 2026 16:40:41 +0000 Subject: [PATCH 2/3] Drop ponytail markers from comments --- .../src/commonMain/kotlin/ru/kode/uikit/components/Slider.kt | 4 ++-- .../kotlin/ru/kode/uikit/core/internal/PlatformDates.jvm.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Slider.kt b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Slider.kt index 40689dc..f80b8c0 100644 --- a/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Slider.kt +++ b/uikit-components-foundation/src/commonMain/kotlin/ru/kode/uikit/components/Slider.kt @@ -323,7 +323,7 @@ private fun DrawScope.drawTrack( activeColor: Color, inactiveColor: Color, ) { - // ponytail: the gap uses the configured thumb width, not the measured one, so a custom thumb slot of another + // The gap uses the configured thumb width, not the measured one, so a custom thumb slot of another // width gets a mismatched gap. Pass measured widths down from SliderLayout if that matters. val thumbWidth = configuration.thumbSize.width.roundToPx() val gap = if (configuration.thumbTrackGapSize > 0.dp) { @@ -356,7 +356,7 @@ private fun DrawScope.drawTrack( if (activeEnd - activeStart > startCorner) { drawTrackPath(activeStart, activeEnd, activeColor, startCorner, insideCorner) } - // ponytail: no step ticks, SliderConfiguration has no tick colors (the M3 backend passes Unspecified). + // No step ticks, SliderConfiguration has no tick colors (the M3 backend passes Unspecified). } private fun DrawScope.drawTrackPath(start: Float, end: Float, color: Color, startCorner: Float, endCorner: Float) { diff --git a/uikit-core/src/jvmMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvm.kt b/uikit-core/src/jvmMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvm.kt index fb59fb2..8a22d04 100644 --- a/uikit-core/src/jvmMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvm.kt +++ b/uikit-core/src/jvmMain/kotlin/ru/kode/uikit/core/internal/PlatformDates.jvm.kt @@ -2,5 +2,5 @@ package ru.kode.uikit.core.internal import java.util.Locale -// ponytail: fixed pattern; Java 19+ DateTimeFormatter.ofLocalizedPattern("yMMMM") once the toolchain moves past 17. +// Fixed pattern; Java 19+ DateTimeFormatter.ofLocalizedPattern("yMMMM") once the toolchain moves past 17. internal actual fun monthYearPattern(locale: Locale): String = "LLLL yyyy" From 431abeb8608ceb9f9c2deaaed5e4cd8fc1579835 Mon Sep 17 00:00:00 2001 From: rinekri Date: Mon, 9 Nov 2026 16:43:31 +0000 Subject: [PATCH 3/3] Fold KMP changes into unreleased 0.3.0 --- CHANGELOG.md | 56 +++++++++++++++++++++-------------------------- gradle.properties | 2 +- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f8d462..9666a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,23 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 0.4.0 +## 0.3.0 ### Added +- The library is split into three artifacts. Pick **one** backend; both depend on `uikit-core` and expose the + same API in `ru.kode.uikit.components`, so switching is a one-line dependency change: + - `uikit-core`: configuration (`UikitConfiguration`, all `*Configuration` classes), shared state types and the + Material3-free components (`TextField`, `TextFieldArea`, `PageIndicator`, shimmer). + - `uikit-components`: the Material3 backend (same artifact id as before, so existing apps just bump the version). + - `uikit-components-foundation`: a Compose Foundation backend with no Material3 or Accompanist dependency. + Adding both backends fails the build with duplicate classes. +- Slots for overriding a component's visual part on either backend: + `Checkbox(box = { state: CheckboxSlotState -> … })`, `RadioButton(indicator = { state: RadioButtonSlotState -> … })`, + `Button(loadingIndicator = { … })`, `ModalBottomSheet(dragHandle = { … } or null)`, + `TextFieldDatePicker(title = { configuration -> … }, headline = { date -> … })`. + Defaults live in `UikitCheckboxDefaults`, `UikitRadioButtonDefaults`, `UikitButtonDefaults`, + `UikitBottomSheetDefaults` and `UikitDatePickerDefaults.Title` / `.Headline`. +- Both backends render pixel-identically; CI verifies each against the same screenshot goldens. - Kotlin Multiplatform: all three artifacts now publish for Android, iOS (`iosArm64`, `iosSimulatorArm64`), JVM desktop, `js` and `wasmJs`. Android consumers keep the same coordinates; Gradle module metadata picks the Android variant. @@ -15,6 +29,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Multiplatform Material3 on the other targets. The foundation backend is pure Compose Foundation everywhere. ### Changed (breaking) +- `Slider`: the `thumb`/`track`/`startThumb`/`endThumb` slot lambdas now receive the library's own + `UikitSliderState` / `UikitRangeSliderState` instead of Material3 `SliderState` / `RangeSliderState`. +- `DatePicker`: `rememberDatePickerState(selectableDates = …)` and `DatePickerState.selectableDates` now use + the library's own `SelectableDates` interface (with `UikitDatePickerDefaults.AllDates` / `.YearRange`) + instead of Material3's `SelectableDates` / `DatePickerDefaults`. - Dates are `kotlinx.datetime.LocalDate` instead of `java.time.LocalDate`: `rememberDatePickerState`, `DatePickerState.selectedDate`, `onDateConfirm`, the `headline` slot and `UikitDatePickerDefaults.Headline`. - Android resource ids in the date picker configuration are replaced by composable lambdas: @@ -32,36 +51,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 rememberDatePickerState(initialSelectedDate = kotlinx.datetime.LocalDate(2026, 1, 15)) ``` -### Notes -- The libraries no longer enable core library desugaring themselves. kotlinx-datetime uses `java.time` on - Android, so apps with `minSdk < 26` need `coreLibraryDesugaring` enabled. -- No `iosX64` (Intel simulator) target: Compose Multiplatform 1.11 no longer publishes it. - -## 0.3.0 - -### Added -- The library is split into three artifacts. Pick **one** backend; both depend on `uikit-core` and expose the - same API in `ru.kode.uikit.components`, so switching is a one-line dependency change: - - `uikit-core`: configuration (`UikitConfiguration`, all `*Configuration` classes), shared state types and the - Material3-free components (`TextField`, `TextFieldArea`, `PageIndicator`, shimmer). - - `uikit-components`: the Material3 backend (same artifact id as before, so existing apps just bump the version). - - `uikit-components-foundation`: a Compose Foundation backend with no Material3 or Accompanist dependency. - Adding both backends fails the build with duplicate classes. -- Slots for overriding a component's visual part on either backend: - `Checkbox(box = { state: CheckboxSlotState -> … })`, `RadioButton(indicator = { state: RadioButtonSlotState -> … })`, - `Button(loadingIndicator = { … })`, `ModalBottomSheet(dragHandle = { … } or null)`, - `TextFieldDatePicker(title = { configuration -> … }, headline = { date -> … })`. - Defaults live in `UikitCheckboxDefaults`, `UikitRadioButtonDefaults`, `UikitButtonDefaults`, - `UikitBottomSheetDefaults` and `UikitDatePickerDefaults.Title` / `.Headline`. -- Both backends render pixel-identically; CI verifies each against the same screenshot goldens. - -### Changed (breaking) -- `Slider`: the `thumb`/`track`/`startThumb`/`endThumb` slot lambdas now receive the library's own - `UikitSliderState` / `UikitRangeSliderState` instead of Material3 `SliderState` / `RangeSliderState`. -- `DatePicker`: `rememberDatePickerState(selectableDates = …)` and `DatePickerState.selectableDates` now use - the library's own `SelectableDates` interface (with `UikitDatePickerDefaults.AllDates` / `.YearRange`) - instead of Material3's `SelectableDates` / `DatePickerDefaults`. - ### Deprecated - `ModalBottomSheet(showHandle = …)`: use `dragHandle` (`null` hides the handle). @@ -71,6 +60,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The foundation sliders size the thumb gap from `SliderConfiguration`, not from a custom `thumb` slot, and draw no step ticks (the Material3 backend draws none with the current configuration either). +### Notes +- The libraries no longer enable core library desugaring themselves. kotlinx-datetime uses `java.time` on + Android, so apps with `minSdk < 26` need `coreLibraryDesugaring` enabled. +- No `iosX64` (Intel simulator) target: Compose Multiplatform 1.11 no longer publishes it. + ## 0.2.0 ### Added diff --git a/gradle.properties b/gradle.properties index d0e0460..e094696 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ android.useAndroidX=true org.gradle.parallel=true org.gradle.caching=true -versionName=0.4.0 +versionName=0.3.0 pomGroupId=ru.kode.uikit pomDescription=Shared UI-kit components pomUrl=https://github.com/appKODE/uikit