Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iconRtlMode param to Chip API #1850

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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,15 @@ 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.material.icons.outlined.VolumeDown
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 +356,22 @@ class ChipTest : ScreenshotBaseTest() {
}
}

@Test
fun withIconMirrored() {
luizgrp marked this conversation as resolved.
Show resolved Hide resolved
screenshotTestRule.setContent(isComponent = true, takeScreenshot = true) {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
@Suppress("Deprecation")
luizgrp marked this conversation as resolved.
Show resolved Hide resolved
Chip(
label = "Primary label",
onClick = { },
secondaryLabel = "Secondary label",
icon = Icons.Outlined.VolumeDown,
iconRtlMode = IconRtlMode.Mirrored,
oas004 marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
}

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.