Skip to content

Commit

Permalink
Compose 1.7 FillMaxSize+Jpanels Workaround (#509)
Browse files Browse the repository at this point in the history
* Compose 1.7 FillMaxSize+Jpanels Workaround

* Fix klint formatting

* Fix detektmain issue

---------

Co-authored-by: Francisco Noriega <francisco.noriega@airbnb.com>
  • Loading branch information
francisconoriega and Francisco Noriega authored Aug 2, 2024
1 parent 5ccfde5 commit afe24b9
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package org.jetbrains.jewel.bridge

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.ComposePanel
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.toSize
import org.jetbrains.jewel.bridge.actionSystem.ComponentDataProviderBridge
import org.jetbrains.jewel.bridge.theme.SwingBridgeTheme
import org.jetbrains.jewel.foundation.ExperimentalJewelApi
Expand All @@ -14,9 +20,11 @@ import javax.swing.JComponent
public fun JewelComposePanel(content: @Composable () -> Unit): JComponent =
ComposePanel().apply {
setContent {
SwingBridgeTheme {
CompositionLocalProvider(LocalComponent provides this@apply) {
ComponentDataProviderBridge(this@apply, content = content)
Compose17IJSizeBugWorkaround {
SwingBridgeTheme {
CompositionLocalProvider(LocalComponent provides this@apply) {
ComponentDataProviderBridge(this@apply, content = content)
}
}
}
}
Expand All @@ -27,3 +35,17 @@ public val LocalComponent: ProvidableCompositionLocal<JComponent> =
staticCompositionLocalOf {
error("CompositionLocal LocalComponent not provided")
}

/**
* Workaround until the issue with Compose 1.7 + fillMax__ + IntelliJ Panels is fixed:
* https://github.com/JetBrains/jewel/issues/504
* https://youtrack.jetbrains.com/issue/CMP-5856
*/
@Composable
private fun Compose17IJSizeBugWorkaround(content: @Composable () -> Unit) {
with(LocalDensity.current) {
Box(modifier = Modifier.requiredSize(LocalWindowInfo.current.containerSize.toSize().toDpSize())) {
content()
}
}
}

0 comments on commit afe24b9

Please sign in to comment.