Browse Source

Update README.md

pull/996/head
Igor Demin 3 years ago committed by GitHub
parent
commit
941540a28f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      tutorials/Window_API_new/README.md

40
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.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.window.WindowDraggableArea import androidx.compose.foundation.window.WindowDraggableArea
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp 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( fun main() = application {
undecorated = true Window(onCloseRequest = ::exitApplication) {
) { WindowDraggableArea {
WindowDraggableArea { Box(Modifier.fillMaxWidth().height(48.dp).background(Color.DarkGray))
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) ![](draggable_area.gif)

Loading…
Cancel
Save