From 25b0458930b3de21340cdc201e7e5e46501dbda1 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 24 Jun 2023 04:54:01 +0700 Subject: [PATCH] composed Modifier changes (#9631) Referring at the examples and other internal usages, the resulting stateful Modifier should be separated from all the previous Modifier chain. --- .../components/ChapterDownloadIndicator.kt | 2 +- .../settings/widget/BasePreferenceWidget.kt | 2 +- .../core/components/material/Tabs.kt | 29 ++++++++++--------- .../presentation/core/util/Modifier.kt | 12 ++++---- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/ChapterDownloadIndicator.kt b/app/src/main/java/eu/kanade/presentation/manga/components/ChapterDownloadIndicator.kt index a6c533d1d3..02444a16fc 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/ChapterDownloadIndicator.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/ChapterDownloadIndicator.kt @@ -245,7 +245,7 @@ private fun Modifier.commonClickable( ) = composed { val haptic = LocalHapticFeedback.current - this.combinedClickable( + Modifier.combinedClickable( enabled = enabled, onLongClick = { onLongClick() diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/widget/BasePreferenceWidget.kt b/app/src/main/java/eu/kanade/presentation/more/settings/widget/BasePreferenceWidget.kt index 267c03e3e0..aeb4f85702 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/widget/BasePreferenceWidget.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/widget/BasePreferenceWidget.kt @@ -113,7 +113,7 @@ internal fun Modifier.highlightBackground(highlighted: Boolean): Modifier = comp tween(200) }, ) - then(Modifier.background(color = highlight)) + Modifier.background(color = highlight) } internal val TrailingWidgetBuffer = 16.dp diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt index 33c819a8ff..b76407e601 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt @@ -29,20 +29,21 @@ import tachiyomi.presentation.core.components.Pill private fun Modifier.tabIndicatorOffset( currentTabPosition: TabPosition, currentPageOffsetFraction: Float, -) = composed { - val currentTabWidth by animateDpAsState( - targetValue = currentTabPosition.width, - animationSpec = spring(stiffness = Spring.StiffnessMediumLow), - ) - val offset by animateDpAsState( - targetValue = currentTabPosition.left + (currentTabWidth * currentPageOffsetFraction), - animationSpec = spring(stiffness = Spring.StiffnessMediumLow), - ) - fillMaxWidth() - .wrapContentSize(Alignment.BottomStart) - .offset { IntOffset(x = offset.roundToPx(), y = 0) } - .width(currentTabWidth) -} +) = fillMaxWidth() + .wrapContentSize(Alignment.BottomStart) + .composed { + val currentTabWidth by animateDpAsState( + targetValue = currentTabPosition.width, + animationSpec = spring(stiffness = Spring.StiffnessMediumLow), + ) + val offset by animateDpAsState( + targetValue = currentTabPosition.left + (currentTabWidth * currentPageOffsetFraction), + animationSpec = spring(stiffness = Spring.StiffnessMediumLow), + ) + Modifier + .offset { IntOffset(x = offset.roundToPx(), y = 0) } + .width(currentTabWidth) + } @Composable fun TabIndicator( diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/util/Modifier.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/util/Modifier.kt index fb8e139966..795c6e211c 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/util/Modifier.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/util/Modifier.kt @@ -25,13 +25,13 @@ import androidx.compose.ui.input.key.onPreviewKeyEvent import androidx.compose.ui.platform.LocalFocusManager import tachiyomi.presentation.core.components.material.SecondaryItemAlpha -fun Modifier.selectedBackground(isSelected: Boolean): Modifier = composed { - if (isSelected) { +fun Modifier.selectedBackground(isSelected: Boolean): Modifier = if (isSelected) { + composed { val alpha = if (isSystemInDarkTheme()) 0.16f else 0.22f - background(MaterialTheme.colorScheme.secondary.copy(alpha = alpha)) - } else { - this + Modifier.background(MaterialTheme.colorScheme.secondary.copy(alpha = alpha)) } +} else { + this } fun Modifier.secondaryItemAlpha(): Modifier = this.alpha(SecondaryItemAlpha) @@ -40,7 +40,7 @@ fun Modifier.clickableNoIndication( onLongClick: (() -> Unit)? = null, onClick: () -> Unit, ): Modifier = composed { - this.combinedClickable( + Modifier.combinedClickable( interactionSource = remember { MutableInteractionSource() }, indication = null, onLongClick = onLongClick,