From 941540a28f28baba9ff20cd0615c997c886a96ed Mon Sep 17 00:00:00 2001 From: Igor Demin Date: Wed, 4 Aug 2021 11:45:15 +0300 Subject: [PATCH] Update README.md --- tutorials/Window_API_new/README.md | 40 +++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/tutorials/Window_API_new/README.md b/tutorials/Window_API_new/README.md index 1e0200d6fe..dc79de47c0 100644 --- a/tutorials/Window_API_new/README.md +++ b/tutorials/Window_API_new/README.md @@ -526,17 +526,45 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.window.WindowDraggableArea +import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp -import androidx.compose.ui.window.singleWindowApplication +import androidx.compose.ui.window.Window +import androidx.compose.ui.window.application -fun main() = singleWindowApplication( - undecorated = true -) { - WindowDraggableArea { - Box(Modifier.fillMaxWidth().height(48.dp).background(Color.DarkGray)) +fun main() = application { + Window(onCloseRequest = ::exitApplication) { + WindowDraggableArea { + Box(Modifier.fillMaxWidth().height(48.dp).background(Color.DarkGray)) + } } } ``` +Note that `WindowDraggableArea` can be used only inside `singleWindowApplication`, `Window` and `Dialog`. If you need to use it in the other Composable function, pass `WindowScope` as a reciever there: +``` +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.window.WindowDraggableArea +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Window +import androidx.compose.ui.window.WindowScope +import androidx.compose.ui.window.application + +fun main() = application { + Window(onCloseRequest = ::exitApplication) { + AppWindowTitleBar() + } +} + +@Composable +private fun WindowScope.AppWindowTitleBar() = WindowDraggableArea { + Box(Modifier.fillMaxWidth().height(48.dp).background(Color.DarkGray)) +} +``` ![](draggable_area.gif)