What would be the best way to fade in/out a window...
# compose-desktop
r
What would be the best way to fade in/out a window covering scrim (dark overlay) on desktop? Here's what I've tried: 1.
Dialog
- scrim can't be animated or customized 2.
Popup
with a
Box(Modifier.fillMaxSize().background(...))
inside - easy to fade in when added to the composition, e.g. using AnimatedVisibility, but hard to fade out when removed. AnimatedVisibility does not keep the Popup around, so it disappears instantly. 3. A custom-built
rememberScrimController()
that adds another JPanel at the window level. Works fine but I don't like touching Swing unless absolutely necessary.
t
Have a look into
AnimatedContent
. This allows content to be animated in and out, so option 2 would work.
r
Unfortunately, neither
AnimatedVisibility
nor
AnimatedContent
work with Popups -- at least in my experience. The Popup gets immediately removed from the composition. You can use AnimatedVisibility for the content inside the popup, but then you have to leave the popup around. I ended up doing a variant of (3) but in compose. I used a
Scrim {}
composable at the root which exposes a
LocalScrimState
for descendants to use to change the scrim. Not ideal, but it works.