Skip to content

Commit 4ead19a

Browse files
authored
Merge branch 'darkokoa:main' into 2_remove_internal
2 parents 9a66cfa + 5939e9a commit 4ead19a

7 files changed

Lines changed: 23 additions & 78 deletions

File tree

datetime-wheel-picker/build.gradle.kts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ kotlin {
4141
sourceSets {
4242
all {
4343
languageSettings {
44-
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
44+
// optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
4545
}
4646
}
4747
commonMain.dependencies {
4848
implementation(compose.runtime)
4949
implementation(compose.material3)
5050
implementation(compose.materialIconsExtended)
51-
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
52-
implementation(compose.components.resources)
51+
// @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
52+
// implementation(compose.components.resources)
5353
implementation(libs.kotlinx.datetime)
5454
}
5555

@@ -58,9 +58,7 @@ kotlin {
5858
}
5959

6060
androidMain.dependencies {
61-
implementation(libs.androidx.appcompat)
6261
implementation(libs.androidx.activityCompose)
63-
implementation(libs.compose.uitooling)
6462
}
6563

6664
jvmMain.dependencies {
@@ -94,12 +92,6 @@ android {
9492
sourceCompatibility = JavaVersion.VERSION_17
9593
targetCompatibility = JavaVersion.VERSION_17
9694
}
97-
buildFeatures {
98-
compose = true
99-
}
100-
composeOptions {
101-
kotlinCompilerExtensionVersion = "1.5.10"
102-
}
10395
}
10496

10597
compose.desktop {

datetime-wheel-picker/src/commonMain/kotlin/dev/darkokoa/datetimewheelpicker/core/WheelPicker.kt

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,19 @@ fun WheelPicker(
6868
flingBehavior = flingBehavior
6969
) {
7070
items(count) { index ->
71-
val rotationX = calculateAnimatedRotationX(
71+
val (newAlpha, newRotationX) = calculateAnimatedAlphaAndRotationX(
7272
lazyListState = lazyListState,
7373
index = index,
7474
rowCount = rowCount
7575
)
76+
7677
Box(
7778
modifier = Modifier
7879
.height(size.height / rowCount)
7980
.width(size.width)
80-
.alpha(
81-
calculateAnimatedAlpha(
82-
lazyListState = lazyListState,
83-
index = index,
84-
rowCount = rowCount
85-
)
86-
)
81+
.alpha(newAlpha)
8782
.graphicsLayer {
88-
this.rotationX = rotationX
83+
rotationX = newRotationX
8984
},
9085
contentAlignment = Alignment.Center
9186
) {
@@ -106,11 +101,11 @@ private fun calculateSnappedItemIndex(lazyListState: LazyListState): Int {
106101
}
107102

108103
@Composable
109-
private fun calculateAnimatedAlpha(
104+
private fun calculateAnimatedAlphaAndRotationX(
110105
lazyListState: LazyListState,
111106
index: Int,
112107
rowCount: Int
113-
): Float {
108+
): Pair<Float, Float> {
114109

115110
val layoutInfo = remember { derivedStateOf { lazyListState.layoutInfo } }.value
116111
val viewPortHeight = layoutInfo.viewportSize.height.toFloat()
@@ -121,48 +116,18 @@ private fun calculateAnimatedAlpha(
121116

122117
val distanceToCenterIndex = index - centerIndex
123118

124-
val distanceToIndexSnap = abs(distanceToCenterIndex) * singleViewPortHeight.toInt() - when {
125-
distanceToCenterIndex > 0 -> centerIndexOffset
126-
distanceToCenterIndex <= 0 -> -centerIndexOffset
127-
else -> 0
128-
}
119+
val distanceToIndexSnap = distanceToCenterIndex * singleViewPortHeight.toInt() - centerIndexOffset
120+
val distanceToIndexSnapAbs = abs(distanceToIndexSnap)
129121

130-
return if (distanceToIndexSnap in 0..singleViewPortHeight.toInt()) {
131-
1.2f - (distanceToIndexSnap / singleViewPortHeight)
122+
val animatedAlpha = if (abs(distanceToIndexSnap) in 0..singleViewPortHeight.toInt()) {
123+
1.2f - (distanceToIndexSnapAbs / singleViewPortHeight)
132124
} else {
133125
0.2f
134126
}
135-
}
136127

137-
@Composable
138-
private fun calculateAnimatedRotationX(
139-
lazyListState: LazyListState,
140-
index: Int,
141-
rowCount: Int
142-
): Float {
143-
144-
val layoutInfo = remember { derivedStateOf { lazyListState.layoutInfo } }.value
145-
val viewPortHeight = layoutInfo.viewportSize.height.toFloat()
146-
val singleViewPortHeight = viewPortHeight / rowCount
128+
val animatedRotationX = (-20 * (distanceToIndexSnap / singleViewPortHeight)).takeUnless { it.isNaN() } ?: 0f
147129

148-
val centerIndex = remember { derivedStateOf { lazyListState.firstVisibleItemIndex } }.value
149-
val centerIndexOffset = remember { derivedStateOf { lazyListState.firstVisibleItemScrollOffset } }.value
150-
151-
val distanceToCenterIndex = index - centerIndex
152-
153-
val distanceToIndexSnap = abs(distanceToCenterIndex) * singleViewPortHeight.toInt() - when {
154-
distanceToCenterIndex > 0 -> centerIndexOffset
155-
distanceToCenterIndex <= 0 -> -centerIndexOffset
156-
else -> 0
157-
}
158-
159-
val animatedRotationX = -20f * (distanceToIndexSnap / singleViewPortHeight)
160-
161-
return if (animatedRotationX.isNaN()) {
162-
0f
163-
} else {
164-
animatedRotationX
165-
}
130+
return animatedAlpha to animatedRotationX
166131
}
167132

168133
object WheelPickerDefaults {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ org.jetbrains.compose.experimental.jscanvas.enabled=true
2424
# Maven Central
2525
GROUP=io.github.darkokoa
2626
POM_ARTIFACT_ID=datetime-wheel-picker
27-
VERSION_NAME=1.0.0-alpha01
27+
VERSION_NAME=1.0.0-alpha02
2828

2929
POM_NAME=DateTime Wheel Picker
3030
POM_INCEPTION_YEAR=2024

gradle/libs.versions.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
[versions]
22

33
kotlin = "1.9.22"
4-
compose = "1.5.12"
5-
agp = "8.2.2"
6-
androidx-appcompat = "1.6.1"
4+
compose = "1.6.0"
5+
agp = "8.3.0"
76
androidx-activityCompose = "1.8.2"
8-
compose-uitooling = "1.5.4"
97
kotlinx-datetime = "0.5.0"
108
maven-publish = "0.27.0"
119

1210
[libraries]
1311

14-
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
1512
androidx-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
16-
compose-uitooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose-uitooling" }
1713
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
1814

1915
[plugins]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

sample/composeApp/build.gradle.kts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ kotlin {
3636
sourceSets {
3737
all {
3838
languageSettings {
39-
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
39+
// optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
4040
}
4141
}
4242
commonMain.dependencies {
@@ -45,8 +45,8 @@ kotlin {
4545
implementation(compose.runtime)
4646
implementation(compose.material3)
4747
implementation(compose.materialIconsExtended)
48-
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
49-
implementation(compose.components.resources)
48+
// @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
49+
// implementation(compose.components.resources)
5050
implementation(libs.kotlinx.datetime)
5151
}
5252

@@ -55,9 +55,7 @@ kotlin {
5555
}
5656

5757
androidMain.dependencies {
58-
implementation(libs.androidx.appcompat)
5958
implementation(libs.androidx.activityCompose)
60-
implementation(libs.compose.uitooling)
6159
}
6260

6361
jvmMain.dependencies {
@@ -96,12 +94,6 @@ android {
9694
sourceCompatibility = JavaVersion.VERSION_17
9795
targetCompatibility = JavaVersion.VERSION_17
9896
}
99-
buildFeatures {
100-
compose = true
101-
}
102-
composeOptions {
103-
kotlinCompilerExtensionVersion = "1.5.10"
104-
}
10597
}
10698

10799
compose.desktop {

sample/composeApp/src/androidMain/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
android:name=".AndroidApp"
66
android:icon="@android:drawable/ic_menu_compass"
77
android:label="datetime-wheel-picker"
8-
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
8+
android:theme="@android:style/Theme.Material.NoActionBar">
99
<activity
1010
android:name=".AppActivity"
1111
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"

0 commit comments

Comments
 (0)