Skip to content

Instantly share code, notes, and snippets.

@axelbrians
Created August 18, 2021 18:07
Show Gist options
  • Save axelbrians/c192159320fe1a93124b62a3ce26c484 to your computer and use it in GitHub Desktop.
Save axelbrians/c192159320fe1a93124b62a3ce26c484 to your computer and use it in GitHub Desktop.
HomeScreen Note Compose
@ExperimentalAnimationApi
@ExperimentalMaterialApi
@Composable
fun HomeScreen() {
var notes by remember {
mutableStateOf(
listOf(
Note(1,"1st Note", "Curabitur gravida eros sed magna."),
Note(2,"2nd Note", "Etiam posuere volutpat luctus. Sed."),
Note(3,"3rd Note", "Lorem ipsum dolor sit amet")
)
)
}
LazyColumn {
items(
items = notes,
key = { item: Note -> item.id }
) { item ->
AnimatedVisibility(
visible = item.isVisible,
exit = fadeOut(
animationSpec = TweenSpec(200, 200, FastOutLinearInEasing)
)
) {
ItemNote(item) {
notes = changeNoteVisibility(notes, it)
}
}
}
}
}
fun changeNoteVisibility(notes: List<Note>, removedNote: Note): List<Note> {
return notes.map { currentNote ->
if (currentNote.id == removedNote.id) {
currentNote.copy(isVisible = false)
} else {
currentNote
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment