Is there a CMP way to implement `isLandscape()`? `...
# compose
m
Is there a CMP way to implement
isLandscape()
?
androidx.compose.material3:material3-window-size-class
or is that overkill?
a
depends what you are trying to do. if it's for responsive design purposes, window size class is the way to go. doesnt make sense to check if the device is on landscape for that because on tablets u have plenty of space even on portrait
alternatively you can use
LocalWindowInfo.current.containerSize
to get the width/height of the container u are on (works on all platforms, but android i think)
m
The user can bring up a pane which ideally is square, and the existing content fills the rest of the space. In squarish displays, I just make do with a non-square pane allowing just enough minimum space for the main content. So the best strategy to get as close to this as possible is to have a different layout for landscape (side by side) compared to portrait (one above the other). So in this case it’s not really about available space but rather aspect ratio.
s
I don't think window size classes are really related to your use case. It seems like you want to check if your width is a certain factor bigger than your height. You can use
LocalWindowInfo
if you want the window size, or
BoxWithConstraints
if you want the usable size. If you really just want to implement
isLandscape()
, I think you'll need to do an expect/actual. the desktop version would be something like:
with(LocalWindowInfo.current.containerSize) { width > height }
m
It’s still an Android app right now, I’m just gradually migrating away from using Android-only APIs. So I guess this is just a step I can do when actually migrating to KMP.