Skip to content

Commit

Permalink
[#112] Review: Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
florentmaitre authored and dolinetouko committed Apr 4, 2023
1 parent 45bd261 commit 3ffee64
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import com.orange.ods.compose.component.utilities.OdsImageCircleShape
import com.orange.ods.compose.component.utilities.Preview
import com.orange.ods.compose.component.utilities.UiModePreviews
import com.orange.ods.compose.text.OdsTextCaption
import com.orange.ods.compose.text.OdsTextSubtitle1
import com.orange.ods.compose.theme.OdsTheme
import com.orange.ods.utilities.extension.getElementOfType
import com.orange.ods.utilities.extension.isNotNullOrBlank
Expand Down Expand Up @@ -137,18 +138,15 @@ fun OdsListItem(
overlineText: String? = null,
trailing: @Composable (() -> Unit)? = null
) {
val hasText = text.isNotBlank()
OdsListItem(
modifier = modifier,
text = {
if (text.isNotBlank()) {
Text(
text = text,
style = OdsTheme.typography.subtitle1,
color = OdsTheme.colors.onSurface
)
if (hasText) {
OdsTextSubtitle1(text = text)
}
},
hasText = text.isNotBlank(),
hasText = hasText,
icon = icon,
secondaryText = secondaryText,
singleLineSecondaryText = singleLineSecondaryText,
Expand Down Expand Up @@ -299,9 +297,9 @@ private fun computeRequiredHeight(
*
* This method throws an exception if no icon type has been specified on the [OdsListItem] modifier using the [Modifier.iconType] method.
*
* @param painter to draw
* @param painter Painter of the icon
* @param contentDescription Content description of the icon
* @param tint icon color
* @param tint Icon color. Has not effect if icon type is different from `OdsListItemIconType.Icon`
*/
@Composable
@OdsComponentApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package com.orange.ods.compose.component.navigationdrawer
import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -31,9 +30,11 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.contentColorFor
import androidx.compose.material.rememberDrawerState
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material.ripple.RippleAlpha
import androidx.compose.material.ripple.RippleTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -59,6 +60,8 @@ import com.orange.ods.compose.theme.OdsTheme

private val DrawerHeaderMaxHeight = 167.dp

private const val SelectedItemOpacity = 20f / 255f

/**
* Navigation drawers provide ergonomic access to destinations in an app.
*
Expand All @@ -85,7 +88,7 @@ fun OdsModalDrawer(
OdsDivider()
LazyColumn {
items(drawerContentList) { item ->
ModalDrawerItem(item = item, isSelected = item == selectedItem, onItemClick)
ModalDrawerItem(item = item, selected = item == selectedItem, onItemClick)
}
}
},
Expand All @@ -104,7 +107,7 @@ object OdsModalDrawerDivider : OdsModalDrawerItem()
data class OdsModalDrawerListItem(@DrawableRes val icon: Int?, val text: String) : OdsModalDrawerItem()

@Composable
private fun ModalDrawerItem(item: OdsModalDrawerItem, isSelected: Boolean, onClick: (OdsModalDrawerListItem) -> Unit) {
private fun ModalDrawerItem(item: OdsModalDrawerItem, selected: Boolean, onClick: (OdsModalDrawerListItem) -> Unit) {
return when (item) {
is OdsModalDrawerSectionLabel -> {
Column {
Expand All @@ -116,30 +119,32 @@ private fun ModalDrawerItem(item: OdsModalDrawerItem, isSelected: Boolean, onCli
}
}
is OdsModalDrawerListItem -> {
OdsListItem(
text = {
Text(text = item.text, color = if (isSelected) OdsTheme.colors.primaryVariant else OdsTheme.colors.onSurface)
},
hasText = true,
modifier = Modifier
.iconType(OdsListItemIconType.Icon)
.selectable(
isSelected,
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(color = OdsTheme.colors.primaryVariant),
onClick = { onClick(item) }
).let {
if (isSelected) it.background(OdsTheme.colors.primaryVariant.copy(alpha = 0.2f)) else it
},
icon = item.icon?.let {
{
OdsListItemIcon(
painterResource(id = it),
tint = if (isSelected) OdsTheme.colors.primaryVariant else OdsTheme.colors.onSurface
CompositionLocalProvider(LocalRippleTheme provides OdsModalDrawerListItemRippleTheme) {
OdsListItem(
text = {
Text(
text = item.text,
color = if (selected) OdsTheme.colors.primaryVariant else OdsTheme.colors.onSurface,
style = OdsTheme.typography.subtitle1
)
},
hasText = true,
modifier = Modifier
.iconType(OdsListItemIconType.Icon)
.selectable(selected = selected, onClick = { onClick(item) })
.let {
if (selected) it.background(OdsTheme.colors.primaryVariant.copy(alpha = SelectedItemOpacity)) else it
},
icon = item.icon?.let {
{
OdsListItemIcon(
painter = painterResource(id = it),
tint = if (selected) OdsTheme.colors.primaryVariant else OdsTheme.colors.onSurface
)
}
}
}
)
)
}
}
is OdsModalDrawerDivider -> {
OdsDivider()
Expand Down Expand Up @@ -167,6 +172,15 @@ data class OdsModalDrawerHeader(
var subtitle: String? = null
)

private object OdsModalDrawerListItemRippleTheme : RippleTheme {

@Composable
override fun defaultColor() = OdsTheme.colors.primaryVariant

@Composable
override fun rippleAlpha() = RippleAlpha(SelectedItemOpacity, SelectedItemOpacity, SelectedItemOpacity, SelectedItemOpacity)
}

@Composable
private fun ModalDrawerHeader(
drawerHeader: OdsModalDrawerHeader
Expand Down

0 comments on commit 3ffee64

Please sign in to comment.