Created
August 18, 2021 18:07
-
-
Save axelbrians/c192159320fe1a93124b62a3ce26c484 to your computer and use it in GitHub Desktop.
HomeScreen Note Compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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