From 0c1acf3313fd99e37dc4b519a7ce4ce12f386535 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 26 Sep 2024 16:22:46 +0200 Subject: [PATCH] add mode change callback Signed-off-by: Pablo --- .../component/LocationSearchBar.kt | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/LocationSearchBar.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/LocationSearchBar.kt index c12ad1f9a..de3c4f7a2 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/LocationSearchBar.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/LocationSearchBar.kt @@ -57,7 +57,7 @@ import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing.Spacing16 import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor -private enum class SearchBarMode { +enum class SearchBarMode { BUTTON, SEARCH, } @@ -67,11 +67,17 @@ fun LocationBar( currentResults: List, onBackClicked: () -> Unit, onClearLocation: () -> Unit, - onSearchLocation: (String) -> Unit, + onSearchLocation: (query: String) -> Unit, onLocationSelected: (LocationItemModel) -> Unit, + onModeChanged:(currentMode: SearchBarMode) -> Unit = {}, ) { var currentMode by remember { mutableStateOf(SearchBarMode.BUTTON) } var currentSearch: String by remember { mutableStateOf("") } + + LaunchedEffect(currentMode){ + onModeChanged(currentMode) + } + when (currentMode) { SearchBarMode.BUTTON -> LocationSearchBarButton( currentSearch = currentSearch, @@ -97,6 +103,10 @@ fun LocationBar( currentMode = SearchBarMode.BUTTON onSearchLocation(currentSearch) }, + onSearch = { searchQuery -> + currentMode = SearchBarMode.BUTTON + onSearchLocation(searchQuery) + }, onLocationSelected = { currentSearch = it.title onLocationSelected(it) @@ -170,6 +180,7 @@ private fun LocationSearchBar( currentSearch: String = "", currentResults: List, onSearchChanged: (String) -> Unit, + onSearch: (String) -> Unit, onBackClicked: () -> Unit, onLocationSelected: (LocationItemModel) -> Unit, ) { @@ -187,7 +198,7 @@ private fun LocationSearchBar( placeHolderText = provideStringResource("search_location"), onActiveChange = {}, onQueryChange = onSearchChanged, - onSearch = onSearchChanged, + onSearch = onSearch, leadingIcon = { IconButton( style = IconButtonStyle.STANDARD, @@ -242,25 +253,13 @@ private fun LocationSearchBar( item { Row( modifier = Modifier.fillMaxWidth().padding(8.dp), - horizontalArrangement = spacedBy(16.dp), ) { - IconButton( - icon = { - Icon( - imageVector = Icons.Outlined.Map, - contentDescription = "map", - tint = SurfaceColor.Primary, - ) - }, - onClick = onBackClicked, - ) - Button( modifier = Modifier.fillMaxWidth(), style = ButtonStyle.TONAL, icon = { Icon( - imageVector = Icons.Outlined.TouchApp, + imageVector = Icons.Outlined.Map, contentDescription = "touch app", ) }, @@ -303,6 +302,8 @@ fun LocationItem( text = locationItemModel.subtitle, style = MaterialTheme.typography.bodySmall, color = TextColor.OnSurface, + maxLines = 1, + overflow = TextOverflow.Ellipsis ) } }