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

Allow z-ordering with Swing interop #2926

Closed
rock3r opened this issue Mar 27, 2023 · 4 comments · Fixed by JetBrains/compose-multiplatform-core#1145
Closed

Allow z-ordering with Swing interop #2926

rock3r opened this issue Mar 27, 2023 · 4 comments · Fixed by JetBrains/compose-multiplatform-core#1145
Assignees
Labels
enhancement New feature or request

Comments

@rock3r
Copy link
Contributor

rock3r commented Mar 27, 2023

Interop with Swing means any Swing content embedded in a Compose panel will always be at the top (max z-order). Content should be composited with the right z-order instead.

@rock3r rock3r added enhancement New feature or request submitted labels Mar 27, 2023
@mahozad
Copy link
Contributor

mahozad commented Apr 3, 2023

Is this issue related:
#1521

@rock3r
Copy link
Contributor Author

rock3r commented Apr 3, 2023

Yes it is in the premise, but that user then talks about issues with (lack of) recomposition when applying a workaround to try and solve the root problem, the lask of z-ordering APIs. The core issue has not been solved yet, as the documentation states:

A SwingPanel is a wrapper that controls the size, position and rendering of a Swing component that is placed on top of a Compose Multiplatform component, meaning the component inside a SwingPanel will always be on top of the Compose in depth. Anything that is misplaced and rests on the SwingPanel will be clipped by the Swing component placed there, so try to think about these situations, and if there is such a risk, then it is better to either redesign the UI accordingly, or stop using the SwingPanel and still try to implement the missing component, thereby contributing to the development of technology and making life easier for other developers.

From here

@xinkunZ
Copy link

xinkunZ commented Sep 14, 2023

😱 The issue makes AlertDialog(KMP 1.5) can not use with Swing too

@MatkovIvan
Copy link
Member

Partially fixed in JetBrains/compose-multiplatform-core#915. That change doesn't fix "z-order" itself, but changes a way to "clip the hole" for an interop component, so the content above it won't be affected anymore.

MatkovIvan added a commit to JetBrains/compose-multiplatform-core that referenced this issue Feb 29, 2024
## Proposed Changes

Currently on both Desktop and iOS interop views are added to the view
hierarchy in order to add nodes to Compose. It works only if all
intersecting interop views were added at the same time (frame). So it's
basically last-added - above-displayed. This PR changes this behavior in
a way that it will respect the order inside Compose like regular compose
elements.

**It does NOT make any changes in the ability to display Compose content
above interop view on Desktop**, this fix was made in #915

Main changes:
- Unify a way to work with interop on Desktop (`SwingPanel`) and iOS
(`UIKitView`)
- `LocalInteropContainer` -> `LocalUIKitInteropContainer` on iOS
- `LocalLayerContainer` -> `LocalSwingInteropContainer` on Desktop
- Reduce copy-pasting by moving `OverlayLayout` and `EmptyLayout`
- Remove overriding `add` method on `ComposePanel` and
`ComposeWindowPanel` - it was required to redirect interop, but now it's
not required and it's better to avoid changing default AWT hierarchy
behaviour
- Do not use `JLayeredPane`'s layers anymore - it brings a lot of
transparency issues (faced with it on Windows too after unrelated
change). Sorting via indexes is used instead
- Add `InteropOrder` page to mpp demo

### How it works

It utilizes `TraversableNode` to traverse the tree in the right order
and calculate the index based on interop views count that placed before
the current node in the hierarchy. All interop nodes are marked via
`Modifier.trackSwingInterop`/`Modifier.trackUIKitInterop` modifier to
filter them from the `LayoutNode`s tree.

## Testing

Test: run reproducers from the issues or look at "InteropOrder" page in
mpp demo

Desktop | iOS
--- | ---
<img width="400" alt="Screenshot 2024-02-27 at 12 51 06"
src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/534cbdc8-9671-4ab7-bd6d-b577d2004d1b">
| <img width="300" alt="Simulator Screenshot - iPhone 15 Pro -
2024-02-27 at 12 49 50"
src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/ac7553db-c2a4-4c4a-a270-5d6dbf82fb79">


## Issues Fixed

### Desktop

Fixes JetBrains/compose-multiplatform#2926
Fixes
JetBrains/compose-multiplatform#1521 (comment)

### iOS

Fixes JetBrains/compose-multiplatform#4004
Fixes JetBrains/compose-multiplatform#3848
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants