From 24debf5963024febf05d18f454694c4916823338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Wed, 20 Sep 2023 23:25:33 +0200 Subject: [PATCH] Fix rotary input after first screen & for picker - The recent switch to Horologist modifiers for rotary input broke after the first screen because of manual focus requesting, and the refresh interval picker in general so also switch that to a Horologist modifier. --- gradle/libs.versions.toml | 4 ++- wear/build.gradle.kts | 2 +- .../home/views/RefreshIntervalPickerView.kt | 30 ++++--------------- .../android/views/ThemeLazyColumn.kt | 12 +------- 4 files changed, 10 insertions(+), 38 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 423e54cff8a..deb63dc81ae 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -64,7 +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" +horologist = "0.5.7" [plugins] android-application = { id = "com.android.application", version.ref = "androidPlugin" } @@ -121,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-composables = { module = "com.google.android.horologist:horologist-composables", version.ref = "horologist" } 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" } @@ -163,5 +164,6 @@ wear-tiles = { module = "androidx.wear.tiles:tiles", version.ref = "wear-tiles" webkit = { module = "androidx.webkit:webkit", version.ref = "webkit" } [bundles] +horologist = ["horologist-layout", "horologist-composables"] media3 = ["media3-exoplayer", "media3-exoplayer-hls", "media3-ui"] wear-tiles = ["wear-tiles", "wear-protolayout-main", "wear-protolayout-expression", "wear-protolayout-material"] \ No newline at end of file diff --git a/wear/build.gradle.kts b/wear/build.gradle.kts index f07a02d9771..e334e796f12 100644 --- a/wear/build.gradle.kts +++ b/wear/build.gradle.kts @@ -108,7 +108,7 @@ dependencies { implementation(libs.wear.compose.material) implementation(libs.wear.compose.navigation) - implementation(libs.horologist.layout) + implementation(libs.bundles.horologist) implementation(libs.guava) implementation(libs.bundles.wear.tiles) diff --git a/wear/src/main/java/io/homeassistant/companion/android/home/views/RefreshIntervalPickerView.kt b/wear/src/main/java/io/homeassistant/companion/android/home/views/RefreshIntervalPickerView.kt index 8ae4b4e18b3..be02b09aaa0 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/home/views/RefreshIntervalPickerView.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/home/views/RefreshIntervalPickerView.kt @@ -1,19 +1,12 @@ package io.homeassistant.companion.android.home.views -import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.remember -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.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Devices @@ -25,15 +18,17 @@ import androidx.wear.compose.material.ButtonDefaults import androidx.wear.compose.material.Picker import androidx.wear.compose.material.Text import androidx.wear.compose.material.rememberPickerState +import com.google.android.horologist.annotations.ExperimentalHorologistApi +import com.google.android.horologist.composables.picker.toRotaryScrollAdapter +import com.google.android.horologist.compose.rotaryinput.rotaryWithSnap import com.mikepenz.iconics.compose.Image import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import io.homeassistant.companion.android.theme.wearColorPalette import io.homeassistant.companion.android.util.intervalToString import io.homeassistant.companion.android.views.ListHeader -import kotlinx.coroutines.launch -import kotlin.math.sign import io.homeassistant.companion.android.common.R as R +@OptIn(ExperimentalHorologistApi::class) @Composable fun RefreshIntervalPickerView( currentInterval: Int, @@ -46,8 +41,6 @@ fun RefreshIntervalPickerView( initiallySelectedOption = if (initialIndex != -1) initialIndex else 0, repeatItems = true ) - val coroutineScope = rememberCoroutineScope() - val focusRequester = remember { FocusRequester() } Column( modifier = Modifier.fillMaxWidth(), @@ -60,16 +53,7 @@ fun RefreshIntervalPickerView( modifier = Modifier .weight(1f) .padding(all = 8.dp) - .onRotaryScrollEvent { - coroutineScope.launch { - state.scrollToOption( - state.selectedOption + it.verticalScrollPixels.sign.toInt() - ) - } - true - } - .focusRequester(focusRequester) - .focusable() + .rotaryWithSnap(state.toRotaryScrollAdapter()) ) { Text( intervalToString(LocalContext.current, options[it]), @@ -87,10 +71,6 @@ fun RefreshIntervalPickerView( ) } } - - LaunchedEffect(Unit) { - focusRequester.requestFocus() - } } @Preview(device = Devices.WEAR_OS_LARGE_ROUND) diff --git a/wear/src/main/java/io/homeassistant/companion/android/views/ThemeLazyColumn.kt b/wear/src/main/java/io/homeassistant/companion/android/views/ThemeLazyColumn.kt index 529fb43edb5..e97d45d28ca 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/views/ThemeLazyColumn.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/views/ThemeLazyColumn.kt @@ -4,12 +4,8 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.remember -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.unit.dp import androidx.wear.compose.foundation.lazy.ScalingLazyColumn import androidx.wear.compose.foundation.lazy.ScalingLazyListScope @@ -24,12 +20,10 @@ fun ThemeLazyColumn( state: ScalingLazyListState = rememberScalingLazyListState(), content: ScalingLazyListScope.() -> Unit ) { - val coroutineScope = rememberCoroutineScope() - val focusRequester = remember { FocusRequester() } ScalingLazyColumn( modifier = Modifier .fillMaxSize() - .rotaryWithScroll(state, focusRequester), + .rotaryWithScroll(state), contentPadding = PaddingValues( start = 8.dp, end = 8.dp @@ -39,8 +33,4 @@ fun ThemeLazyColumn( state = state, content = content ) - - LaunchedEffect(Unit) { - focusRequester.requestFocus() - } }