Add smooth scrolling for rotary input (#3876)

This commit is contained in:
Dubzer 2023-09-19 22:39:25 +03:00 committed by GitHub
parent 3915ec6d8f
commit 20f87c810b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 13 deletions

View File

@ -64,6 +64,7 @@ wearInput = "1.2.0-alpha02"
webkit = "1.8.0"
wear-remote-interactions = "1.0.0"
workRuntimeKtx = "2.8.1"
horologist = "0.5.5"
[plugins]
android-application = { id = "com.android.application", version.ref = "androidPlugin" }
@ -120,6 +121,7 @@ constraintlayout = { module = "androidx.constraintlayout:constraintlayout", vers
guava = { module = "com.google.guava:guava", version.ref = "guava" }
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
horologist-layout = { module = "com.google.android.horologist:horologist-compose-layout", version.ref = "horologist" }
iconics-compose = { module = "com.mikepenz:iconics-compose", version.ref = "iconics" }
iconics-core = { module = "com.mikepenz:iconics-core", version.ref = "iconics" }
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson-module-kotlin" }

View File

@ -108,6 +108,8 @@ dependencies {
implementation(libs.wear.compose.material)
implementation(libs.wear.compose.navigation)
implementation(libs.horologist.layout)
implementation(libs.guava)
implementation(libs.bundles.wear.tiles)

View File

@ -1,7 +1,5 @@
package io.homeassistant.companion.android.views
import androidx.compose.foundation.focusable
import androidx.compose.foundation.gestures.scrollBy
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
@ -12,15 +10,15 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.input.rotary.onRotaryScrollEvent
import androidx.compose.ui.unit.dp
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.ScalingLazyListScope
import androidx.wear.compose.foundation.lazy.ScalingLazyListState
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import kotlinx.coroutines.launch
import com.google.android.horologist.annotations.ExperimentalHorologistApi
import com.google.android.horologist.compose.rotaryinput.rotaryWithScroll
@OptIn(ExperimentalHorologistApi::class)
@Composable
fun ThemeLazyColumn(
state: ScalingLazyListState = rememberScalingLazyListState(),
@ -31,14 +29,7 @@ fun ThemeLazyColumn(
ScalingLazyColumn(
modifier = Modifier
.fillMaxSize()
.onRotaryScrollEvent {
coroutineScope.launch {
state.scrollBy(it.verticalScrollPixels)
}
true
}
.focusRequester(focusRequester)
.focusable(),
.rotaryWithScroll(state, focusRequester),
contentPadding = PaddingValues(
start = 8.dp,
end = 8.dp