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

ursus

03/03/2024, 1:14 AM
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

Chrimaeon

03/03/2024, 8:58 AM
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

ursus

03/03/2024, 11:09 AM
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

Chrimaeon

03/03/2024, 11:12 AM
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

ursus

03/03/2024, 11:13 AM
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

Chrimaeon

03/03/2024, 11:15 AM
Then set it to portrait in the manifest. And change only for lager devices
u

ursus

03/03/2024, 11:16 AM
Sounds reasonable, but what tat be percievable on Fold somehow? i.e. portrait splash screen for a split second them boom landscape?
c

Chrimaeon

03/03/2024, 11:16 AM
🤷🏼‍♂️ like said, this is a kotlin workspace, your question really do not relate here.
u

ursus

03/03/2024, 11:17 AM
where does it relate to then, dont say stackoverflow 😀
c

Chrimaeon

03/03/2024, 11:18 AM
There are plenty of android resources. Check the #android channel description.
u

ursus

03/03/2024, 11:18 AM
not sure how a thread bothers anyone but sure
s

Stylianos Gakis

03/03/2024, 11:19 AM
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

ursus

03/03/2024, 11:20 AM
Yes the recipe is helpful thank you. But it goes agains what the stakcoverflow says, hence me asking followups
s

Stylianos Gakis

03/03/2024, 11:21 AM
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

ursus

03/03/2024, 11:30 AM
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

Chrimaeon

03/03/2024, 11:32 AM
That’s why you have window classes now and depending on it have different layouts. 😅
u

ursus

03/03/2024, 11:33 AM
Obviously not programatically guys. I mean visually, design wise.
Ask designers 🙈
u

ursus

03/03/2024, 11:34 AM
Okay
s

Stylianos Gakis

03/03/2024, 11:35 AM
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

Chrimaeon

03/03/2024, 11:37 AM
And @ursus there’s is also split screen on android where you would have the same issue on a phone in portrait.
u

ursus

03/03/2024, 11:41 AM
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?
3 Views