Skip to content

Commit

Permalink
Merge pull request #148 from tarkalabs/mahi/enhance/tui_selec_card
Browse files Browse the repository at this point in the history
Optional trailing CheckMarIcon was added in TUISelectionCard.
  • Loading branch information
rajajawahar authored Dec 13, 2023
2 parents b35994f + 783717a commit 3aef097
Show file tree
Hide file tree
Showing 259 changed files with 69 additions and 21 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.tarkalabs.uicomponents

import androidx.compose.ui.test.assertContentDescriptionContains
import androidx.compose.ui.test.assertContentDescriptionEquals
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import com.tarkalabs.tarkaicons.CheckmarkCircle24
import com.tarkalabs.tarkaicons.ChevronRight24
import com.tarkalabs.tarkaicons.Person24
import com.tarkalabs.uicomponents.components.card.TUISelectionCard
Expand All @@ -31,9 +33,9 @@ class TUISelectionCardTest {

val leadingIcon = TarkaIcons.Regular.Person24

//This is default icon when
// isTrailingBackArrowEnabled = true
val trailingIcon = TarkaIcons.Regular.ChevronRight24
//Default Icon used when
// showCheckMarkIconWhenSelected = true
val selectedCheckMarkIcon = TarkaIcons.Regular.CheckmarkCircle24

val tags = TUISelectionCardTags()

Expand All @@ -46,11 +48,11 @@ class TUISelectionCardTest {
secondaryDetails = detail2,
badgeCount = badgeCount,
leadingIcon = leadingIcon,
isSelected = true,
showTrailingIcon = true,
showCheckMarkIcon = true,
tags = tags,
) {

}
) {}
}

//if we used multiple similar types of composable or Nodes inside a compose function. jetpack will merge all those into one for performance improvements.
Expand All @@ -65,8 +67,27 @@ class TUISelectionCardTest {

//All are Icon Composable
composeRule.onNodeWithTag(tags.leadingIconTag, useUnmergedTree = true)
.assertContentDescriptionContains(leadingIcon.contentDescription)
composeRule.onNodeWithTag(tags.trailingFrontArrowIconTag, useUnmergedTree = true)
.assertContentDescriptionEquals(leadingIcon.contentDescription)
composeRule.onNodeWithTag(tags.trailingCheckMarkIconTag, useUnmergedTree = true)
.assertContentDescriptionEquals(selectedCheckMarkIcon.contentDescription)
}

