Weather widget: disable nested scrolling for day and time selectors

Close #457
This commit is contained in:
MM20 2023-07-10 17:57:30 +02:00
parent 7a66157605
commit 7a513b8820
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 38 additions and 19 deletions

View File

@ -39,6 +39,7 @@ import androidx.compose.ui.unit.dp
import de.mm20.launcher2.search.data.Tag
import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.launcher.sheets.LocalBottomSheetManager
import de.mm20.launcher2.ui.modifier.consumeAllScrolling
@Composable
fun FavoritesTagSelector(
@ -72,7 +73,7 @@ fun FavoritesTagSelector(
Row(
modifier = Modifier
.weight(1f)
.nestedScroll(NestedScrollConnection)
.consumeAllScrolling()
.horizontalScroll(scrollState)
.padding(end = 12.dp),
) {
@ -156,20 +157,4 @@ fun FavoritesTagSelector(
}
}
}
}
private object NestedScrollConnection:
NestedScrollConnection {
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
return available
}
override fun onPostScroll(
consumed: Offset,
available: Offset,
source: NestedScrollSource
): Offset {
return available
}
}

View File

@ -40,10 +40,14 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.Lifecycle
@ -59,6 +63,7 @@ import de.mm20.launcher2.ui.icons.HumidityPercentage
import de.mm20.launcher2.ui.icons.Rain
import de.mm20.launcher2.ui.ktx.blendIntoViewScale
import de.mm20.launcher2.ui.locals.LocalCardStyle
import de.mm20.launcher2.ui.modifier.consumeAllScrolling
import de.mm20.launcher2.weather.DailyForecast
import de.mm20.launcher2.weather.Forecast
import de.mm20.launcher2.widgets.WeatherWidget
@ -338,7 +343,7 @@ fun WeatherTimeSelector(
val listState = rememberLazyListState()
LazyRow(
state = listState,
modifier = modifier.fillMaxWidth(),
modifier = modifier.fillMaxWidth().consumeAllScrolling(),
horizontalArrangement = Arrangement.spacedBy(12.dp),
contentPadding = PaddingValues(start = 16.dp, end = 16.dp),
verticalAlignment = Alignment.CenterVertically
@ -397,7 +402,7 @@ fun WeatherDaySelector(
val listState = rememberLazyListState()
LazyRow(
state = listState,
modifier = modifier.fillMaxWidth(),
modifier = modifier.fillMaxWidth().consumeAllScrolling(),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically,
contentPadding = PaddingValues(start = 16.dp, end = 16.dp),

View File

@ -0,0 +1,29 @@
package de.mm20.launcher2.ui.modifier
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.unit.Velocity
/**
* Consumes all scrolling, so that the parent doesn't scroll.
*/
fun Modifier.consumeAllScrolling() = this.nestedScroll(ConsumeAllScrollConnection)
private object ConsumeAllScrollConnection:
NestedScrollConnection {
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
return available
}
override fun onPostScroll(
consumed: Offset,
available: Offset,
source: NestedScrollSource
): Offset {
return available
}
}