PopupHost

ViewModel-like retained model helper for dialogs and popups, composable integration with declarative entryProvider and metadata-based factories, typed PopupId, and synchronous showDialog result delivery.

Android JVMJVMKotlin/Native
GitHub stars1
Authorsandannn
Dependents0
OSS Health
LicenseApache License 2.0
Creation date5 months ago

Last activity13 days ago
Latest release1.0.2 (2 months ago)

A simple suspending API to show popups such as dialogs and bottom sheets.

Important: Popups shown using this library are not restored after process death.

Install

libs.versions.toml

[versions]
popuphost = "1.0.0"

[dependencies]
popuphost = { group = "io.github.andannn", name = "popuphost", version.ref = "popuphost" }

then

dependencies {
    implementation(libs.popuphost)
}

Quick Start

  1. Define DialogId
object DialogA : PopupId<Long>
  1. Setup PopupHost
@Composable
fun App() {
    val popupHostState = remember { PopupHostState() }
    PopupHost(
        popupHostState = popupHostState,
        entryProvider = entryProvider {
            entry(
                metadata = DialogFactoryProvider.metadata()
            ) { dialogId, onAction ->
                Surface(
                    modifier = Modifier.wrapContentSize(),
                    shape = AlertDialogDefaults.shape,
                    tonalElevation = AlertDialogDefaults.TonalElevation,
                ) {
                    DialogAContent(dialogId, onAction)
                }
            }
        }
    )
}

@Composable
fun DialogAContent(dialogA: DialogA, onAction: (Long) -> Unit) {
    Column(modifier = Modifier.padding(16.dp)) {
        Text(text = "Dialog A")
        Button(
            onClick = {
                // set Result
                onAction(123L)
            },
        ) {
            Text(
                text = "Set Result",
            )
        }
    }
}
  1. Show popup
val result: Long? = popupHostState.showDialog(DialogA)
Android JVMJVMKotlin/Native
GitHub stars1
Authorsandannn
Dependents0
OSS Health
LicenseApache License 2.0
Creation date5 months ago

Last activity13 days ago
Latest release1.0.2 (2 months ago)

A simple suspending API to show popups such as dialogs and bottom sheets.

Important: Popups shown using this library are not restored after process death.

Install

libs.versions.toml

[versions]
popuphost = "1.0.0"

[dependencies]
popuphost = { group = "io.github.andannn", name = "popuphost", version.ref = "popuphost" }

then

dependencies {
    implementation(libs.popuphost)
}

Quick Start

  1. Define DialogId
object DialogA : PopupId<Long>
  1. Setup PopupHost
@Composable
fun App() {
    val popupHostState = remember { PopupHostState() }
    PopupHost(
        popupHostState = popupHostState,
        entryProvider = entryProvider {
            entry(
                metadata = DialogFactoryProvider.metadata()
            ) { dialogId, onAction ->
                Surface(
                    modifier = Modifier.wrapContentSize(),
                    shape = AlertDialogDefaults.shape,
                    tonalElevation = AlertDialogDefaults.TonalElevation,
                ) {
                    DialogAContent(dialogId, onAction)
                }
            }
        }
    )
}

@Composable
fun DialogAContent(dialogA: DialogA, onAction: (Long) -> Unit) {
    Column(modifier = Modifier.padding(16.dp)) {
        Text(text = "Dialog A")
        Button(
            onClick = {
                // set Result
                onAction(123L)
            },
        ) {
            Text(
                text = "Set Result",
            )
        }
    }
}
  1. Show popup
val result: Long? = popupHostState.showDialog(DialogA)