Is it possible to overlap two elements in a Surfac...
# compose
n
Is it possible to overlap two elements in a Surface, and for them to both be centred? With my current code, one element pushes the other one to the top left. I was expecting both to be stacked in the centre... I know I can do that with a Box, but I have to use a Surface. More in thread.
I am using the Konfetti library and apparently it only works if the Composable is in a Surface. The problem is that the confetti Composable pushes the Text to the top left of the row. Here is my code:
Copy code
Row(
            Modifier.fillMaxSize(),
            horizontalArrangement = Arrangement.Center,
            verticalAlignment = Alignment.CenterVertically
        ) {
             Surface(Modifier.fillMaxSize(), color = Color.Transparent) {
                        ShowCelebration()
                        Text(text = resultString!!)
                    }
                }
            }
m
Box or constraint layout can be used
n
Do you mean use a Box inside the Surface?
m
Yes
Box lays out one on top of other in Z order
n
No, it doesn't work because the ShowCelebration Composable only works if it is in a Surface...
Thanks anyway!
m
Ok for your use case you can still use box on top of ShowCelebration and set box background transparent and place text inside it, make sure box is maxsize
n
Thanks, that worked! 😊
c
apparently it only works if the Composable is in a Surface
Could you elaborate on what isn’t working? Surface under the hood is just a Box with MaterialTheme colors passed as CompositionLocals and parameters to set elevation
today i learned 1
n
I only managed to get the animation to show when using a Surface. When I use a Box it doesn't show. Maybe I'm just doing something wrong...
Maybe I needed to use a Transparent Box in the first place
c
Hmm were the Composables still there in the hierarchy and the colors were just not showing?
n
That's correct.