Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popup doesn't dismiss if it is inside Lazy component #412

Open
igordmn opened this issue Feb 21, 2021 · 0 comments
Open

Popup doesn't dismiss if it is inside Lazy component #412

igordmn opened this issue Feb 21, 2021 · 0 comments
Assignees
Labels
bug Something isn't working desktop

Comments

@igordmn
Copy link
Collaborator

igordmn commented Feb 21, 2021

Compose v0.3.0-rc1

import androidx.compose.desktop.Window
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.GridCells
import androidx.compose.foundation.lazy.LazyVerticalGrid
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup

@ExperimentalFoundationApi
fun main() = Window {
    var popupState2 by remember { mutableStateOf(false) }
    LazyVerticalGrid(GridCells.Fixed(3)) {
        items((1..1).toList()) {
            var popupState by remember { mutableStateOf(false) }
            if (popupState) {
                val onDismissRequest = {
                    println("onDismissRequest")
                    popupState = false
                    // uncomment this and onDismissRequest will be called,
                    // otherwise it will not be called
                    //popupState2 = false
                }
                Popup(isFocusable = true, onDismissRequest = onDismissRequest) {
                    Text("Popup $it", modifier = Modifier.size(120.dp).background(Color.Blue))
                }
            }
            Box(Modifier.padding(1.dp).size(40.dp).clickable {
                popupState = true
            }) {
                Text("Show $it")
            }
        }
    }
}

onDismissRequest isn't called when we click outside Popup. But if we uncomment popupState2 = false, it will be called.
Maybe it is a bug in "compose.runtime" (lambda with the same hashCode is called inside Popup, but doesn't print anything 🤔)

@igordmn igordmn added the bug Something isn't working label Feb 21, 2021
@igordmn igordmn self-assigned this Mar 11, 2021
@igordmn igordmn added this to the 1.0 milestone Nov 2, 2021
@igordmn igordmn removed this from the 1.0 milestone Nov 18, 2021
@igordmn igordmn removed the p:normal label Dec 9, 2022
MatkovIvan pushed a commit to MatkovIvan/compose-multiplatform that referenced this issue May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working desktop
Projects
None yet
Development

No branches or pull requests

2 participants