Created
September 29, 2020 21:02
-
-
Save alifhasnain/b0a6e71a52bef31e1ba6f829683db303 to your computer and use it in GitHub Desktop.
A Kotlin class which can help as being a wrapper around any other class to trigger the LiveData once.
This file contains 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
class Event<out R>(private val data: R) { | |
var hasEventBeenHandled = false | |
private set | |
val content: R? | |
get() = if (!hasEventBeenHandled) { | |
hasEventBeenHandled = true | |
data | |
} else { | |
null | |
} | |
val oldContent: R = data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment