### Implement local SnackbarBox in screen Source: https://github.com/ajiekcx/declarativesnackbar/blob/master/README.md Display local snackbars with custom UI and action handling. ```kotlin SnackbarBox( component = viewModel.snackbarComponent, alignment = Alignment.TopCenter, snackbarContent = { message -> Snackbar( modifier = Modifier.padding(horizontal = 16.dp), action = { if (message is MySnackbarMessage.TextWithAction) { TextButton(onClick = { message.onActionClick() }) { Text(message.actionTitle) } } } ) { Text(message.message) } }, ) { // Your screen content here } ``` -------------------------------- ### Create global snackbar component Source: https://github.com/ajiekcx/declarativesnackbar/blob/master/README.md Define a global snackbar component object. Use dependency injection in production environments. ```kotlin object GlobalSnackbarComponent: SnackbarComponent by SnackbarComponent() ``` -------------------------------- ### Add dependency to build.gradle.kts Source: https://github.com/ajiekcx/declarativesnackbar/blob/master/README.md Include the necessary library dependencies in your Gradle configuration. ```kotlin dependencies { implementation("io.github.ajiekcx:declarative-snackbar-compose:0.2.0") implementation("io.github.ajiekcx:declarative-snackbar-core:0.2.0") // Optional, for modules without compose dependency } ``` -------------------------------- ### Wrap app content with SnackbarBox Source: https://github.com/ajiekcx/declarativesnackbar/blob/master/README.md Integrate the snackbar component into the UI hierarchy using SnackbarBox. ```kotlin SnackbarBox( component = GlobalSnackbarComponent, snackbarContent = { message -> Snackbar { Text(message) } }, ) { // Your app content here } ``` -------------------------------- ### Create local snackbar component in ViewModel Source: https://github.com/ajiekcx/declarativesnackbar/blob/master/README.md Manage a local snackbar component within a ViewModel, ensuring cleanup on destruction. ```kotlin class MyViewModel : ViewModel() { val snackbarComponent: SnackbarComponent = SnackbarComponent() fun showMessage() { snackbarComponent.show( SnackbarMessage( content = MySnackbarMessage.Text("This is a local message"), duration = SnackbarDuration.Short ) ) } override fun onCleared() { super.onCleared() snackbarComponent.onDestroy() } } ``` -------------------------------- ### Show global snackbar message Source: https://github.com/ajiekcx/declarativesnackbar/blob/master/README.md Trigger a snackbar message from the presentation layer. ```kotlin GlobalSnackbarComponent.show( SnackbarMessage( content = "This is a global message", duration = SnackbarDuration.Short ) ) ``` -------------------------------- ### Define custom snackbar message types Source: https://github.com/ajiekcx/declarativesnackbar/blob/master/README.md Create a sealed interface to support type-safe custom snackbar messages. ```kotlin sealed interface MySnackbarMessage { val message: String class Text(override val message: String) : MySnackbarMessage class TextWithAction( override val message: String, val actionTitle: String, val onActionClick: () -> Unit ) : MySnackbarMessage } ``` -------------------------------- ### Apply overlap prevention modifiers Source: https://github.com/ajiekcx/declarativesnackbar/blob/master/README.md Use modifiers to ensure snackbars do not overlap with top or bottom UI elements. ```kotlin SnackbarBox() { Scaffold( topBar = { TopAppBar( title = { Text("Title") }, modifier = Modifier.noOverlapTopContentBySnackbar() ) }, bottomBar = { NavigationBar( modifier = Modifier.noOverlapBottomContentBySnackbar() ) } ) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.