Skip to content

berkayKirecci/KMP-CrossMessages

Repository files navigation

📦 Compose CrossMessages

Compose CrossMessages is a simple and lightweight library for displaying messages across Android and iOS using Jetpack Compose Multiplatform (KMP).
It currently supports:

  • ✅ Custom Snackbar UI for Compose-based apps
  • ✅ Native Toast Messages and Alert Dialogs using platform-specific APIs:
    • AlertDialog on Android
    • UIAlertController on iOS

✨ Features

  • Cross-platform message handling with shared API
  • Snackbar supports:
    • Custom actions
    • Duration control
    • Queued messages
  • Native toast messages and alerts on both platforms
  • Designed for KMP-first projects

🎞️ Demo

Android Snackbar Demo   iOS Snackbar Demo


🚀 Getting Started

1. Add Dependency

Gradle (Kotlin DSL)

dependencies {
    implementation("io.github.berkaykirecci:crossmessages:$version")
}

2. Example Usages

📍 Show Snackbar Messages

🔹 Default Types

val snackbarState = rememberSnackbarState()
MultiPlatformSnackbar(state = snackbarState)

snackbarState.success("Success Message")
snackbarState.warning("Warning Message")
snackbarState.error("Error Message")
snackbarState.info("Info Message")

🔹 Change Default Snacbkar Colors

CompositionLocalProvider(
  LocalSnackbarColors provides DefaultSnackbarColors(success = Color.Green)
) {
  val snackbarState = rememberSnackbarState()
  MultiPlatformSnackbar(state = snackbarState)

  snackbarState.success("Success Message")
}

🔹 Fully Customized Snackbar

snackbarState.show(
    SnackbarModel(
        message = "Custom Message",
        backgroundColor = Color.Black,
        duration = 3000L,
        showActionButton = true,
        actionButtonModel = ActionButtonModel(
            iconRes = Res.drawable.action_btn,
            onActionClick = { }
        ),
        leadingIconModel = LeadingIconModel(
            iconRes = Res.drawable.icon,
            iconTint = Color.LightGray,
            iconSize = 18.dp
        ),
        textModel = TextModel(
            textColor = Color.Yellow,
            textAlignment = TextAlign.Center
        ),
        alignment = Alignment.TopCenter
    )
)

📍 Show Toast Messages

val toastState = rememberToastState()
Toast(state = toastState)

toastState.show("Toast Message")

📍 Show Native Alert

val alertState = rememberAlertState()
Alert(state = alertState)

alertState.show(
    AlertModel(
        message = "Alert Message",
        title = "Alert Title",
        actions = listOf(
            DialogAction("Ok", ActionStyle.DEFAULT),
            DialogAction("Cancel", ActionStyle.CANCEL)
        )
    )
)

📄 License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and 
limitations under the License.

👋 Contributing

Pull requests and issues are welcome!

About

Cross-platform Snackbar/Toast for Kotlin Compose Multiplatform (Android & iOS)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages