From 64a790baf10530a5d478e5dada73675b885d35d9 Mon Sep 17 00:00:00 2001 From: Mahendran Date: Mon, 11 Sep 2023 23:05:38 +0530 Subject: [PATCH 1/4] 1) Unused content param removed from TabItem. 2) TUITab was used in TUITabBar. 3) Pager related testMethods removed from TUITabBarTest due to we removed pager from TUITabBar. --- .../tarkalabs/uicomponents/TUITabBarTest.kt | 294 ++---------------- .../screenshots/TUITabBarScreenshotTest.kt | 163 ++-------- .../uicomponents/components/TUITab.kt | 2 +- .../uicomponents/components/TUITabBar.kt | 86 ++--- 4 files changed, 79 insertions(+), 466 deletions(-) diff --git a/tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/TUITabBarTest.kt b/tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/TUITabBarTest.kt index fe709382..53582f39 100644 --- a/tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/TUITabBarTest.kt +++ b/tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/TUITabBarTest.kt @@ -1,9 +1,7 @@ package com.tarkalabs.uicomponents -import androidx.compose.material3.Text import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.assertIsDisplayed -import androidx.compose.ui.test.assertIsNotDisplayed import androidx.compose.ui.test.assertIsNotSelected import androidx.compose.ui.test.assertIsSelected import androidx.compose.ui.test.junit4.createComposeRule @@ -11,13 +9,11 @@ import androidx.compose.ui.test.onAllNodesWithContentDescription import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick -import androidx.compose.ui.test.performTouchInput -import androidx.compose.ui.test.swipeLeft -import androidx.compose.ui.test.swipeRight import com.tarkalabs.tarkaicons.Tabs24 import com.tarkalabs.tarkaicons.TarkaIcons import com.tarkalabs.uicomponents.components.TUITabBar import com.tarkalabs.uicomponents.components.TUITabBarTags +import com.tarkalabs.uicomponents.components.TUITabTags import com.tarkalabs.uicomponents.components.TabItem import org.junit.Rule import org.junit.Test @@ -34,9 +30,9 @@ class TUITabBarTest { @Test fun is_passed_tabs_shown() { val tabItems = listOf( - TabItem(name = "Tab 1", content = {}), - TabItem(name = "Tab 2", content = {}), - TabItem(name = "Tab 3", content = {}), + TabItem(name = "Tab 1"), + TabItem(name = "Tab 2"), + TabItem(name = "Tab 3"), ) composeTestRule.setContent { @@ -48,9 +44,9 @@ class TUITabBarTest { ) } - composeTestRule.onNodeWithTag("Tab 1 ${testTags.tabId}").assertIsDisplayed() - composeTestRule.onNodeWithTag("Tab 2 ${testTags.tabId}").assertIsDisplayed() - composeTestRule.onNodeWithTag("Tab 2 ${testTags.tabId}").assertIsDisplayed() + composeTestRule.onNodeWithTag("Tab 1 ${TUITabTags().parentTag}").assertIsDisplayed() + composeTestRule.onNodeWithTag("Tab 2 ${TUITabTags().parentTag}").assertIsDisplayed() + composeTestRule.onNodeWithTag("Tab 2 ${TUITabTags().parentTag}").assertIsDisplayed() } @Test @@ -59,9 +55,9 @@ class TUITabBarTest { val leadingIcon = TarkaIcons.Regular.Tabs24 val tabItems = listOf( - TabItem(name = "Tab 1", leadingTabIcon = leadingIcon, content = {}), - TabItem(name = "Tab 2", leadingTabIcon = leadingIcon, content = {}), - TabItem(name = "Tab 3", leadingTabIcon = leadingIcon, content = {}), + TabItem(name = "Tab 1", leadingTabIcon = leadingIcon), + TabItem(name = "Tab 2", leadingTabIcon = leadingIcon), + TabItem(name = "Tab 3", leadingTabIcon = leadingIcon), ) composeTestRule.setContent { @@ -77,36 +73,12 @@ class TUITabBarTest { .assertCountEquals(3) } - @Test - fun is_passed_content_shown() { - val tabItems = listOf( - TabItem(name = "Tab 1", content = { Text(text = "Content 1") }), - TabItem(name = "Tab 2", content = { Text(text = "Content 2") }), - TabItem(name = "Tab 3", content = { Text(text = "Content 3") }), - ) - - composeTestRule.setContent { - TUITabBar( - tabItems = tabItems, - selectedTabIndex = 0, - tags = testTags, - onTabChanged = {}, - ) - } - - //Initially the content of the first tab should be shown due to the selected index is 0. - composeTestRule.onNodeWithText("Content 1").assertIsDisplayed() - //Other tab contents should not be exist - composeTestRule.onNodeWithText("Content 2").assertDoesNotExist() - composeTestRule.onNodeWithText("Content 3").assertDoesNotExist() - } - @Test fun is_passed_content_not_shown_when_pager_disabled() { val tabItems = listOf( - TabItem(name = "Tab 1", content = { Text(text = "Content 1") }), - TabItem(name = "Tab 2", content = { Text(text = "Content 2") }), - TabItem(name = "Tab 3", content = { Text(text = "Content 3") }), + TabItem(name = "Tab 1"), + TabItem(name = "Tab 2"), + TabItem(name = "Tab 3"), ) composeTestRule.setContent { @@ -127,9 +99,9 @@ class TUITabBarTest { @Test fun is_correct_tab_selected_based_on_selected_index_value() { val tabItems = listOf( - TabItem(name = "Tab 1", content = {}), - TabItem(name = "Tab 2", content = {}), - TabItem(name = "Tab 3", content = {}), + TabItem(name = "Tab 1"), + TabItem(name = "Tab 2"), + TabItem(name = "Tab 3"), ) composeTestRule.setContent { @@ -142,125 +114,10 @@ class TUITabBarTest { } //Third tab should be shown due to the selected index 2 - composeTestRule.onNodeWithTag("Tab 3 ${testTags.tabId}").assertIsSelected() + composeTestRule.onNodeWithTag("Tab 3 ${TUITabTags().parentTag}").assertIsSelected() //other tabs should not be shown - composeTestRule.onNodeWithTag("Tab 1 ${testTags.tabId}").assertIsNotSelected() - composeTestRule.onNodeWithTag("Tab 2 ${testTags.tabId}").assertIsNotSelected() - } - - @Test - fun is_pager_disabled_properly_based_on_param() { - - val tabItems = listOf( - TabItem(name = "Tab 1", content = {}), - TabItem(name = "Tab 2", content = {}), - TabItem(name = "Tab 3", content = {}), - ) - - composeTestRule.setContent { - TUITabBar( - tabItems = tabItems, - selectedTabIndex = 1, - tags = testTags, - onTabChanged = {}, - ) - } - composeTestRule.onNodeWithTag(testTags.contentId + 1).assertDoesNotExist() - } - - @Test - fun is_pager_enabled_properly_based_on_param() { - val tabItems = listOf( - TabItem(name = "Tab 1", content = { Text(text = "Content 1") }), - TabItem(name = "Tab 2", content = { Text(text = "Content 2") }), - TabItem(name = "Tab 3", content = { Text(text = "Content 3") }), - ) - - composeTestRule.setContent { - TUITabBar( - tabItems = tabItems, - selectedTabIndex = 1, - tags = testTags, - onTabChanged = {}, - ) - } - composeTestRule.onNodeWithTag(testTags.contentId + 1).assertIsDisplayed() - } - - @Test - fun is_proper_content_shown_when_switching_tab_by_click_tabRow() { - val tabItems = listOf( - TabItem(name = "Tab 1", content = { Text(text = "Content 1") }), - TabItem(name = "Tab 2", content = { Text(text = "Content 2") }), - TabItem(name = "Tab 3", content = { Text(text = "Content 3") }), - ) - - composeTestRule.setContent { - TUITabBar( - tabItems = tabItems, - selectedTabIndex = 0, - tags = testTags, - onTabChanged = {}, - ) - } - - //Initially the content of the first tab should be shown due to the selected index is 0. - composeTestRule.onNodeWithText("Content 1").assertIsDisplayed() - //Other tab contents should not be exist - composeTestRule.onNodeWithText("Content 2").assertDoesNotExist() - composeTestRule.onNodeWithText("Content 3").assertDoesNotExist() - - //Clicking the second Tab & updating Index - composeTestRule.onNodeWithTag("Tab 2 ${testTags.tabId}").performClick() - - //Now the content of the second tab should be shown due to the selected index is 1. - composeTestRule.onNodeWithText("Content 2").assertIsDisplayed() - //Other tab contents should not be shown - composeTestRule.onNodeWithText("Content 1").assertIsNotDisplayed() - composeTestRule.onNodeWithText("Content 3").assertIsNotDisplayed() - } - - @Test - fun is_proper_tab_shown_when_switching_tab_by_scrolling_pager() { - val tabItems = listOf( - TabItem(name = "Tab 1", content = { Text(text = "Content 1") }), - TabItem(name = "Tab 2", content = { Text(text = "Content 2") }), - TabItem(name = "Tab 3", content = { Text(text = "Content 3") }), - ) - - composeTestRule.setContent { - TUITabBar( - tabItems = tabItems, - selectedTabIndex = 0, - tags = testTags, - onTabChanged = {}, - ) - } - - //state before scroll - composeTestRule.onNodeWithText("Content 1").assertIsDisplayed() - composeTestRule.onNodeWithText("Content 2").assertDoesNotExist() - composeTestRule.onNodeWithText("Content 3").assertDoesNotExist() - - //if the scrolling was disabled the page content couldn't change - //First Tab Content - composeTestRule.onNodeWithTag(testTags.contentId + 0) - .performTouchInput { swipeLeft(startX = 450f, endX = 150f) } - - //state after first scroll - composeTestRule.onNodeWithText("Content 2").assertIsDisplayed() - composeTestRule.onNodeWithText("Content 3").assertIsNotDisplayed() - composeTestRule.onNodeWithText("Content 1").assertIsNotDisplayed() - - //Second Scroll to right - //Second Tab Content - composeTestRule.onNodeWithTag(testTags.contentId + 1) - .performTouchInput { swipeRight(startX = 150f, endX = 450f) } - - //state after second scroll - composeTestRule.onNodeWithText("Content 1").assertIsDisplayed() - composeTestRule.onNodeWithText("Content 2").assertIsNotDisplayed() - composeTestRule.onNodeWithText("Content 3").assertIsNotDisplayed() + composeTestRule.onNodeWithTag("Tab 1 ${TUITabTags().parentTag}").assertIsNotSelected() + composeTestRule.onNodeWithTag("Tab 2 ${TUITabTags().parentTag}").assertIsNotSelected() } @Test @@ -269,9 +126,9 @@ class TUITabBarTest { val onTabChange: (Int) -> Unit = mock() val tabItems = listOf( - TabItem(name = "Tab 1", content = {}), - TabItem(name = "Tab 2", content = {}), - TabItem(name = "Tab 3", content = {}), + TabItem(name = "Tab 1"), + TabItem(name = "Tab 2"), + TabItem(name = "Tab 3"), ) composeTestRule.setContent { @@ -284,115 +141,12 @@ class TUITabBarTest { } var clickedTabIndex = 1 - composeTestRule.onNodeWithTag("Tab 2 ${testTags.tabId}").performClick() + composeTestRule.onNodeWithTag("Tab 2 ${TUITabTags().parentTag}").performClick() verify(onTabChange).invoke(clickedTabIndex) clickedTabIndex = 2 - composeTestRule.onNodeWithTag("Tab 3 ${testTags.tabId}").performClick() + composeTestRule.onNodeWithTag("Tab 3 ${TUITabTags().parentTag}").performClick() verify(onTabChange).invoke(clickedTabIndex) } - @Test - fun is_onTabChange_invoked_while_scrolling_tabContent() { - val onTabChange: (Int) -> Unit = mock() - - val tabItems = listOf( - TabItem(name = "Tab 1", content = { Text(text = "Content 1") }), - TabItem(name = "Tab 2", content = { Text(text = "Content 2") }), - TabItem(name = "Tab 3", content = { Text(text = "Content 3") }), - ) - - composeTestRule.setContent { - TUITabBar( - tabItems = tabItems, - selectedTabIndex = 0, - tags = testTags, - onTabChanged = onTabChange, - ) - } - - composeTestRule.onNodeWithTag(testTags.contentId + 0) - .performTouchInput { swipeLeft(startX = 450f, endX = 150f) } - composeTestRule.waitForIdle() - verify(onTabChange).invoke(1) - } - - @Test - fun is_scrolling_enabled_in_pager_based_on_the_param() { - - val tabItems = listOf( - TabItem(name = "Tab 1", content = { Text(text = "Content 1") }), - TabItem(name = "Tab 2", content = { Text(text = "Content 2") }), - TabItem(name = "Tab 3", content = { Text(text = "Content 3") }), - ) - - composeTestRule.setContent { - TUITabBar( - tabItems = tabItems, - selectedTabIndex = 0, - tags = testTags, - onTabChanged = {}, - ) - } - - //state before scroll - composeTestRule.onNodeWithText("Content 1").assertIsDisplayed() - composeTestRule.onNodeWithText("Content 2").assertDoesNotExist() - composeTestRule.onNodeWithText("Content 3").assertDoesNotExist() - - composeTestRule.onNodeWithTag(testTags.contentId + 0) - .performTouchInput { swipeLeft(startX = 450f, endX = 150f) } - - composeTestRule.waitForIdle() - //if the scrolling was enabled the page content will change - - //state after scroll - composeTestRule.onNodeWithText("Content 2").assertIsDisplayed() - composeTestRule.onNodeWithText("Content 1").assertIsNotDisplayed() - // here when content 2 is displayed then sequence tab - content 3 wil initialized but not shown - // that's why we used assertIsNotDisplayed instead of assertDoesNotExist - composeTestRule.onNodeWithText("Content 3").assertIsNotDisplayed() - } - - @Test - fun is_scrolling_disabled_in_pager_based_on_the_param() { - - val tabItems = listOf( - TabItem(name = "Tab 1", content = { Text(text = "Content 1") }), - TabItem(name = "Tab 2", content = { Text(text = "Content 2") }), - TabItem(name = "Tab 3", content = { Text(text = "Content 3") }), - ) - - composeTestRule.setContent { - TUITabBar( - tabItems = tabItems, - selectedTabIndex = 0, - tags = testTags, - onTabChanged = {}, - ) - } - - //state before scroll - composeTestRule.onNodeWithText("Content 1").assertIsDisplayed() - composeTestRule.onNodeWithText("Content 2").assertDoesNotExist() - composeTestRule.onNodeWithText("Content 3").assertDoesNotExist() - - //if the scrolling was disabled the page content couldn't change - composeTestRule.onNodeWithTag(testTags.contentId + 0) - .performTouchInput { swipeLeft(startX = 450f, endX = 150f) } - - //state after scroll - composeTestRule.onNodeWithText("Content 1").assertIsDisplayed() - composeTestRule.onNodeWithText("Content 2").assertDoesNotExist() - composeTestRule.onNodeWithText("Content 3").assertDoesNotExist() - - //second scroll to right - composeTestRule.onNodeWithTag(testTags.contentId + 0) - .performTouchInput { swipeRight(startX = 150f, endX = 450f) } - - //state after second scroll - composeTestRule.onNodeWithText("Content 1").assertIsDisplayed() - composeTestRule.onNodeWithText("Content 2").assertDoesNotExist() - composeTestRule.onNodeWithText("Content 3").assertDoesNotExist() - } } \ No newline at end of file diff --git a/tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/screenshots/TUITabBarScreenshotTest.kt b/tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/screenshots/TUITabBarScreenshotTest.kt index 3227a068..1ba45295 100644 --- a/tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/screenshots/TUITabBarScreenshotTest.kt +++ b/tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/screenshots/TUITabBarScreenshotTest.kt @@ -1,10 +1,7 @@ package com.tarkalabs.uicomponents.screenshots -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Text import androidx.compose.ui.Modifier -import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.tarkalabs.tarkaicons.Circle12 import com.tarkalabs.tarkaicons.TarkaIcons @@ -33,143 +30,47 @@ class TUITabBarScreenshotTest( } val tabItems = listOf( - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), ) val tabItemsWithIcons = listOf( - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), ) val tabItemsWithContent = listOf( - TabItem("Tab") { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 1", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab") { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 2", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab") { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 3", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab") { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 4", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab") { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 5", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab") { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 6", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab") { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 7", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab") { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 8", - textAlign = TextAlign.Center - ) - }, + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), ) val tabItemsWithIconAndContent = listOf( - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 1", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 2", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 3", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 4", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 5", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 6", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 7", - textAlign = TextAlign.Center - ) - }, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) { - Text( - modifier = Modifier.fillMaxSize(), - text = "Content 8", - textAlign = TextAlign.Center - ) - }, + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), ) } diff --git a/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITab.kt b/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITab.kt index 48bf2471..d9d7b22c 100644 --- a/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITab.kt +++ b/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITab.kt @@ -55,7 +55,7 @@ fun TUITab( onTabClicked: () -> Unit, ) { Tab(modifier = modifier - .testTag(tags.parentTag) + .testTag("$title ${tags.parentTag}") .padding(4.dp) .clip(RoundedCornerShape(32.dp)) .background(if (isSelected) TUITheme.colors.secondary else Color.Transparent), diff --git a/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITabBar.kt b/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITabBar.kt index 553ee6f3..cefb9445 100644 --- a/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITabBar.kt +++ b/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITabBar.kt @@ -7,13 +7,9 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Icon -import androidx.compose.material3.Tab -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -21,10 +17,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.testTag -import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.tarkalabs.tarkaicons.Circle12 @@ -63,50 +56,18 @@ import com.tarkalabs.uicomponents.theme.TUITheme Row( horizontalArrangement = Arrangement.SpaceAround, modifier = modifier + .testTag(tags.parentId) .wrapContentWidth() .horizontalScroll(rememberScrollState()) .background(color = TUITheme.colors.secondaryAlt, shape = RoundedCornerShape(32.dp)) ) { tabItems.forEachIndexed { index, item -> - Tab(modifier = Modifier - .testTag("${item.name} ${tags.tabId}") - .padding(4.dp) - .clip(RoundedCornerShape(32.dp)) - .background(if (selectedTabIndex == index) TUITheme.colors.secondary else Color.Transparent), - selected = selectedTabIndex == index, - selectedContentColor = TUITheme.colors.secondary, - unselectedContentColor = TUITheme.colors.onSurface, - onClick = { - onTabChanged.invoke(index) - }) { - Row( - modifier = Modifier.padding(start = if (item.leadingTabIcon != null) 6.dp else 0.dp), - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically + TUITab( + title = item.name, + isSelected = selectedTabIndex == index, + leadingIcon = item.leadingTabIcon, ) { - - item.leadingTabIcon?.let { - Icon( - modifier = Modifier.size(20.dp), - painter = painterResource(id = it.iconRes), - contentDescription = it.contentDescription, - tint = if (selectedTabIndex == index) TUITheme.colors.onSecondary else TUITheme.colors.onSurface, - ) - } - - Text( - modifier = Modifier.padding( - start = if (item.leadingTabIcon == null) 16.dp else 4.dp, - end = 16.dp, - top = 6.dp, - bottom = 6.dp - ), - text = item.name, - style = TUITheme.typography.button6, - color = if (selectedTabIndex == index) TUITheme.colors.onSecondary else TUITheme.colors.onSurface, - ) - } - + onTabChanged.invoke(index) } } @@ -116,13 +77,10 @@ import com.tarkalabs.uicomponents.theme.TUITheme data class TabItem( val name: String, val leadingTabIcon: TarkaIcon? = null, - val content: @Composable () -> Unit, ) data class TUITabBarTags( val parentId: String = "TUITabBar", - val tabId: String = "TUITabBar_TabTag", - val contentId: String = "TUITabBar_PagerContentTag", ) @Composable @@ -131,24 +89,24 @@ fun PreviewTUITabRow() { val tabItems = listOf( - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, - TabItem("Tab") {}, + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), + TabItem("Tab"), ) val tabItemsWithIcons = listOf( - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, - TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12) {}, + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), + TabItem("Tab", leadingTabIcon = TarkaIcons.Regular.Circle12), ) TUITheme { From ee2e59ad4efd8ccc76ebea5626881c95963f5408 Mon Sep 17 00:00:00 2001 From: Mahendran Date: Tue, 12 Sep 2023 12:05:22 +0530 Subject: [PATCH 2/4] Title used as testTag for TUITab. --- .../main/java/com/tarkalabs/uicomponents/components/TUITab.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITab.kt b/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITab.kt index d9d7b22c..556344f9 100644 --- a/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITab.kt +++ b/tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUITab.kt @@ -55,7 +55,7 @@ fun TUITab( onTabClicked: () -> Unit, ) { Tab(modifier = modifier - .testTag("$title ${tags.parentTag}") + .testTag(title) .padding(4.dp) .clip(RoundedCornerShape(32.dp)) .background(if (isSelected) TUITheme.colors.secondary else Color.Transparent), @@ -99,7 +99,6 @@ fun TUITab( } data class TUITabTags( - val parentTag: String = "TUITab", val leadIconTag: String = "TUITab_leadIcon_Tag", ) From be4c141fa11d3d1d7946b7c2943e23a2c7f58050 Mon Sep 17 00:00:00 2001 From: Mahendran Date: Tue, 12 Sep 2023 12:08:24 +0530 Subject: [PATCH 3/4] Version Increment --- tarkaui/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tarkaui/build.gradle.kts b/tarkaui/build.gradle.kts index e523e1c0..a4e52837 100644 --- a/tarkaui/build.gradle.kts +++ b/tarkaui/build.gradle.kts @@ -66,7 +66,7 @@ publishing { run { groupId = "com.tarkalabs" artifactId = getLibraryArtifactId() - version = "0.43-alpha" + version = "0.44-alpha" artifact("$buildDir/outputs/aar/${getLibraryArtifactId()}-release.aar") } } From 8637dcbc353c9b423ce301c2434dabea2c017ed5 Mon Sep 17 00:00:00 2001 From: Mahendran Date: Tue, 12 Sep 2023 12:08:24 +0530 Subject: [PATCH 4/4] Version Increment --- tarkaui/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tarkaui/build.gradle.kts b/tarkaui/build.gradle.kts index e523e1c0..bb2887d8 100644 --- a/tarkaui/build.gradle.kts +++ b/tarkaui/build.gradle.kts @@ -66,7 +66,7 @@ publishing { run { groupId = "com.tarkalabs" artifactId = getLibraryArtifactId() - version = "0.43-alpha" + version = "0.45-alpha" artifact("$buildDir/outputs/aar/${getLibraryArtifactId()}-release.aar") } }