Skip to content

Commit

Permalink
Add iconRtlMode param to Chip API
Browse files Browse the repository at this point in the history
  • Loading branch information
oas004 committed Dec 4, 2023
1 parent 259d190 commit 1ca55cd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
4 changes: 2 additions & 2 deletions compose-material/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -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<kotlin.Unit> 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<kotlin.Unit> 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<kotlin.Unit> 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<kotlin.Unit> 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<kotlin.Unit> onClick, optional androidx.compose.ui.Modifier modifier, optional String? secondaryLabel, optional kotlin.jvm.functions.Function1<? super androidx.compose.foundation.layout.BoxScope,kotlin.Unit>? icon, optional boolean largeIcon, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ 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
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
Expand All @@ -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,
Expand All @@ -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 ->
Expand Down Expand Up @@ -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,
Expand All @@ -150,6 +152,7 @@ public fun Chip(
placeholder = placeholder,
colors = colors,
enabled = enabled,
iconRtlMode = iconRtlMode
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1ca55cd

Please sign in to comment.