André Thiele
06/04/2021, 1:12 PMFilip Wiesner
06/04/2021, 1:15 PMAndré Thiele
06/04/2021, 1:19 PM@Composable
fun PlacesSearch(
currentlySearchedPlaces: List<PlaceEntity>,
onItemBookmarkClicked: (PlaceEntity) -> Unit,
onPlaceSearched: (PlaceEntity) -> Unit,
onPlaceClicked: (PlaceEntity) -> Unit,
) {
if (currentlySearchedPlaces.isNotEmpty()) {
Log.e("Searched places", "$currentlySearchedPlaces")
RulonaSearchList(
places = currentlySearchedPlaces,
onItemClick = { uuid ->
onPlaceClicked(uuid)
onPlaceSearched(uuid)
},
onItemBookmarkClicked = {
onItemBookmarkClicked(it)
},
)
}
}
@Composable
fun RulonaSearchList(
places: List<PlaceEntity>,
onItemClick: (PlaceEntity) -> Unit,
onItemBookmarkClicked: (PlaceEntity) -> Unit,
) {
Log.e("rendering places", "$places")
LazyColumn {
items(places) { place ->
Log.e("item in list", "$place")
RulonaSearchItem(
title = place.name,
isBookmarked = place.isBookmarked,
onClick = { onItemClick(place) },
onBookmarkClicked = { onItemBookmarkClicked(place) },
)
}
}
}
As you can see in the logs, the items correctly update with the new bookmarked state but the "item in list" log is not called again, which means that the SearchItem does not recompose inside the listFilip Wiesner
06/04/2021, 1:27 PMcurrentlySearchedPlaces
? It looks that you have that data in a VM somewhere. Do you use collextAsState()
on your search places?André Thiele
06/04/2021, 1:29 PMval placesUiState = viewModel.collectAsState(PlacesState::uiState)
PlacesSearch(
currentlySearchedPlaces = uiState.currentlySearchedPlaces,
onItemBookmarkClicked = { place ->
viewModel.action(TogglePlaceBookmarkUseCase(place))
},
onPlaceSearched = { place ->
viewModel.action(SetPlaceSearchTimestampUseCase(place))
},
onPlaceClicked = { place -> onPlaceClicked(place.uuid) },
)
Andrey Kulikov
06/04/2021, 1:29 PMAndré Thiele
06/04/2021, 1:30 PMAndrey Kulikov
06/04/2021, 1:36 PMitems(places) {…}
to items(places, key = { it.toString() } ) {}
will it work?André Thiele
06/04/2021, 1:39 PMAndrey Kulikov
06/04/2021, 1:41 PMAndré Thiele
06/04/2021, 1:42 PM