diff --git a/datetime-wheel-picker/build.gradle.kts b/datetime-wheel-picker/build.gradle.kts index 3e52958..611d5b2 100644 --- a/datetime-wheel-picker/build.gradle.kts +++ b/datetime-wheel-picker/build.gradle.kts @@ -41,15 +41,15 @@ kotlin { sourceSets { all { languageSettings { - optIn("org.jetbrains.compose.resources.ExperimentalResourceApi") +// optIn("org.jetbrains.compose.resources.ExperimentalResourceApi") } } commonMain.dependencies { implementation(compose.runtime) implementation(compose.material3) implementation(compose.materialIconsExtended) - @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) - implementation(compose.components.resources) +// @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) +// implementation(compose.components.resources) implementation(libs.kotlinx.datetime) } @@ -58,9 +58,7 @@ kotlin { } androidMain.dependencies { - implementation(libs.androidx.appcompat) implementation(libs.androidx.activityCompose) - implementation(libs.compose.uitooling) } jvmMain.dependencies { @@ -94,12 +92,6 @@ android { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } - buildFeatures { - compose = true - } - composeOptions { - kotlinCompilerExtensionVersion = "1.5.10" - } } compose.desktop { diff --git a/datetime-wheel-picker/src/commonMain/kotlin/dev/darkokoa/datetimewheelpicker/core/WheelPicker.kt b/datetime-wheel-picker/src/commonMain/kotlin/dev/darkokoa/datetimewheelpicker/core/WheelPicker.kt index 073663a..b62ffe9 100644 --- a/datetime-wheel-picker/src/commonMain/kotlin/dev/darkokoa/datetimewheelpicker/core/WheelPicker.kt +++ b/datetime-wheel-picker/src/commonMain/kotlin/dev/darkokoa/datetimewheelpicker/core/WheelPicker.kt @@ -68,24 +68,19 @@ fun WheelPicker( flingBehavior = flingBehavior ) { items(count) { index -> - val rotationX = calculateAnimatedRotationX( + val (newAlpha, newRotationX) = calculateAnimatedAlphaAndRotationX( lazyListState = lazyListState, index = index, rowCount = rowCount ) + Box( modifier = Modifier .height(size.height / rowCount) .width(size.width) - .alpha( - calculateAnimatedAlpha( - lazyListState = lazyListState, - index = index, - rowCount = rowCount - ) - ) + .alpha(newAlpha) .graphicsLayer { - this.rotationX = rotationX + rotationX = newRotationX }, contentAlignment = Alignment.Center ) { @@ -106,11 +101,11 @@ private fun calculateSnappedItemIndex(lazyListState: LazyListState): Int { } @Composable -private fun calculateAnimatedAlpha( +private fun calculateAnimatedAlphaAndRotationX( lazyListState: LazyListState, index: Int, rowCount: Int -): Float { +): Pair { val layoutInfo = remember { derivedStateOf { lazyListState.layoutInfo } }.value val viewPortHeight = layoutInfo.viewportSize.height.toFloat() @@ -121,48 +116,18 @@ private fun calculateAnimatedAlpha( val distanceToCenterIndex = index - centerIndex - val distanceToIndexSnap = abs(distanceToCenterIndex) * singleViewPortHeight.toInt() - when { - distanceToCenterIndex > 0 -> centerIndexOffset - distanceToCenterIndex <= 0 -> -centerIndexOffset - else -> 0 - } + val distanceToIndexSnap = distanceToCenterIndex * singleViewPortHeight.toInt() - centerIndexOffset + val distanceToIndexSnapAbs = abs(distanceToIndexSnap) - return if (distanceToIndexSnap in 0..singleViewPortHeight.toInt()) { - 1.2f - (distanceToIndexSnap / singleViewPortHeight) + val animatedAlpha = if (abs(distanceToIndexSnap) in 0..singleViewPortHeight.toInt()) { + 1.2f - (distanceToIndexSnapAbs / singleViewPortHeight) } else { 0.2f } -} -@Composable -private fun calculateAnimatedRotationX( - lazyListState: LazyListState, - index: Int, - rowCount: Int -): Float { - - val layoutInfo = remember { derivedStateOf { lazyListState.layoutInfo } }.value - val viewPortHeight = layoutInfo.viewportSize.height.toFloat() - val singleViewPortHeight = viewPortHeight / rowCount + val animatedRotationX = (-20 * (distanceToIndexSnap / singleViewPortHeight)).takeUnless { it.isNaN() } ?: 0f - val centerIndex = remember { derivedStateOf { lazyListState.firstVisibleItemIndex } }.value - val centerIndexOffset = remember { derivedStateOf { lazyListState.firstVisibleItemScrollOffset } }.value - - val distanceToCenterIndex = index - centerIndex - - val distanceToIndexSnap = abs(distanceToCenterIndex) * singleViewPortHeight.toInt() - when { - distanceToCenterIndex > 0 -> centerIndexOffset - distanceToCenterIndex <= 0 -> -centerIndexOffset - else -> 0 - } - - val animatedRotationX = -20f * (distanceToIndexSnap / singleViewPortHeight) - - return if (animatedRotationX.isNaN()) { - 0f - } else { - animatedRotationX - } + return animatedAlpha to animatedRotationX } object WheelPickerDefaults { diff --git a/gradle.properties b/gradle.properties index 25eea80..4f8b351 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ org.jetbrains.compose.experimental.jscanvas.enabled=true # Maven Central GROUP=io.github.darkokoa POM_ARTIFACT_ID=datetime-wheel-picker -VERSION_NAME=1.0.0-alpha01 +VERSION_NAME=1.0.0-alpha02 POM_NAME=DateTime Wheel Picker POM_INCEPTION_YEAR=2024 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e37c486..b82c534 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,19 +1,15 @@ [versions] kotlin = "1.9.22" -compose = "1.5.12" -agp = "8.2.2" -androidx-appcompat = "1.6.1" +compose = "1.6.0" +agp = "8.3.0" androidx-activityCompose = "1.8.2" -compose-uitooling = "1.5.4" kotlinx-datetime = "0.5.0" maven-publish = "0.27.0" [libraries] -androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" } androidx-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } -compose-uitooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose-uitooling" } kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" } [plugins] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index da55e4b..c5622d6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/sample/composeApp/build.gradle.kts b/sample/composeApp/build.gradle.kts index 740b211..3ff34c6 100644 --- a/sample/composeApp/build.gradle.kts +++ b/sample/composeApp/build.gradle.kts @@ -36,7 +36,7 @@ kotlin { sourceSets { all { languageSettings { - optIn("org.jetbrains.compose.resources.ExperimentalResourceApi") +// optIn("org.jetbrains.compose.resources.ExperimentalResourceApi") } } commonMain.dependencies { @@ -45,8 +45,8 @@ kotlin { implementation(compose.runtime) implementation(compose.material3) implementation(compose.materialIconsExtended) - @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) - implementation(compose.components.resources) +// @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) +// implementation(compose.components.resources) implementation(libs.kotlinx.datetime) } @@ -55,9 +55,7 @@ kotlin { } androidMain.dependencies { - implementation(libs.androidx.appcompat) implementation(libs.androidx.activityCompose) - implementation(libs.compose.uitooling) } jvmMain.dependencies { @@ -96,12 +94,6 @@ android { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } - buildFeatures { - compose = true - } - composeOptions { - kotlinCompilerExtensionVersion = "1.5.10" - } } compose.desktop { diff --git a/sample/composeApp/src/androidMain/AndroidManifest.xml b/sample/composeApp/src/androidMain/AndroidManifest.xml index d315d8d..1fea4ef 100644 --- a/sample/composeApp/src/androidMain/AndroidManifest.xml +++ b/sample/composeApp/src/androidMain/AndroidManifest.xml @@ -5,7 +5,7 @@ android:name=".AndroidApp" android:icon="@android:drawable/ic_menu_compass" android:label="datetime-wheel-picker" - android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"> + android:theme="@android:style/Theme.Material.NoActionBar">