Skip to content

Commit 375c25c

Browse files
committed
Document TrayWindowDismissMode with examples in README.md
- Added usage examples and runtime behavior for `TrayWindowDismissMode` API in README.md. - Updated `TrayAppDemo` to use `TrayWindowDismissMode.AUTO` as the default dismiss mode.
1 parent 8d55f0c commit 375c25c

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,48 @@ trayAppState.setWindowSize(400.dp, 600.dp)
646646
trayAppState.setWindowSize(DpSize(350.dp, 500.dp))
647647
```
648648

649+
## 🧩 New: Tray Window Dismiss Modes
650+
651+
By default, the `TrayApp` popup window closes automatically when it loses focus or when the user clicks outside of it.
652+
With the new `TrayWindowDismissMode` API, you can choose between:
653+
654+
* **AUTO** (default): The popup closes automatically when focus is lost or when clicking outside.
655+
* **MANUAL**: The popup remains visible until you explicitly call `trayAppState.hide()`.
656+
657+
### Example
658+
659+
```kotlin
660+
@OptIn(ExperimentalTrayAppApi::class)
661+
application {
662+
val trayAppState = rememberTrayAppState(
663+
initialWindowSize = DpSize(300.dp, 400.dp),
664+
initiallyVisible = false,
665+
initialDismissMode = TrayWindowDismissMode.MANUAL // 👈 Manual mode
666+
)
667+
668+
TrayApp(
669+
state = trayAppState,
670+
icon = Icons.Default.Settings,
671+
tooltip = "Quick Settings"
672+
) {
673+
Column {
674+
Text("This popup will NOT auto-close")
675+
Button(onClick = { trayAppState.hide() }) {
676+
Text("Close manually")
677+
}
678+
}
679+
}
680+
}
681+
```
682+
683+
### Switching at runtime
684+
685+
```kotlin
686+
LaunchedEffect(Unit) {
687+
trayAppState.setDismissMode(TrayWindowDismissMode.AUTO)
688+
}
689+
```
690+
649691
### Advanced Examples
650692

651693
#### Example 1: Control from Main Window

demo/src/jvmMain/kotlin/com/kdroid/composetray/demo/TrayAppDemo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fun main() {
4343
val trayAppState = rememberTrayAppState(
4444
initialWindowSize = DpSize(300.dp, 500.dp),
4545
initiallyVisible = true,
46-
initialDismissMode = TrayWindowDismissMode.MANUAL
46+
initialDismissMode = TrayWindowDismissMode.AUTO
4747
)
4848

4949
// Observe visibility changes

0 commit comments

Comments
 (0)