question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Navigating to new screen and lockToLandscape() immediatelly doesn't rotate on iOS

See original GitHub issue

When using react-navigation 6, navigating to a screen and having this code doesn’t rotate screen.

useEffect(() => {
    Orientation.lockToLandscape()
}, [])

It only works with timeout over 500 (in my case).

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
Amol-B-Patilcommented, Apr 7, 2022

Not any of the solutions listed above worked for me on iOS 13, 14 and 15.

For now I solved the problem by adding setTimeout to lock the screen orientation.

setTimeout(() => {
      Orientation.lockToLandscape();
    }, Platform.select({
  android: 0,
  ios: 600,
}));

On Android, the app automatically locks into the landscape mode so I put the timeout as 0. On iOS, tweak the timeout between 600 to 1000 as per your need, it will automatically rotate the app in landscape mode (It will work for switching from landscape to portrait too).

This will work as expected.

Thank you!

3reactions
achang0406commented, Dec 14, 2021

adding shouldAutoRotate fixed my problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rotate the screen on your iPhone or iPod touch - Apple Support
Tap the Portrait Orientation Lock button to make sure that it's off. Turn your iPhone sideways. If the screen still doesn't rotate, try...
Read more >
iPhone Screen Not Rotating to Landscape Mode? Here's How ...
Here, tap on the Portrait Orientation Lock toggle (which looks like a lock with a circular arrow) to turn it on or off....
Read more >
iPhone or iPad Screen Won't Rotate? Here's How to Fix It
Step 1. Turn Off Rotation Lock in the Control Center · Step 2. Try Rotating the Screen in a Different App · Step...
Read more >
Android - Emulator in landscape mode, screen does not rotate
That was my problem too, I feel like a dummy. I'm new to Android (used iOS for years) and have realized that auto-rotate...
Read more >
Make Your iPhone's Portrait Orientation Lock Change ...
I always keep my iPhone's Portrait Orientation Lock on so that my screen doesn't randomly rotate while I'm lying down.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found