@Test
fun is_front_arrow_trail_icon_shown_properly() {

//This is default icon when
// isTrailingBackArrowEnabled = true
val trailingIcon = TarkaIcons.Regular.ChevronRight24

composeRule.setContent {
TUISelectionCard(
label = "label",
primaryDescription = "desc",
showTrailingIcon = true,
) {}
}

composeRule.onNodeWithTag(TUISelectionCardTags().trailingFrontArrowIconTag, useUnmergedTree = true)
.assertContentDescriptionContains(trailingIcon.contentDescription)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TUISelectionCardScreenShotTest(
private val detail2: String?,
private val badgeCount: Int?,
private val trailingIconEnabled: Boolean,
private val checkMarkIconEnabled: Boolean,
private val testName: String,
) : ComposeScreenshotComparator() {

Expand All @@ -37,6 +38,7 @@ class TUISelectionCardScreenShotTest(
val detail2Values = listOf(null, "Detail2")
val badgeCountValues = listOf(null, 4)
val trailingIconEnabledValues = listOf(false, true)
val showSelectedCheckMarIconValues = listOf(false, true)

val testData = arrayListOf<Array<Any?>>()

Expand All @@ -48,6 +50,7 @@ class TUISelectionCardScreenShotTest(
for (detail2 in detail2Values) {
for (badgeCount in badgeCountValues) {
for (trailingIconEnabled in trailingIconEnabledValues) {
for (showSelectedCheckMarIcon in showSelectedCheckMarIconValues) {

val testName =
"darkTheme_${darkTheme}_isSelected${isSelected}_leadIcShown_${if (leadingIcon != null) "true" else "false"}" +
Expand All @@ -64,10 +67,12 @@ class TUISelectionCardScreenShotTest(
detail2,
badgeCount,
trailingIconEnabled,
showSelectedCheckMarIcon,
testName
)
)
}
}
}
}
}
Expand All @@ -94,7 +99,8 @@ class TUISelectionCardScreenShotTest(
primaryDetails = detail,
secondaryDetails = detail2,
badgeCount = badgeCount,
showTrailingIcon = trailingIconEnabled
showTrailingIcon = trailingIconEnabled,
showCheckMarkIcon = checkMarkIconEnabled,
) {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.tarkalabs.tarkaicons.CheckmarkCircle24
import com.tarkalabs.tarkaicons.ChevronRight24
import com.tarkalabs.tarkaicons.Person24
import com.tarkalabs.tarkaicons.TarkaIcon
import com.tarkalabs.tarkaicons.TarkaIcons
import com.tarkalabs.tarkaicons.TarkaIcons.Filled
import com.tarkalabs.tarkaicons.TarkaIcons.Regular
import com.tarkalabs.uicomponents.components.VerticalSpacer
import com.tarkalabs.uicomponents.components.card.SecondaryDetailsStyle.ERROR
Expand Down Expand Up @@ -65,10 +66,11 @@ fun TUISelectionCard(
secondaryDescription: String? = null,
primaryDetails: String? = null,
secondaryDetails: String? = null,
secondaryDetailStyle: SecondaryDetailsStyle = SecondaryDetailsStyle.NORMAL,
secondaryDetailStyle: SecondaryDetailsStyle = NORMAL,
badgeCount: Int? = null,
showTrailingIcon: Boolean = false,
isSelected: Boolean = false,
showCheckMarkIcon: Boolean = false,
tags: TUISelectionCardTags = TUISelectionCardTags(),
onCardClicked: () -> Unit,
) {
Expand Down Expand Up @@ -100,7 +102,7 @@ fun TUISelectionCard(

Column(
modifier = Modifier
.padding(start = if(leadingIcon != null) 16.dp else 0.dp)
.padding(start = if (leadingIcon != null) 16.dp else 0.dp)
.weight(1f)
) {

Expand Down Expand Up @@ -151,23 +153,37 @@ fun TUISelectionCard(

badgeCount?.let {
TUIBadge(
modifier = Modifier.align(Alignment.CenterVertically)
modifier = Modifier
.align(Alignment.CenterVertically)
.padding(start = 16.dp)
.testTag(tags.badgeTag),
count = badgeCount,
color = TUITheme.colors.tertiary
)
}

if (showTrailingIcon) {
if (showCheckMarkIcon && isSelected) {
Icon(
modifier = Modifier.align(Alignment.CenterVertically)
modifier = Modifier
.align(Alignment.CenterVertically)
.size(24.dp)
.testTag(tags.trailingFrontArrowIconTag),
painter = painterResource(id = TarkaIcons.Regular.ChevronRight24.iconRes),
contentDescription = TarkaIcons.Regular.ChevronRight24.contentDescription,
tint = if (isSelected) TUITheme.colors.onSecondaryAlt else TUITheme.colors.utilityOutline
.testTag(tags.trailingCheckMarkIconTag),
painter = painterResource(id = Filled.CheckmarkCircle24.iconRes),
contentDescription = Regular.CheckmarkCircle24.contentDescription,
tint = TUITheme.colors.onSecondaryAlt
)
} else {
if (showTrailingIcon) {
Icon(
modifier = Modifier
.align(Alignment.CenterVertically)
.size(24.dp)
.testTag(tags.trailingFrontArrowIconTag),
painter = painterResource(id = Regular.ChevronRight24.iconRes),
contentDescription = Regular.ChevronRight24.contentDescription,
tint = if (isSelected) TUITheme.colors.onSecondaryAlt else TUITheme.colors.utilityOutline
)
}
}

}
Expand All @@ -183,6 +199,7 @@ data class TUISelectionCardTags(
val details2Tag: String = "TUISelectionCard_SecondaryDetailsTag",
val badgeTag: String = "TUISelectionCard_BadgeTag",
val trailingFrontArrowIconTag: String = "TUISelectionCard_TrailingFrontArrowIconTag",
val trailingCheckMarkIconTag: String = "TUISelectionCard_TrailingCheckMarkIconTag",
)

@Preview
Expand Down Expand Up @@ -236,7 +253,9 @@ fun TUISelectionCardPreview() {
secondaryDetails = "Details2",
secondaryDetailStyle = ERROR,
badgeCount = 4,
showTrailingIcon = true
showTrailingIcon = true,
isSelected = true,
showCheckMarkIcon = true
) {}
VerticalSpacer(space = 14)
TUISelectionCard(
Expand All @@ -247,7 +266,9 @@ fun TUISelectionCardPreview() {
primaryDetails = "Details",
secondaryDetails = "Details2",
badgeCount = 4,
showTrailingIcon = true
showTrailingIcon = false,
isSelected = true,
showCheckMarkIcon = true
) {}

VerticalSpacer(space = 14)
Expand Down

0 comments on commit 3aef097

Please sign in to comment.