Created
October 9, 2022 18:19
-
-
Save sergei-mikhailovskii-idf/7617fe231e433a6e3afecaf0620e15bd to your computer and use it in GitHub Desktop.
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
enum class SnackbarState { | |
DEFAULT, | |
ERROR | |
} | |
internal class SnackbarDelegate( | |
var snackbarHostState: SnackbarHostState? = null, | |
var coroutineScope: CoroutineScope? = null | |
) { | |
private var snackbarState: SnackbarState = SnackbarState.DEFAULT | |
val snackbarBackgroundColor: Color | |
@Composable | |
get() = when (snackbarState) { | |
SnackbarState.DEFAULT -> SnackbarDefaults.backgroundColor | |
SnackbarState.ERROR -> ErrorColor | |
} | |
fun showSnackbar( | |
state: SnackbarState, | |
message: String, | |
actionLabel: String? = null, | |
duration: SnackbarDuration = SnackbarDuration.Short | |
) { | |
this.snackbarState = state | |
coroutineScope?.launch { | |
snackbarHostState?.showSnackbar(message, actionLabel, duration) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment