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
16.26k stars 1.18k forks source link

Using LazyColumn in AlertDialog causes IllegalStateException. #1111

Closed varpihovsky closed 1 year ago

varpihovsky commented 3 years ago

Compose 1.0.0-alpha3, Linux. Executing following code:

@OptIn(ExperimentalMaterialApi::class)
fun main() = singleWindowApplication {
    AlertDialog(
        onDismissRequest = {},
        confirmButton = {},
        text = {
            LazyColumn {

            }
        }
    )
}

Causes following exception:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Asking for intrinsic measurements of SubcomposeLayout layouts is not supported. This includes components that are built on top of SubcomposeLayout, such as lazy lists, BoxWithConstraints, TabRow, etc. To mitigate this:
- if intrinsic measurements are used to achieve 'match parent' sizing,, consider replacing the parent of the component with a custom layout which controls the order in which children are measured, making intrinsic measurement not needed
- adding a size modifier to the component, in order to fast return the queried intrinsic measurement.
    at androidx.compose.ui.node.LayoutNode$NoIntrinsicsMeasurePolicy.minIntrinsicWidth(LayoutNode.kt:452)
    at androidx.compose.ui.node.LayoutNode$NoIntrinsicsMeasurePolicy.minIntrinsicWidth(LayoutNode.kt:448)
    at androidx.compose.ui.node.IntrinsicsPolicy.minIntrinsicWidth(IntrinsicsPolicy.kt:42)
    at androidx.compose.ui.node.InnerPlaceable.minIntrinsicWidth(InnerPlaceable.kt:97)
    at androidx.compose.ui.layout.MeasuringIntrinsics$DefaultIntrinsicMeasurable.measure-BRTryo0(LayoutModifier.kt:204)
    at androidx.compose.foundation.layout.PaddingValuesModifier.measure-3p2s80s(Padding.kt:417)
    at androidx.compose.ui.layout.MeasuringIntrinsics.minWidth$ui(LayoutModifier.kt:129)
    at androidx.compose.ui.layout.LayoutModifier$DefaultImpls.minIntrinsicWidth(LayoutModifier.kt:66)
    at androidx.compose.foundation.layout.PaddingValuesModifier.minIntrinsicWidth(Padding.kt:396)
    at androidx.compose.ui.node.ModifiedLayoutNode.minIntrinsicWidth(ModifiedLayoutNode.kt:46)
    at androidx.compose.ui.layout.MeasuringIntrinsics$DefaultIntrinsicMeasurable.measure-BRTryo0(LayoutModifier.kt:204)
    at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:219)
    at androidx.compose.ui.layout.MeasuringIntrinsics.minWidth$ui(LayoutModifier.kt:129)
    at androidx.compose.ui.layout.LayoutModifier$DefaultImpls.minIntrinsicWidth(LayoutModifier.kt:66)
    at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.minIntrinsicWidth(GraphicsLayerModifier.kt:182)
    at androidx.compose.ui.node.ModifiedLayoutNode.minIntrinsicWidth(ModifiedLayoutNode.kt:46)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.ui.node.OuterMeasurablePlaceable.minIntrinsicWidth(OuterMeasurablePlaceable.kt:166)
    at androidx.compose.ui.node.LayoutNode.minIntrinsicWidth(LayoutNode.kt:1256)
    at androidx.compose.ui.layout.DefaultIntrinsicMeasurable.measure-BRTryo0(Layout.kt:259)
    at androidx.compose.foundation.layout.BoxKt$boxMeasurePolicy$1.measure-3p2s80s(Box.kt:115)
    at androidx.compose.ui.layout.MeasurePolicy$DefaultImpls.minIntrinsicWidth(MeasurePolicy.kt:103)
    at androidx.compose.foundation.layout.BoxKt$boxMeasurePolicy$1.minIntrinsicWidth(Box.kt:95)
    at androidx.compose.ui.node.IntrinsicsPolicy.minIntrinsicWidth(IntrinsicsPolicy.kt:42)
    at androidx.compose.ui.node.InnerPlaceable.minIntrinsicWidth(InnerPlaceable.kt:97)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.ui.layout.MeasuringIntrinsics$DefaultIntrinsicMeasurable.measure-BRTryo0(LayoutModifier.kt:204)
    at androidx.compose.foundation.layout.PaddingModifier.measure-3p2s80s(Padding.kt:364)
    at androidx.compose.ui.layout.MeasuringIntrinsics.minWidth$ui(LayoutModifier.kt:129)
    at androidx.compose.ui.layout.LayoutModifier$DefaultImpls.minIntrinsicWidth(LayoutModifier.kt:66)
    at androidx.compose.foundation.layout.PaddingModifier.minIntrinsicWidth(Padding.kt:337)
    at androidx.compose.ui.node.ModifiedLayoutNode.minIntrinsicWidth(ModifiedLayoutNode.kt:46)
    at androidx.compose.ui.node.OuterMeasurablePlaceable.minIntrinsicWidth(OuterMeasurablePlaceable.kt:166)
    at androidx.compose.ui.node.LayoutNode.minIntrinsicWidth(LayoutNode.kt:1256)
    at androidx.compose.ui.layout.DefaultIntrinsicMeasurable.measure-BRTryo0(Layout.kt:259)
    at androidx.compose.material.AlertDialogKt$AlertDialogBaselineLayout$2.measure-3p2s80s(AlertDialog.kt:117)
    at androidx.compose.ui.layout.MeasurePolicy$DefaultImpls.minIntrinsicWidth(MeasurePolicy.kt:103)
    at androidx.compose.material.AlertDialogKt$AlertDialogBaselineLayout$2.minIntrinsicWidth(AlertDialog.kt:111)
    at androidx.compose.ui.node.IntrinsicsPolicy.minIntrinsicWidth(IntrinsicsPolicy.kt:42)
    at androidx.compose.ui.node.InnerPlaceable.minIntrinsicWidth(InnerPlaceable.kt:97)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.ui.node.OuterMeasurablePlaceable.minIntrinsicWidth(OuterMeasurablePlaceable.kt:166)
    at androidx.compose.ui.node.LayoutNode.minIntrinsicWidth(LayoutNode.kt:1256)
    at androidx.compose.foundation.layout.IntrinsicMeasureBlocks$VerticalMinWidth$1$1.invoke(RowColumnImpl.kt:591)
    at androidx.compose.foundation.layout.IntrinsicMeasureBlocks$VerticalMinWidth$1$1.invoke(RowColumnImpl.kt:591)
    at androidx.compose.foundation.layout.RowColumnImplKt.intrinsicCrossAxisSize(RowColumnImpl.kt:751)
    at androidx.compose.foundation.layout.RowColumnImplKt.intrinsicSize(RowColumnImpl.kt:684)
    at androidx.compose.foundation.layout.RowColumnImplKt.access$intrinsicSize(RowColumnImpl.kt:1)
    at androidx.compose.foundation.layout.IntrinsicMeasureBlocks$VerticalMinWidth$1.invoke(RowColumnImpl.kt:589)
    at androidx.compose.foundation.layout.IntrinsicMeasureBlocks$VerticalMinWidth$1.invoke(RowColumnImpl.kt:588)
    at androidx.compose.foundation.layout.RowColumnImplKt$rowColumnMeasurePolicy$1.minIntrinsicWidth(RowColumnImpl.kt:268)
    at androidx.compose.ui.node.IntrinsicsPolicy.minIntrinsicWidth(IntrinsicsPolicy.kt:42)
    at androidx.compose.ui.node.InnerPlaceable.minIntrinsicWidth(InnerPlaceable.kt:97)
    at androidx.compose.ui.node.OuterMeasurablePlaceable.minIntrinsicWidth(OuterMeasurablePlaceable.kt:166)
    at androidx.compose.ui.node.LayoutNode.minIntrinsicWidth(LayoutNode.kt:1256)
    at androidx.compose.ui.layout.DefaultIntrinsicMeasurable.measure-BRTryo0(Layout.kt:259)
    at androidx.compose.foundation.layout.BoxKt$boxMeasurePolicy$1.measure-3p2s80s(Box.kt:115)
    at androidx.compose.ui.layout.MeasurePolicy$DefaultImpls.minIntrinsicWidth(MeasurePolicy.kt:103)
    at androidx.compose.foundation.layout.BoxKt$boxMeasurePolicy$1.minIntrinsicWidth(Box.kt:95)
    at androidx.compose.ui.node.IntrinsicsPolicy.minIntrinsicWidth(IntrinsicsPolicy.kt:42)
    at androidx.compose.ui.node.InnerPlaceable.minIntrinsicWidth(InnerPlaceable.kt:97)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.ui.layout.MeasuringIntrinsics$DefaultIntrinsicMeasurable.measure-BRTryo0(LayoutModifier.kt:204)
    at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:219)
    at androidx.compose.ui.layout.MeasuringIntrinsics.minWidth$ui(LayoutModifier.kt:129)
    at androidx.compose.ui.layout.LayoutModifier$DefaultImpls.minIntrinsicWidth(LayoutModifier.kt:66)
    at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.minIntrinsicWidth(GraphicsLayerModifier.kt:182)
    at androidx.compose.ui.node.ModifiedLayoutNode.minIntrinsicWidth(ModifiedLayoutNode.kt:46)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.minIntrinsicWidth(DelegatingLayoutNodeWrapper.kt:159)
    at androidx.compose.foundation.layout.MinIntrinsicWidthModifier.calculateContentConstraints-l58MMJ0(Intrinsic.kt:117)
    at androidx.compose.foundation.layout.IntrinsicSizeModifier$DefaultImpls.measure-3p2s80s(Intrinsic.kt:252)
    at androidx.compose.foundation.layout.MinIntrinsicWidthModifier.measure-3p2s80s(Intrinsic.kt:112)
    at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:39)
    at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$3.invoke(OuterMeasurablePlaceable.kt:100)
    at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$3.invoke(OuterMeasurablePlaceable.kt:99)
    at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:128)
    at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui(OwnerSnapshotObserver.kt:75)
    at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui(OwnerSnapshotObserver.kt:63)
    at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:99)
    at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:71)
    at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1238)
    at androidx.compose.foundation.layout.BoxKt$boxMeasurePolicy$1.measure-3p2s80s(Box.kt:115)
    at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:50)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:116)
    at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$3.invoke(OuterMeasurablePlaceable.kt:100)
    at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$3.invoke(OuterMeasurablePlaceable.kt:99)
    at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:128)
    at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui(OwnerSnapshotObserver.kt:75)
    at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui(OwnerSnapshotObserver.kt:63)
    at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:99)
    at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:71)
    at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1238)
    at androidx.compose.ui.layout.RootMeasurePolicy.measure-3p2s80s(RootMeasurePolicy.kt:38)
    at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:50)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:116)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:116)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:116)
    at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:116)
    at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$3.invoke(OuterMeasurablePlaceable.kt:100)
    at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$3.invoke(OuterMeasurablePlaceable.kt:99)
    at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:1776)
    at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:123)
    at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui(OwnerSnapshotObserver.kt:75)
    at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui(OwnerSnapshotObserver.kt:63)
    at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:99)
    at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui(LayoutNode.kt:1247)
    at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:169)
    at androidx.compose.ui.node.MeasureAndLayoutDelegate.access$doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:38)
    at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:207)
    at androidx.compose.ui.platform.DesktopOwner.measureAndLayout(DesktopOwner.desktop.kt:253)
    at androidx.compose.ui.awt.ComposeLayer$Wrapped.doLayout(ComposeLayer.desktop.kt:124)
    at java.desktop/java.awt.Container.validateTree(Container.java:1722)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validate(Container.java:1657)
    at java.desktop/java.awt.Container.validateUnconditionally(Container.java:1694)
    at java.desktop/java.awt.Window.pack(Window.java:836)
    at androidx.compose.ui.util.Windows_desktopKt.setSizeSafely-1UfYcH4(Windows.desktop.kt:82)
    at androidx.compose.ui.window.Dialog_desktopKt$Dialog$5$1$7.invoke-Bx6NYns(Dialog.desktop.kt:153)
    at androidx.compose.ui.window.Dialog_desktopKt$Dialog$5$1$7.invoke(Dialog.desktop.kt:153)
    at androidx.compose.ui.util.ComponentUpdater$UpdateScope.set(ComponentUpdater.kt:45)
    at androidx.compose.ui.window.Dialog_desktopKt$Dialog$5$1.invoke(Dialog.desktop.kt:153)
    at androidx.compose.ui.window.Dialog_desktopKt$Dialog$5$1.invoke(Dialog.desktop.kt:146)
    at androidx.compose.ui.util.ComponentUpdater.update(ComponentUpdater.kt:27)
    at androidx.compose.ui.window.Dialog_desktopKt$Dialog$5.invoke(Dialog.desktop.kt:146)
    at androidx.compose.ui.window.Dialog_desktopKt$Dialog$5.invoke(Dialog.desktop.kt:145)
    at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$3.invoke(AwtWindow.desktop.kt:88)
    at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$3.invoke(AwtWindow.desktop.kt:87)
    at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2$performUpdate$2.invoke(UpdateEffect.desktop.kt:58)
    at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2$performUpdate$2.invoke(UpdateEffect.desktop.kt:57)
    at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:1776)
    at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:123)
    at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2.invoke$performUpdate(UpdateEffect.desktop.kt:54)
    at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2.invoke(UpdateEffect.desktop.kt:62)
    at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2.invoke(UpdateEffect.desktop.kt:47)
    at androidx.compose.runtime.DisposableEffectImpl.onRemembered(Effects.kt:81)
    at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:780)
    at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:638)
    at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:733)
    at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime(Composer.kt:2986)
    at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:432)
    at androidx.compose.ui.platform.Wrapper_desktopKt.setContent(Wrapper.desktop.kt:41)
    at androidx.compose.ui.awt.ComposeLayer$setContent$4.invoke(ComposeLayer.desktop.kt:292)
    at androidx.compose.ui.awt.ComposeLayer$setContent$4.invoke(ComposeLayer.desktop.kt:283)
    at androidx.compose.ui.awt.ComposeLayer$Wrapped.init(ComposeLayer.desktop.kt:91)
    at org.jetbrains.skiko.SkiaLayer.checkInit(SkiaLayer.kt:72)
    at org.jetbrains.skiko.SkiaLayer._init_$lambda-0(SkiaLayer.kt:60)
    at java.desktop/java.awt.Component.processHierarchyEvent(Component.java:6819)
    at java.desktop/java.awt.Component.processEvent(Component.java:6438)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5027)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4859)
    at java.desktop/java.awt.Component.addNotify(Component.java:7123)
    at java.desktop/java.awt.Canvas.addNotify(Canvas.java:104)
    at java.desktop/java.awt.Container.addNotify(Container.java:2800)
    at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
    at java.desktop/java.awt.Container.addNotify(Container.java:2800)
    at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
    at androidx.compose.ui.awt.ComposeWindowDelegate$pane$1.addNotify(ComposeWindowDelegate.desktop.kt:58)
    at java.desktop/java.awt.Container.addNotify(Container.java:2800)
    at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
    at java.desktop/java.awt.Container.addNotify(Container.java:2800)
    at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
    at java.desktop/java.awt.Container.addNotify(Container.java:2800)
    at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
    at java.desktop/javax.swing.JRootPane.addNotify(JRootPane.java:733)
    at java.desktop/java.awt.Container.addNotify(Container.java:2800)
    at java.desktop/java.awt.Window.addNotify(Window.java:787)
    at java.desktop/java.awt.Frame.addNotify(Frame.java:490)
    at java.desktop/java.awt.Window.show(Window.java:1049)
    at java.desktop/java.awt.Component.show(Component.java:1732)
    at java.desktop/java.awt.Component.setVisible(Component.java:1679)
    at java.desktop/java.awt.Window.setVisible(Window.java:1032)
    at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$4$1.invokeSuspend(AwtWindow.desktop.kt:122)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at org.jetbrains.skiko.context.OpenGLContextHandler.initCanvas(OpenGLContextHandler.kt:66)
    at org.jetbrains.skiko.SkiaLayer.prepareDrawContext$skiko(SkiaLayer.kt:336)
    at org.jetbrains.skiko.redrawer.LinuxOpenGLRedrawer.draw(LinuxOpenGLRedrawer.kt:56)
    at org.jetbrains.skiko.redrawer.LinuxOpenGLRedrawer.access$draw(LinuxOpenGLRedrawer.kt:14)
    at org.jetbrains.skiko.redrawer.LinuxOpenGLRedrawer$Companion$frameDispatcher$1.invokeSuspend(LinuxOpenGLRedrawer.kt:87)
    at org.jetbrains.skiko.redrawer.LinuxOpenGLRedrawer$Companion$frameDispatcher$1.invoke(LinuxOpenGLRedrawer.kt)
    at org.jetbrains.skiko.redrawer.LinuxOpenGLRedrawer$Companion$frameDispatcher$1.invoke(LinuxOpenGLRedrawer.kt)
    at org.jetbrains.skiko.FrameDispatcher$job$1.invokeSuspend(FrameDispatcher.kt:36)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Thomas-Vos commented 2 years ago

