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

[desktop] SwingPanel not work with Snackbar #3474

Closed
xinkunZ opened this issue Aug 9, 2023 · 5 comments
Closed

[desktop] SwingPanel not work with Snackbar #3474

xinkunZ opened this issue Aug 9, 2023 · 5 comments
Assignees
Labels
bug Something isn't working desktop duplicate This issue or pull request already exists reproduced swing interop Swing interop issue

Comments

@xinkunZ
Copy link

xinkunZ commented Aug 9, 2023

  1. Snackbar works with Text
            Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
                Box(modifier = Modifier.matchParentSize()) {
                    Text("aaaa")
                    Snackbar(
                        action = { Button(onClick = {}) {} },
                        modifier = Modifier.padding(8.dp).align(Alignment.BottomCenter)
                    ) { Text(text = "This is a snackbar!") }
                }
            }

image

  1. not work with Swing JPanel
            Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
                Box(modifier = Modifier.matchParentSize()) {
                    SwingPanel(factory = {
                        JPanel().apply {
                            background = java.awt.Color.red
                        }
                    })
                    Snackbar(
                        action = { Button(onClick = {}) {} },
                        modifier = Modifier.padding(8.dp).align(Alignment.BottomCenter)
                    ) { Text(text = "This is a snackbar!") }
                }
            }

image

@xinkunZ xinkunZ added bug Something isn't working submitted labels Aug 9, 2023
@elijah-semyonov
Copy link
Contributor

Thanks for the report, we will look into it.

@alexzhirkevich
Copy link
Contributor

SwingPanel is always on top of compose content. Just use snackbar inside of panel or use column and display it below panel
#2926

@elijah-semyonov elijah-semyonov added the duplicate This issue or pull request already exists label Aug 9, 2023
@xinkunZ
Copy link
Author

xinkunZ commented Aug 16, 2023

@alexzhirkevich so the snackbar can only display below swingpanel but can not float on it?

@alexzhirkevich
Copy link
Contributor

alexzhirkevich commented Aug 16, 2023

@xinkunZ You can have a ComposePanel with snackbar attached to your swing panel component, but i assume you have to manually manage its size and position

@MatkovIvan
Copy link
Member

MatkovIvan commented Nov 27, 2023

SwingPanel is always on top of compose content.

It's actually depend on platform 😕. It's always under Compose on macOS, but Compose uses those component bounds to clip the content.
JetBrains/compose-multiplatform-core#915 changes a way of drawing "the hole" in Compose so it won't affect overlapping elements anymore. I've added the code snippet that shared above to show how it behaves now.

MatkovIvan added a commit to JetBrains/compose-multiplatform-core that referenced this issue Dec 15, 2023
## Proposed Changes

- Adopt an approach that we're using for iOS - using custom blending to
respect clip/shape modifiers and overlapped drawings.
- Fix bounds in window calculation - it should work properly inside
scaled content now.

## Testing

The new behavior is under a feature flag, so you can test it by setting
system property:

```kt
System.setProperty("compose.interop.blending", "true")
```

Currently it supports Metal (macOS), Direct3D (Windows) (requires
JetBrains/skiko#837), and off-screen rendering
(might be enable by another feature flag:
`compose.swing.render.on.graphics`)

### Clipping

```kt
SwingPanel(
    modifier = Modifier.clip(RoundedCornerShape(6.dp))
    ...
)
```
<img width="262" alt="image"
src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/a03926f5-8977-4530-8894-d84aedfd5939">

### Overlapping

```kt
Box(modifier = Modifier.fillMaxSize()) {
    SwingPanel(factory = {
        JPanel().also { panel ->
            panel.background = java.awt.Color.red
            panel.add(JButton().also { button ->
                button.text = "JButton"
            })
        }
    })
    Snackbar(
        action = { Button(onClick = {}) { Text("OK") } },
        modifier = Modifier.padding(8.dp).align(Alignment.BottomCenter),
    ) {
        Text("Snackbar")
    }
    Popup(alignment = Alignment.Center) {
        Box(
            modifier = Modifier.size(200.dp, 100.dp).background(Gray),
            contentAlignment = Alignment.Center,
        ) {

            Text("Popup")
        }

    }
}
```
<img width="592" alt="Screenshot 2023-11-27 at 13 57 43"
src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/dda1f2d6-6a1e-456c-8763-46a82d9562a8">


## Issues Fixed

Fixes JetBrains/compose-multiplatform#3823
Fixes JetBrains/compose-multiplatform#3739
Fixes JetBrains/compose-multiplatform#3353
Fixes JetBrains/compose-multiplatform#3474
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 duplicate This issue or pull request already exists reproduced swing interop Swing interop issue
Projects
None yet
Development

No branches or pull requests

4 participants