Skip to content

About

Typed, extensible info/success/warning/error messages for Compose Multiplatform (Android + Desktop)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

message-compose

Typed, extensible info / success / warning / error messages for Compose Multiplatform (Android + Desktop). iOS is not a target yet.

implementation("io.github.ridvangnc:message-compose:0.1.0")

A message is two parts: a type (color, visible time, copy, icon) and a text (with {name} placeholders).

val state = remember { MessageHostState() }

MessageHost(state, placement = MessagePlacement.Top(), animation = MessageAnimation.Fade()) {
    Screen(onSave = { state.show(MessageType.Success(), "{name} saved.", "name" to "Invoice") })
}

The host draws the boxes above the content without blocking taps outside them. Boxes stack: a new one appears at the edge and pushes the older ones away, and each keeps its own timer. MessageHostState(maxVisible = 5) caps how many show at once; extra messages wait in a queue and enter one by one as slots free up (state.messages, state.queuedCount, state.clear()).

An action button next to the copy button runs your own code:

state.show(MessageType.Error(), "Upload failed", MessageAction("Report") { reportIssue() })

Extending

// New type: implement MessageType (no icon -> a gray circle with "?" is drawn)
data class Progress(
    override val color: Color = Color(0xFF1A237E),
    override val visibleTime: Duration = 6.seconds,
    override val copyEnabled: Boolean = false,
) : MessageType { override val kind = MessageKind("PROGRESS") }

when (val type = message.type) {
    is MessageType.Error -> …
    is Progress -> …   // smart cast; add `else` for types you do not know
}
Piece Built in Extend by
MessageType Info, Success, Warning, Error (data classes, copy them) implementing MessageType
MessageAnimation Fade, Grow (grows from 0 height at the placement edge) implementing enter(edge) / exit(edge)
MessagePlacement Top, Bottom, TopStick, BottomStick (edge-to-edge strip: no outer padding, no rounding), BubbleRight / BubbleLeft (floating, boxes hug the right / left side) implementing alignment / edge / fillWidth / padding / maxWidth / flush
MessageStyle shape, padding, text style, maxLines (2), colors, CopyButtonStyle copy(...)

Long text is cut with "…" after maxLines; the copy button always copies the full text.

Local development

./gradlew :message:desktopTest
./gradlew :demo:run

Using it from another project before publishing

Composite build, no Maven needed. In the consuming project's settings.gradle.kts:

includeBuild("../message-compose") {
    dependencySubstitution {
        substitute(module("io.github.ridvangnc:message-compose")).using(project(":message"))
    }
}

and depend on io.github.ridvangnc:message-compose:0.1.0 as usual. Edits here show up in the consumer on its next build.

About

Typed, extensible info/success/warning/error messages for Compose Multiplatform (Android + Desktop)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages