Ahmad Hassan
03/22/2023, 2:32 PMArkadii Ivanov
03/22/2023, 2:59 PMAhmad Hassan
03/22/2023, 3:05 PMinternal fun NoteListScreen(
viewModel: NoteListViewModelComponent
) {
val state by viewModel.state.collectAsState()
LaunchedEffect(key1 = true) {
viewModel.loadNotes()
}
Scaffold(
floatingActionButton = {
FloatingActionButton(
onClick = {
viewModel.onAddORItemClicked(null)
},
backgroundColor = Color.Black,
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = "Add Note",
tint = Color.White
)
}
},
) { padding ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(padding),
) {
Box(
modifier = Modifier.fillMaxWidth(),
contentAlignment = Alignment.Center
) {
HideableSearchTextField(
text = state.searchText,
onTextChange = viewModel::onSearchTextChange,
isSearchActive = state.isSearchActive,
onSearchClick = viewModel::onToggleSearch,
onCloseClick = viewModel::onToggleSearch,
modifier = Modifier
.fillMaxWidth()
.height(90.dp)
)
this@Column.AnimatedVisibility(
visible = !state.isSearchActive,
enter = fadeIn(),
exit = fadeOut()
) {
Text(
text = "All Notes",
fontWeight = FontWeight.Bold,
fontSize = 30.sp
)
}
}
LazyColumn(
modifier = Modifier
.weight(1f)
) {
items(
items = state.notes,
key = { it.id!! }
) { note ->
NoteItem(
note = note,
backgroundColor = Color(note.colorHex),
onNoteClick = {
viewModel.onAddORItemClicked(note.id)
},
onDeleteClick = {
viewModel.deleteNote(note.id!!)
},
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.animateItemPlacement()
)
}
}
}
}
}
Arkadii Ivanov
03/22/2023, 3:29 PMNoteListViewModelComponent#state
is of type Flow
. The code looks correct. But since Decompose components are just normal classes, this looks a bit unrelated to Decompose.
Please make sure that the state is actually updated in the component. You can add some logs to verify that.
Also a common mistake with Decompose + Compose for iOS - make sure you have called root's LifecycleRegistery.resume
after you created the root component.Ahmad Hassan
03/24/2023, 8:24 AMArkadii Ivanov
03/24/2023, 10:50 AM