From 60a3ba5a5c1d09e3c3cb56f808a95b239cb0624e Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Tue, 21 Feb 2023 22:41:56 +0700 Subject: [PATCH] Use non-stable Compose BOM (#9120) --- .../manga/components/MangaInfoHeader.kt | 4 +- .../settings/widget/ListPreferenceWidget.kt | 4 +- .../widget/MultiSelectListPreferenceWidget.kt | 4 +- .../track/TrackInfoDialogSelector.kt | 4 +- gradle/compose.versions.toml | 10 ++-- .../core/components/material/Surface.kt | 4 +- .../presentation/core/util/Modifier.kt | 54 ------------------- 7 files changed, 14 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt index fde46f667..fc6efe7b1 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt @@ -38,7 +38,7 @@ import androidx.compose.material.icons.outlined.Sync import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.Icon import androidx.compose.material3.LocalContentColor -import androidx.compose.material3.LocalMinimumTouchTargetEnforcement +import androidx.compose.material3.LocalMinimumInteractiveComponentEnforcement import androidx.compose.material3.MaterialTheme import androidx.compose.material3.ProvideTextStyle import androidx.compose.material3.SuggestionChip @@ -642,7 +642,7 @@ private fun TagsChip( text: String, onClick: () -> Unit, ) { - CompositionLocalProvider(LocalMinimumTouchTargetEnforcement provides false) { + CompositionLocalProvider(LocalMinimumInteractiveComponentEnforcement provides false) { SuggestionChip( onClick = onClick, label = { Text(text = text, style = MaterialTheme.typography.bodySmall) }, diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/widget/ListPreferenceWidget.kt b/app/src/main/java/eu/kanade/presentation/more/settings/widget/ListPreferenceWidget.kt index c6ee53ccb..7862ff9d0 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/widget/ListPreferenceWidget.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/widget/ListPreferenceWidget.kt @@ -11,6 +11,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.RadioButton import androidx.compose.material3.Text import androidx.compose.material3.TextButton +import androidx.compose.material3.minimumInteractiveComponentSize import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -27,7 +28,6 @@ import tachiyomi.presentation.core.components.ScrollbarLazyColumn import tachiyomi.presentation.core.components.material.Divider import tachiyomi.presentation.core.util.isScrolledToEnd import tachiyomi.presentation.core.util.isScrolledToStart -import tachiyomi.presentation.core.util.minimumTouchTargetSize @Composable fun ListPreferenceWidget( @@ -97,7 +97,7 @@ private fun DialogRow( onClick = { if (!isSelected) onSelected() }, ) .fillMaxWidth() - .minimumTouchTargetSize(), + .minimumInteractiveComponentSize(), ) { RadioButton( selected = isSelected, diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/widget/MultiSelectListPreferenceWidget.kt b/app/src/main/java/eu/kanade/presentation/more/settings/widget/MultiSelectListPreferenceWidget.kt index 8965d0266..98b3d7f99 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/widget/MultiSelectListPreferenceWidget.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/widget/MultiSelectListPreferenceWidget.kt @@ -10,6 +10,7 @@ import androidx.compose.material3.Checkbox import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextButton +import androidx.compose.material3.minimumInteractiveComponentSize import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -24,7 +25,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.window.DialogProperties import eu.kanade.presentation.more.settings.Preference import eu.kanade.tachiyomi.R -import tachiyomi.presentation.core.util.minimumTouchTargetSize @Composable fun MultiSelectListPreferenceWidget( @@ -69,7 +69,7 @@ fun MultiSelectListPreferenceWidget( selected = isSelected, onClick = { onSelectionChanged() }, ) - .minimumTouchTargetSize() + .minimumInteractiveComponentSize() .fillMaxWidth(), ) { Checkbox( diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt index 1ee7cd992..919c9cf2c 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt @@ -18,6 +18,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.RadioButton import androidx.compose.material3.Text import androidx.compose.material3.TextButton +import androidx.compose.material3.minimumInteractiveComponentSize import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -38,7 +39,6 @@ import tachiyomi.presentation.core.components.material.Divider import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.util.isScrolledToEnd import tachiyomi.presentation.core.util.isScrolledToStart -import tachiyomi.presentation.core.util.minimumTouchTargetSize import java.time.LocalDate import java.time.format.TextStyle import java.util.Locale @@ -68,7 +68,7 @@ fun TrackStatusSelector( onClick = { onSelectionChange(key) }, ) .fillMaxWidth() - .minimumTouchTargetSize(), + .minimumInteractiveComponentSize(), ) { RadioButton( selected = isSelected, diff --git a/gradle/compose.versions.toml b/gradle/compose.versions.toml index 9cd0428dd..e9bd3c883 100644 --- a/gradle/compose.versions.toml +++ b/gradle/compose.versions.toml @@ -1,11 +1,11 @@ [versions] compiler = "1.4.2" -compose-bom = "2023.01.00" -accompanist = "0.28.0" +compose-bom = "2023.02.00-beta01" +accompanist = "0.29.1-alpha" [libraries] activity = "androidx.activity:activity-compose:1.6.1" -bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" } +bom = { group = "dev.chrisbanes.compose", name = "compose-bom", version.ref = "compose-bom" } foundation = { module = "androidx.compose.foundation:foundation" } animation = { module = "androidx.compose.animation:animation" } animation-graphics = { module = "androidx.compose.animation:animation-graphics" } @@ -16,9 +16,7 @@ material3-core = { module = "androidx.compose.material3:material3" } material-icons = { module = "androidx.compose.material:material-icons-extended" } # Here until M3's swipeable became public https://issuetracker.google.com/issues/234640556 -# Using newer version for PullRefresh fix -# TODO: use default version after next Compose BOM is released -material-core = { module = "androidx.compose.material:material", version = "1.4.0-beta01" } +material-core = { module = "androidx.compose.material:material" } accompanist-webview = { module = "com.google.accompanist:accompanist-webview", version.ref = "accompanist" } accompanist-flowlayout = { module = "com.google.accompanist:accompanist-flowlayout", version.ref = "accompanist" } diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Surface.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Surface.kt index 1b3a60380..eda45695f 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Surface.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Surface.kt @@ -12,6 +12,7 @@ import androidx.compose.material3.LocalAbsoluteTonalElevation import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme import androidx.compose.material3.contentColorFor +import androidx.compose.material3.minimumInteractiveComponentSize import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.NonRestartableComposable @@ -27,7 +28,6 @@ import androidx.compose.ui.graphics.compositeOver import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import tachiyomi.presentation.core.util.minimumTouchTargetSize import kotlin.math.ln /** @@ -58,7 +58,7 @@ fun Surface( ) { Box( modifier = modifier - .minimumTouchTargetSize() + .minimumInteractiveComponentSize() .surface( shape = shape, backgroundColor = surfaceColorAtElevation( 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 d81aeadb2..ca538a866 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 @@ -4,7 +4,6 @@ import androidx.compose.foundation.background import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material3.LocalMinimumTouchTargetEnforcement import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.remember import androidx.compose.ui.Modifier @@ -13,16 +12,7 @@ import androidx.compose.ui.draw.alpha import androidx.compose.ui.input.key.Key import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.onPreviewKeyEvent -import androidx.compose.ui.layout.LayoutModifier -import androidx.compose.ui.layout.Measurable -import androidx.compose.ui.layout.MeasureResult -import androidx.compose.ui.layout.MeasureScope -import androidx.compose.ui.platform.LocalViewConfiguration -import androidx.compose.ui.platform.debugInspectorInfo -import androidx.compose.ui.unit.Constraints -import androidx.compose.ui.unit.DpSize import tachiyomi.presentation.core.components.material.SecondaryItemAlpha -import kotlin.math.roundToInt fun Modifier.selectedBackground(isSelected: Boolean): Modifier = composed { if (isSelected) { @@ -62,47 +52,3 @@ fun Modifier.runOnEnterKeyPressed(action: () -> Unit): Modifier = this.onPreview else -> false } } - -@Suppress("ModifierInspectorInfo") -fun Modifier.minimumTouchTargetSize(): Modifier = composed( - inspectorInfo = debugInspectorInfo { - name = "minimumTouchTargetSize" - properties["README"] = "Adds outer padding to measure at least 48.dp (default) in " + - "size to disambiguate touch interactions if the element would measure smaller" - }, -) { - if (LocalMinimumTouchTargetEnforcement.current) { - val size = LocalViewConfiguration.current.minimumTouchTargetSize - MinimumTouchTargetModifier(size) - } else { - Modifier - } -} - -private class MinimumTouchTargetModifier(val size: DpSize) : LayoutModifier { - override fun MeasureScope.measure( - measurable: Measurable, - constraints: Constraints, - ): MeasureResult { - val placeable = measurable.measure(constraints) - - // Be at least as big as the minimum dimension in both dimensions - val width = maxOf(placeable.width, size.width.roundToPx()) - val height = maxOf(placeable.height, size.height.roundToPx()) - - return layout(width, height) { - val centerX = ((width - placeable.width) / 2f).roundToInt() - val centerY = ((height - placeable.height) / 2f).roundToInt() - placeable.place(centerX, centerY) - } - } - - override fun equals(other: Any?): Boolean { - val otherModifier = other as? MinimumTouchTargetModifier ?: return false - return size == otherModifier.size - } - - override fun hashCode(): Int { - return size.hashCode() - } -}