Skip to content

Commit

Permalink
Add smooth scrolling for rotary input
Browse files Browse the repository at this point in the history
  • Loading branch information
Dubzer committed Sep 18, 2023
1 parent 14907fa commit 38a90fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
Expand Down
2 changes: 2 additions & 0 deletions wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(),
Expand All @@ -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
Expand Down

0 comments on commit 38a90fb

Please sign in to comment.