https://kotlinlang.org logo
#compose
Title
# compose
r

redrield

11/14/2020, 1:54 AM
How can I get the current orientation of the device in a composable?
i

Ian Lake

11/14/2020, 2:02 AM
This is generally not actually what you want, given that in cases such as split screen multi-window on a phone, you'll be in "landscape" (just because the window's width > its height). Have you looked at `onSizeChanged`: https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/package-summary#onsizechanged
☝️ 1
r

redrield

11/14/2020, 2:19 AM
I'm still thinking about how I'd like to lay this out in that case, but I expect that in order to fit everything without having to resort to a scrolling view (which I'd prefer) I would need to adjust parts of the view more than I would be able to with that (e.g. turning a
Row
of buttons into a
Column
)
a

Andrey Kulikov

11/14/2020, 8:28 AM
you can use
WithConstraints
where you check
if(maxWidth > maxHeight)
for the dynamic size of your component, or you can use
ConfigurationAmbient
for the sizes of your screen. either of these two should work better than
onSizeChanged
7 Views