From bd962eccfe6464644d075939f7c72f35145e99e8 Mon Sep 17 00:00:00 2001 From: Raja Jawahar Date: Tue, 5 Mar 2024 13:07:10 +0530 Subject: [PATCH] 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 + ) } } }