Hi! I would like to keep my app in the portrait mo...
# compose-android
r
Hi! I would like to keep my app in the portrait mode mode for compact size devices and enable landscape mode for medium and expanded size screens. What’s the best way to handle that for the whole activity?
I’m not sure if this is the right channel for the question and sorry if not. I’m just working on adaptive layouts that are closely related to this.
c
i feel like @Alex Vanyo has thoughts on this... but IIRC android is essentially preventing anything like this in android 16+? i do understand that most PMs just say "only make the app portrait" but that really falls apart in the world of foldables.
👍🏽 1
a
Heh I do 😄. I'll give two answers: ideally, you move towards handling all orientations in all situations. The situations where this matters are growing more and more numerous: • full-screen apps in landscape and portrait on a variety of device types (phones, foldables, tablets, ChromeOS, cars, XR) • multi-window modes (split-screen, free-form windows, desktop windowing, connected displays, XR) with arbitrary window sizes • accessibility requirements In targetSdk 36, we're removing the ability to restrict orientation, resizability and aspect ratio on displays that are at least sw600dp as @Colton Idle mentioned: https://developer.android.com/about/versions/16/behavior-changes-16#large-screens-form-factors but as part of those changes in Android 16, behavior on smaller displays (<sw600dp) won't be changed, so it sounds like that's compatible with your question and the Android 16 changes wouldn't impact your app that uses that logic. The second answer is that we have a guide for doing exactly that: https://developer.android.com/develop/ui/compose/quick-guides/content/restrict-app-orientation-on-phones. While this isn't ideal, it's a common pattern right now, and it's also not straightforward to implement due to letterboxing and some other quirks, so it is preferable to do this than try to lock to portrait always.
r
Thank You! 🙇