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#stateFlowLifecycleRegistery.resumeAhmad Hassan
03/24/2023, 8:24 AMAhmad Hassan
03/24/2023, 10:31 AMArkadii Ivanov
03/24/2023, 10:50 AMArkadii Ivanov
03/24/2023, 10:52 AM