From 754924c617be6dc4ea3cefe8c0721e09613fd8b3 Mon Sep 17 00:00:00 2001 From: AskNilesh Date: Mon, 4 Mar 2024 17:23:03 +0530 Subject: [PATCH 1/2] - Added extra parameter for searchbar visibility in TUIAppTopBar --- .../tarkalabs/ui/UIComponentListActivity.kt | 52 +++++++++---------- .../tarkaui/components/TUIAppTopBar.kt | 5 ++ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/example/src/main/java/com/tarkalabs/ui/UIComponentListActivity.kt b/example/src/main/java/com/tarkalabs/ui/UIComponentListActivity.kt index c73f7096..fbc3819f 100644 --- a/example/src/main/java/com/tarkalabs/ui/UIComponentListActivity.kt +++ b/example/src/main/java/com/tarkalabs/ui/UIComponentListActivity.kt @@ -17,13 +17,11 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.tarkalabs.tarkaui.components.TUIAppTopBar -import com.tarkalabs.tarkaui.components.TUISearchBar -import com.tarkalabs.tarkaui.icons.BarcodeScanner24 +import com.tarkalabs.tarkaui.components.VerticalSpacer +import com.tarkalabs.tarkaui.components.base.TUIButton import com.tarkalabs.tarkaui.icons.ChevronRight20 -import com.tarkalabs.tarkaui.icons.Dismiss16 +import com.tarkalabs.tarkaui.icons.Search24 import com.tarkalabs.tarkaui.icons.TarkaIcons -import com.tarkalabs.tarkaui.icons.TarkaIcons.Filled -import com.tarkalabs.tarkaui.icons.TarkaIcons.Regular import com.tarkalabs.tarkaui.theme.TUITheme @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") @@ -38,6 +36,10 @@ class UIComponentListActivity : ComponentActivity() { mutableStateOf("") } + var showSearchbar by remember { + mutableStateOf(false) + } + Scaffold(topBar = { TUIAppTopBar( title = "Lorem Ipsum", @@ -45,6 +47,13 @@ class UIComponentListActivity : ComponentActivity() { menuItemIconOne = TarkaIcons.Regular.ChevronRight20, menuItemIconTwo = TarkaIcons.Regular.ChevronRight20, menuItemIconThree = TarkaIcons.Regular.ChevronRight20, + searchIcon = TarkaIcons.Regular.Search24, + searchQuery = query, + searchQueryHint = "Search something", + onSearchQuery = { + query = it + }, + toggleSearchbar = showSearchbar ) }) { paddingValues -> @@ -55,29 +64,16 @@ class UIComponentListActivity : ComponentActivity() { .fillMaxHeight() .padding(horizontal = 8.dp) ) { - TUISearchBar( - query = "My Search", - placeholder = "Search", - onQueryTextChange = {}, - trailingIcon = Filled.Dismiss16, - leadingIcon = Regular.BarcodeScanner24, - onLeadingIconClick = {}, - modifier = Modifier - .fillMaxWidth() - .padding(10.dp), - ) - TUISearchBar( - query = "Search", - placeholder = "Search Here", - onQueryTextChange = {}, - trailingIcon = Filled.Dismiss16, - leadingIcon = Regular.BarcodeScanner24, - onLeadingIconClick = {}, - modifier = Modifier - .fillMaxWidth() - .padding(10.dp), - ) - + VerticalSpacer(space = 20) + TUIButton(label = "Show Searchbar") { + query = "Hello there" + showSearchbar = true + } + VerticalSpacer(space = 20) + TUIButton(label = "Hide Searchbar") { + query = "" + showSearchbar = false + } } } diff --git a/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUIAppTopBar.kt b/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUIAppTopBar.kt index 1d7e3554..8c01450d 100644 --- a/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUIAppTopBar.kt +++ b/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUIAppTopBar.kt @@ -12,6 +12,7 @@ import androidx.compose.material3.TopAppBarColors import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -85,6 +86,7 @@ import com.tarkalabs.tarkaui.theme.TUITheme searchQueryHint : String = "", disableSearchIcon: Boolean = false, clearQueryAndHideSearchBar: Boolean = false, + toggleSearchbar: Boolean = false, colors: TopAppBarColors = TopAppBarDefaults.topAppBarColors( containerColor = TUITheme.colors.surface ), @@ -100,6 +102,9 @@ import com.tarkalabs.tarkaui.theme.TUITheme showSearchBar = false onSearchQuery("") } + LaunchedEffect(key1 = toggleSearchbar){ + showSearchBar = toggleSearchbar + } Column( modifier = modifier From bd962eccfe6464644d075939f7c72f35145e99e8 Mon Sep 17 00:00:00 2001 From: Raja Jawahar Date: Tue, 5 Mar 2024 13:07:10 +0530 Subject: [PATCH 2/2] Minor optimisation in SearchBar naming --- .../tarkalabs/ui/UIComponentListActivity.kt | 2 +- .../tarkaui/components/TUIAppTopBar.kt | 40 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/example/src/main/java/com/tarkalabs/ui/UIComponentListActivity.kt b/example/src/main/java/com/tarkalabs/ui/UIComponentListActivity.kt index fbc3819f..a51e4d33 100644 --- a/example/src/main/java/com/tarkalabs/ui/UIComponentListActivity.kt +++ b/example/src/main/java/com/tarkalabs/ui/UIComponentListActivity.kt @@ -53,7 +53,7 @@ class UIComponentListActivity : ComponentActivity() { onSearchQuery = { query = it }, - toggleSearchbar = showSearchbar + showSearchBar = showSearchbar ) }) { paddingValues -> diff --git a/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUIAppTopBar.kt b/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUIAppTopBar.kt index 8c01450d..c1470392 100644 --- a/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUIAppTopBar.kt +++ b/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUIAppTopBar.kt @@ -82,11 +82,11 @@ import com.tarkalabs.tarkaui.theme.TUITheme onSecondMenuItemClicked: () -> Unit = {}, onThirdMenuItemClicked: () -> Unit = {}, onSearchQuery: (String) -> Unit = {}, - searchQuery : String = "", - searchQueryHint : String = "", + searchQuery: String = "", + searchQueryHint: String = "", disableSearchIcon: Boolean = false, clearQueryAndHideSearchBar: Boolean = false, - toggleSearchbar: Boolean = false, + showSearchBar: Boolean = false, colors: TopAppBarColors = TopAppBarDefaults.topAppBarColors( containerColor = TUITheme.colors.surface ), @@ -94,26 +94,25 @@ import com.tarkalabs.tarkaui.theme.TUITheme tags: TUIAppTopBarTags = TUIAppTopBarTags(), ) { - var showSearchBar by remember { + var showSearchBarState by remember { mutableStateOf(false) } - if (clearQueryAndHideSearchBar && showSearchBar) { - showSearchBar = false + if (clearQueryAndHideSearchBar && showSearchBarState) { + showSearchBarState = false onSearchQuery("") } - LaunchedEffect(key1 = toggleSearchbar){ - showSearchBar = toggleSearchbar + LaunchedEffect(key1 = showSearchBar) { + showSearchBarState = showSearchBar } Column( modifier = modifier .background(color = TUITheme.colors.surface) .fillMaxWidth() - .wrapContentHeight(), - horizontalAlignment = Alignment.CenterHorizontally + .wrapContentHeight(), horizontalAlignment = Alignment.CenterHorizontally ) { - if (showSearchBar) { + if (showSearchBarState) { TUISearchBar( modifier = Modifier .fillMaxWidth() @@ -122,7 +121,7 @@ import com.tarkalabs.tarkaui.theme.TUITheme placeholder = searchQueryHint, leadingIcon = TarkaIcons.Regular.ChevronLeft24, onLeadingIconClick = { - showSearchBar = false + showSearchBarState = false onSearchQuery("") }, onQueryTextChange = { @@ -141,7 +140,7 @@ import com.tarkalabs.tarkaui.theme.TUITheme }, navigationIcon = { if (navigationIcon != null) { - if (!showSearchBar) { + if (!showSearchBarState) { TUIIconButton( onIconClick = onNavigationIconClick, icon = navigationIcon, @@ -153,7 +152,7 @@ import com.tarkalabs.tarkaui.theme.TUITheme } }, actions = { - if (!showSearchBar) { + if (!showSearchBarState) { if (searchIcon != null) { TUIIconButton( icon = searchIcon, @@ -161,7 +160,7 @@ import com.tarkalabs.tarkaui.theme.TUITheme iconButtonStyle = GHOST, onIconClick = { if (!disableSearchIcon) { - showSearchBar = true + showSearchBarState = true } }, buttonSize = XL @@ -229,9 +228,7 @@ data class TUIAppTopBarTags( menuItemIconThree = TarkaIcons.Regular.ChevronRight20, searchQuery = "Search", onSearchQuery = { _ -> - }, - searchIcon = TarkaIcons.Regular.Search24, - searchQueryHint = "Search" + }, searchIcon = TarkaIcons.Regular.Search24, searchQueryHint = "Search" ) VerticalSpacer(space = 5) TUIAppTopBar( @@ -239,6 +236,13 @@ data class TUIAppTopBarTags( navigationIcon = TarkaIcons.Regular.ChevronRight20, searchIcon = TarkaIcons.Regular.Search16 ) + VerticalSpacer(space = 5) + TUIAppTopBar( + title = "Lorem Ipsum", + navigationIcon = TarkaIcons.Regular.ChevronRight20, + searchIcon = TarkaIcons.Regular.Search16, + showSearchBar = true + ) } } }