It would be great if this could be fixed. Currently running into this issue and have not found a solution so far.

Thomas-Vos commented 2 years ago

I tried to use a Column with verticalScroll modifier, but unfortunately that does not work either due to https://github.com/JetBrains/compose-jb/issues/976.

varpihovsky commented 2 years ago

I tried to use a Column with verticalScroll modifier, but unfortunately that does not work either due to #976.

Just use offset modifier to compensate indentation. It doesn't look good but at least it's possible to use

m-sasha commented 1 year ago

Putting scrollable content inside an AlertDialog is actually not a supported use-case. This is the case in Android too: https://issuetracker.google.com/issues/217151230#comment7

We do have plans to add a non-opinionated, "clean" dialog widget where you could put any content, and you can follow that effort here: https://github.com/JetBrains/compose-jb/issues/933

In the meanwhile, you could use this basic implementation that uses Popup:

import androidx.compose.foundation.LocalScrollbarStyle
import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.type
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.*
import androidx.compose.ui.window.*
import kotlinx.coroutines.*

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun PopupDialog(
    onDismissRequest: () -> Unit,
    content: @Composable () -> Unit
) {
    Popup(
        popupPositionProvider = object : PopupPositionProvider {
            override fun calculatePosition(
                anchorBounds: IntRect,
                windowSize: IntSize,
                layoutDirection: LayoutDirection,
                popupContentSize: IntSize
            ): IntOffset = IntOffset.Zero
        },
        focusable = true,
        onDismissRequest = onDismissRequest,
        onKeyEvent = {
            if ((it.type == KeyEventType.KeyDown) && (it.key == Key.Escape)) {
                onDismissRequest()
                true
            } else {
                false
            }
        },
    ) {
        val scrimColor = Color.Black.copy(alpha = 0.32f)
        Box(
            modifier = Modifier
                .fillMaxSize()
                .background(scrimColor)
                .pointerInput(onDismissRequest) {
                    detectTapGestures(onPress = { onDismissRequest() })
                },
            contentAlignment = Alignment.Center
        ) {
            Surface(Modifier.pointerInput(onDismissRequest) {
                detectTapGestures(onPress = {
                    // Workaround to disable clicks on Surface background https://github.com/JetBrains/compose-jb/issues/2581
                })
            }, elevation = 24.dp) {
                content()
            }
        }
    }
}

fun main() = singleWindowApplication(
    state = WindowState(width = 640.dp, height = 480.dp)
) {
    var dialogVisible by remember { mutableStateOf(true) }
    if (dialogVisible){
        PopupDialog(
            onDismissRequest = { dialogVisible = false },
        ) {
            Box(
                modifier = Modifier.size(300.dp, 200.dp)
            ) {
                val state = rememberLazyListState()
                LazyColumn(
                    modifier = Modifier.padding(end = LocalScrollbarStyle.current.thickness),
                    state = state,
                ) {
                    items(500) { index ->
                        Text(
                            text = "Row $index",
                            modifier = Modifier.padding(16.dp).fillMaxWidth(),
                        )
                    }
                }
                VerticalScrollbar(
                    modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
                    adapter = rememberScrollbarAdapter(scrollState = state),
                )
            }
        }
    }
}
okushnikov commented 2 months ago

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