JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.92k stars 1.16k forks source link

ModalDrawer opens and closes (fast) on window resize #1122

Open brolicious12 opened 3 years ago

brolicious12 commented 3 years ago

23-01-34

import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.DrawerValue
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ModalDrawer
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import kotlinx.coroutines.launch

fun main() = application {
    Window(onCloseRequest = this::exitApplication) {
        MaterialTheme {
            drawer()
        }
    }
}

@Composable
fun drawer() {
    var DrawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
    var CoroutineScope = rememberCoroutineScope()
    ModalDrawer(content = {
        TopAppBar {
            IconButton(onClick = {
                CoroutineScope.launch {
                    DrawerState.open()
                }
            }) {
                Icon(contentDescription = null,
                     imageVector = Icons.Filled.Menu)
            }
            Text("topappbar")
        }

    },
                drawerState = DrawerState,
                drawerContent = {
                    LazyColumn {
                        item { menu() }
                        item { menu() }
                        item { menu() }
                        item { menu() }
                        item { menu() }
                        item { menu() }
                        item { menu() }
                        item { menu() }
                        item { menu() }
                        item { menu() }
                    }
                })
}

@Composable
fun menu() {
    Text(text = "item", modifier = Modifier
        .padding(start = 15.dp))
}

version ("1.0.0-alpha4-build328")

akurasov commented 3 years ago

Reproduced on the latest (348) build. It is enough to drag window border to increase it size. When size is decreased there is no issue.

brolicious12 commented 2 years ago

version 1.1.0-alpha04 still unfixed. Furthermore it happens also with the ModalBottomSheetLayout if you just increase the height of the window. I guess it has to do something with the widgets offset is updated after the resize and render of the window is completed. Cant test it on android because i have non resizeable phones.

okushnikov commented 3 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.