https://kotlinlang.org logo
Title
n

nitrog42

08/23/2021, 3:54 PM
I have a coworker that is asking me an interesting question : Is there anyway to lock orientation of "screen" in a Compose app ? I assume we have to use
setRequestedOrientation
in the main activity ? context : setRequestedOrientation might recreate activity, and I read that with Compose we can just override all configChanges as it can be handled directly
t

tad

08/23/2021, 5:01 PM
Compose has nothing to do with this, essentially. Overriding configChanges for orientation means the activity is not recreated
n

nitrog42

08/23/2021, 5:24 PM
yes but the Compose UI will still adapt from portait to landscape right ?
t

tad

08/23/2021, 5:24 PM
Yes, because
ComposeView
will trigger a recomposition on the configuration change
n

nitrog42

08/23/2021, 5:25 PM
but what about displaying in portrait mode, even when the phone is in landscape
t

tad

08/23/2021, 5:26 PM
That wouldn't happen
Oh, you mean locking the orientation to portrait?
n

nitrog42

08/23/2021, 5:27 PM
yes
t

tad

08/23/2021, 5:27 PM
The activity would remain in portrait in that case, and no recomposition would happen
n

nitrog42

08/23/2021, 5:27 PM
if I force the orientation in the activity, right ?
t

tad

08/23/2021, 5:28 PM
Right
n

nitrog42

08/23/2021, 5:28 PM
my example is something like this :

https://miro.medium.com/max/1400/1*p-2ZKX8WwwDrbnZXL5clOg.png

assuming I don't want to lock the activity to portrait, I just want to handle the orientation change in composation to keep the UI as is, but with icon rotated to still be at the good angle for the user