1

I'm using ReactJS: Is it possible to programmatically change orientation with user input? In my case, when a user presses fullscreen on my custom video player, I want it to automatically change to Landscape if they are in portrait.

I'm detecting orientation with window.orientation, but I can't find any way to set it. I can provide a fiddle if it will help anyone but I think the solution would be pretty straight forward: is there a way to change programmatically set orientation in ReactJS?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Big Guy
  • 712
  • 1
  • 8
  • 21
  • React isn't a different language. It's JS. If you can't find suitable JS solution, it doesn't exist. You actually can't set the orientation of entire screen. You can detect orientation changes and change the layout accordingly. – Estus Flask Oct 26 '18 at 21:07
  • Yeah I'm aware of that, couldn't find a suitable JS solution, but if possible I said React since it's nice to avoid messy javascript solutions when possible. Anyway, I am listening for orientation changes, but it would require way too much work to make every component "think" it is in landscape. Ie, if I give it `width:100vw`, that means different things if it is in portrait vs landscape. Changing the layout manually would be pretty hacky – Big Guy Oct 26 '18 at 21:13
  • I guess https://stackoverflow.com/a/18914945/3731501 is the best thing you can come up with. – Estus Flask Oct 26 '18 at 21:17
  • yeah I found that before I posted, but that's over 5 years old so I was hoping something had changed – Big Guy Oct 26 '18 at 21:18
  • To clarify: we might think of a phone as 300px width by 500px height, but view units (vw and vh) respond to the orientation (300 x 500 or 500 x 300). Planning for both of those—and other resolutions—calls for responsive design. – stealththeninja Oct 26 '18 at 21:26
  • I have responsive design for both cases that works well, but we're straying a little away from the question. I'm keeping track of the state of orientation and I don't really want to "trick it" and throw off other aspects. If there's no legit way to change the orientation, I will just live without it – Big Guy Oct 26 '18 at 21:31

1 Answers1

0

I hope i am not to late in answering this question I face a similar but managed to solve using this solution provided here it work's well but a bit laggy some times works for both IOS and android

Charles
  • 1,844
  • 1
  • 14
  • 21