Skip to content

Commit

Permalink
Merge branch 'darkokoa:main' into 2_remove_internal
Browse files Browse the repository at this point in the history
  • Loading branch information
herrrta authored Mar 16, 2024
2 parents 9a66cfa + 5939e9a commit 4ead19a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 78 deletions.
14 changes: 3 additions & 11 deletions datetime-wheel-picker/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -58,9 +58,7 @@ kotlin {
}

androidMain.dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.activityCompose)
implementation(libs.compose.uitooling)
}

jvmMain.dependencies {
Expand Down Expand Up @@ -94,12 +92,6 @@ android {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.10"
}
}

compose.desktop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand All @@ -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<Float, Float> {

val layoutInfo = remember { derivedStateOf { lazyListState.layoutInfo } }.value
val viewPortHeight = layoutInfo.viewportSize.height.toFloat()
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
14 changes: 3 additions & 11 deletions sample/composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ kotlin {
sourceSets {
all {
languageSettings {
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
// optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
}
}
commonMain.dependencies {
Expand All @@ -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)
}

Expand All @@ -55,9 +55,7 @@ kotlin {
}

androidMain.dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.activityCompose)
implementation(libs.compose.uitooling)
}

jvmMain.dependencies {
Expand Down Expand Up @@ -96,12 +94,6 @@ android {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.10"
}
}

compose.desktop {
Expand Down
2 changes: 1 addition & 1 deletion sample/composeApp/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<activity
android:name=".AppActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
Expand Down

0 comments on commit 4ead19a

Please sign in to comment.