How would I lock phone layout in portrait, yet all...
# compose
u
How would I lock phone layout in portrait, yet allow landscape (i.e. don't force portrait) on foldables/large devices? My app can handle orientation changes, but certain layouts are not worth redoing for phone landscape (simply too narrow) Something like this maybe?
android:screenOrientation="@enums/screenOrientation"
and then provide different enum value for default &
sw-600dp
but how do I do it for enums?
not kotlin but kotlin colored 2
c
I would set it from code, depending on the new window size classes. But your question is more Android related than compose or Kotlin. So maybe check other resources for an appropriate answer.
u
hmm okay so setting
requestedOrientation
at runtime is idiomatic? That's what I googled as a first thing, but stackoerflow comments said it potentially restarts the just started activity Not true anymore?
c
Of course it can, if the orientation changed. It’s an configuration change and results in the onCreate to be re-created
But that’s what you actually want 😅
u
how so? in a phone?
what I'm trying to say phones are 99% usecase so I don't want to degrade the experience
c
Then set it to portrait in the manifest. And change only for lager devices
u
Sounds reasonable, but what tat be percievable on Fold somehow? i.e. portrait splash screen for a split second them boom landscape?
c
🤷🏼‍♂️ like said, this is a kotlin workspace, your question really do not relate here.
u
where does it relate to then, dont say stackoverflow 😀
c
There are plenty of android resources. Check the #android channel description.
u
not sure how a thread bothers anyone but sure
s
Also the recipe is literally holding your hand to do exactly what you're supposed to do if you want locked portrait only for phone. I don't think you will find anything more specific than that anywhere else. With that said Christian is right, if we asked any question ever in the compose channel what is the purpose of the compose channel?
u
Yes the recipe is helpful thank you. But it goes agains what the stakcoverflow says, hence me asking followups
s
That comes directly from google documentation, I would if anything trust that one a bit more. You can find a lot of atrocities over at stackoverflow, especially the further back you go in time. Things that are clear hacks and nowadays we got better solutions for. With that said, see both approaches and pick the one which you feel is more fitting
u
One more quick one How would you translate such screen to landscape (phone)? The whole issue of blocking phones to portrait stemming from this I.e. a screen with a action button pinned at the bottom If I were to just rotate and pin, then on phone you have like 3cm between the toolbar and the action button
😅 1
c
That’s why you have window classes now and depending on it have different layouts. 😅
u
Obviously not programatically guys. I mean visually, design wise.
Ask designers 🙈
u
Okay
s
And make your screens scrollable regardless, even if you don't have landscape mode, you might have a normal phone with a small screen where the button wouldn't fit anyway. But always good to ask whoever has made your design to see what they want to happen if you don't have your own opinion on it.
c
And @ursus there’s is also split screen on android where you would have the same issue on a phone in portrait.
u
well yea its scrollable so its correct, nothing clips in split mode on phone you have a tiny area anyways so you tolerate it not being great My question was mostly as how to best utilize the screen when in landscape. No pattern comes to mind. Maybe split the screen into 2 columns, and have the action button on the right half?