Skip to content

Commit

Permalink
Minor optimisation in SearchBar naming
Browse files Browse the repository at this point in the history
  • Loading branch information
rajajawahar committed Mar 5, 2024
1 parent 754924c commit bd962ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class UIComponentListActivity : ComponentActivity() {
onSearchQuery = {
query = it
},
toggleSearchbar = showSearchbar
showSearchBar = showSearchbar
)

}) { paddingValues ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,37 @@ 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
),
scrollBehavior: TopAppBarScrollBehavior? = null,
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()
Expand All @@ -122,7 +121,7 @@ import com.tarkalabs.tarkaui.theme.TUITheme
placeholder = searchQueryHint,
leadingIcon = TarkaIcons.Regular.ChevronLeft24,
onLeadingIconClick = {
showSearchBar = false
showSearchBarState = false
onSearchQuery("")
},
onQueryTextChange = {
Expand All @@ -141,7 +140,7 @@ import com.tarkalabs.tarkaui.theme.TUITheme
},
navigationIcon = {
if (navigationIcon != null) {
if (!showSearchBar) {
if (!showSearchBarState) {
TUIIconButton(
onIconClick = onNavigationIconClick,
icon = navigationIcon,
Expand All @@ -153,15 +152,15 @@ import com.tarkalabs.tarkaui.theme.TUITheme
}
},
actions = {
if (!showSearchBar) {
if (!showSearchBarState) {
if (searchIcon != null) {
TUIIconButton(
icon = searchIcon,
tags = tags.searchIconTags,
iconButtonStyle = GHOST,
onIconClick = {
if (!disableSearchIcon) {
showSearchBar = true
showSearchBarState = true
}
},
buttonSize = XL
Expand Down Expand Up @@ -229,16 +228,21 @@ 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(
title = "Lorem Ipsum",
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
)
}
}
}

0 comments on commit bd962ec

Please sign in to comment.