diff --git a/compose-material/api/current.api b/compose-material/api/current.api index 05e62bdbfb..2771ea0413 100644 --- a/compose-material/api/current.api +++ b/compose-material/api/current.api @@ -46,8 +46,8 @@ package com.google.android.horologist.compose.material { } public final class ChipKt { - method @androidx.compose.runtime.Composable @com.google.android.horologist.annotations.ExperimentalHorologistApi public static void Chip(String label, kotlin.jvm.functions.Function0 onClick, optional androidx.compose.ui.Modifier modifier, optional String? secondaryLabel, optional Object? icon, optional boolean largeIcon, optional androidx.compose.ui.graphics.painter.Painter? placeholder, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled); - method @androidx.compose.runtime.Composable @com.google.android.horologist.annotations.ExperimentalHorologistApi public static void Chip(@StringRes int labelId, kotlin.jvm.functions.Function0 onClick, optional androidx.compose.ui.Modifier modifier, optional @StringRes Integer? secondaryLabel, optional Object? icon, optional boolean largeIcon, optional androidx.compose.ui.graphics.painter.Painter? placeholder, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled); + method @androidx.compose.runtime.Composable @com.google.android.horologist.annotations.ExperimentalHorologistApi public static void Chip(String label, kotlin.jvm.functions.Function0 onClick, optional androidx.compose.ui.Modifier modifier, optional String? secondaryLabel, optional com.google.android.horologist.compose.material.IconRtlMode iconRtlMode, optional Object? icon, optional boolean largeIcon, optional androidx.compose.ui.graphics.painter.Painter? placeholder, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled); + method @androidx.compose.runtime.Composable @com.google.android.horologist.annotations.ExperimentalHorologistApi public static void Chip(@StringRes int labelId, kotlin.jvm.functions.Function0 onClick, optional androidx.compose.ui.Modifier modifier, optional @StringRes Integer? secondaryLabel, optional com.google.android.horologist.compose.material.IconRtlMode iconRtlMode, optional Object? icon, optional boolean largeIcon, optional androidx.compose.ui.graphics.painter.Painter? placeholder, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled); method @androidx.compose.runtime.Composable @com.google.android.horologist.annotations.ExperimentalHorologistApi public static void Chip(String label, kotlin.jvm.functions.Function0 onClick, optional androidx.compose.ui.Modifier modifier, optional String? secondaryLabel, optional kotlin.jvm.functions.Function1? icon, optional boolean largeIcon, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled); } diff --git a/compose-material/src/debug/java/com/google/android/horologist/compose/material/ChipPreview.kt b/compose-material/src/debug/java/com/google/android/horologist/compose/material/ChipPreview.kt index 19aed2810d..a55eaa9357 100644 --- a/compose-material/src/debug/java/com/google/android/horologist/compose/material/ChipPreview.kt +++ b/compose-material/src/debug/java/com/google/android/horologist/compose/material/ChipPreview.kt @@ -17,12 +17,16 @@ package com.google.android.horologist.compose.material import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.outlined.VolumeDown import androidx.compose.material.icons.filled.Image import androidx.compose.material.icons.materialPath import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import androidx.wear.compose.material.ChipDefaults @@ -178,6 +182,24 @@ fun ChipPreviewWithImageBackgroundChipColors() { ) } +@Preview( + name = "With icon and forced rtl mode", + backgroundColor = 0xff000000, + showBackground = true, +) +@Composable +private fun ChipPreviewWithIconMirroredMode() { + CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) { + Chip( + label = "Primary label", + onClick = { }, + secondaryLabel = "Secondary label", + icon = Icons.AutoMirrored.Outlined.VolumeDown, + iconRtlMode = IconRtlMode.Mirrored + ) + } +} + private val Icon32dp: ImageVector get() = ImageVector.Builder( name = "Icon Large", diff --git a/compose-material/src/main/java/com/google/android/horologist/compose/material/Chip.kt b/compose-material/src/main/java/com/google/android/horologist/compose/material/Chip.kt index c43304a1ae..0e73911e5c 100644 --- a/compose-material/src/main/java/com/google/android/horologist/compose/material/Chip.kt +++ b/compose-material/src/main/java/com/google/android/horologist/compose/material/Chip.kt @@ -31,7 +31,6 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -39,7 +38,6 @@ import androidx.compose.ui.unit.dp import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipColors import androidx.wear.compose.material.ChipDefaults -import androidx.wear.compose.material.Icon import androidx.wear.compose.material.LocalContentAlpha import androidx.wear.compose.material.Text import coil.compose.rememberAsyncImagePainter @@ -59,6 +57,7 @@ public fun Chip( onClick: () -> Unit, modifier: Modifier = Modifier, secondaryLabel: String? = null, + iconRtlMode: IconRtlMode = IconRtlMode.Default, icon: Any? = null, largeIcon: Boolean = false, placeholder: Painter? = null, @@ -84,13 +83,15 @@ public fun Chip( imageVector = icon, contentDescription = DECORATIVE_ELEMENT_CONTENT_DESCRIPTION, modifier = iconModifier, + rtlMode = iconRtlMode, ) is Int -> Icon( - painter = painterResource(id = icon), + id = icon, contentDescription = DECORATIVE_ELEMENT_CONTENT_DESCRIPTION, modifier = iconModifier, + rtlMode = iconRtlMode, ) else -> @@ -134,6 +135,7 @@ public fun Chip( onClick: () -> Unit, modifier: Modifier = Modifier, @StringRes secondaryLabel: Int? = null, + iconRtlMode: IconRtlMode = IconRtlMode.Default, icon: Any? = null, largeIcon: Boolean = false, placeholder: Painter? = null, @@ -150,6 +152,7 @@ public fun Chip( placeholder = placeholder, colors = colors, enabled = enabled, + iconRtlMode = iconRtlMode ) } diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/ChipTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/ChipTest.kt index 24f0f25c5c..5fdb162a18 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/ChipTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/ChipTest.kt @@ -18,12 +18,14 @@ package com.google.android.horologist.compose.material import android.R import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.outlined.VolumeDown import androidx.compose.material.icons.filled.Image import androidx.compose.material.icons.materialPath import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalInspectionMode +import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp @@ -353,6 +355,21 @@ class ChipTest : ScreenshotBaseTest() { } } + @Test + fun withIconMirrored() { + screenshotTestRule.setContent(isComponent = true, takeScreenshot = true) { + CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) { + Chip( + label = "Primary label", + onClick = { }, + secondaryLabel = "Secondary label", + icon = Icons.AutoMirrored.Outlined.VolumeDown, + iconRtlMode = IconRtlMode.Mirrored + ) + } + } + } + companion object { private const val largestFontScale = 1.18f diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ChipTest_withIconMirrored.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ChipTest_withIconMirrored.png new file mode 100644 index 0000000000..9eee21643e --- /dev/null +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ChipTest_withIconMirrored.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d800b2b3b41814e9beda00e17da47f396259e06f36dd2f4b8bb530fd1c4ccad5 +size 10410