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.

ScreenOrientation is not functioning.

See original GitHub issue

Summary

It worked with sdk version 45.0.0, but there was a bug in the expo-av being built with eas. So, I was advised to upgrade to version 45.0.2, which fixed the expo-av problem, but the ScreenOrientation seems not to function at all.

The ScreenOrientation.addOrientationChangeListener doesn’t fire any events.

This won’t change the orientation , ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_LEFT);

This doesn’t unlock the orientation either. await ScreenOrientation.unlockAsync();

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

iOS

SDK Version (managed workflow only)

^45.0.2

Environment

expo-env-info 1.0.3 environment info:
    System:
      OS: macOS 12.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 18.0.0 - /opt/homebrew/bin/node
      Yarn: 1.22.18 - /opt/homebrew/bin/yarn
      npm: 8.6.0 - /opt/homebrew/bin/npm
    Managers:
      CocoaPods: 1.11.3 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
    IDEs:
      Android Studio: 2021.1 AI-211.7628.21.2111.8309675
      Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
    npmPackages:
      expo: ^45.0.2 => 45.0.4 
      react: 17.0.2 => 17.0.2 
      react-dom: 17.0.2 => 17.0.2 
      react-native: 0.68.2 => 0.68.2 
      react-native-web: 0.17.7 => 0.17.7 
    npmGlobalPackages:
      eas-cli: 0.52.0
      expo-cli: 5.4.3
    Expo Workflow: managed

Reproducible demo

const SomeScreen = ({ route, navigation }: { route: any, navigation: any }) => {

  React.useEffect(() => {
    let res = ScreenOrientation.addOrientationChangeListener(({ orientationInfo, orientationLock }) => {
      switch (orientationInfo.orientation) {
        case ScreenOrientation.Orientation.LANDSCAPE_LEFT:
        case ScreenOrientation.Orientation.LANDSCAPE_RIGHT:
          console.log('orientation changed to lanscape')
          break;
        default:
          console.log('orientation changed to portrait')
          break;
      }
    });
    (async () => {
      console.log('lock left orientation')
      // await ScreenOrientation.unlockAsync();
      await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_LEFT);
      console.log('locked left orientation')
    })();
    return () => {
      console.log('lock orientation')
     res.remove();
    }
  }, [])
return <View style={{
    flex: 1,
    justifyContent: 'flex-start',
    backgroundColor:'red'
}}></View>
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mephisto83commented, May 13, 2022

ScreenOrientation does work with expo-go, but not with a eas build. I’m wondering if it is also related to the expo-av issue that was fixed in expo@45.0.2

1reaction
ritu2510commented, Jun 3, 2022

Does anyone found a solution to this? We are facing a similar issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - screenOrientation portrait not always working
I'm making activity which should always remain in one orientation on all devices, preferably portrait. here is my activity
Read more >
Screen Orientation Not Working. - Unity Forum
Hi, I am new to Unity, I am making a small 2d game where all Scenes are in Portrait, The new Scene i...
Read more >
Screen Orientation - W3C
The Screen Orientation specification standardizes the types and angles for a device's screen orientation, and provides a mechanism to that ...
Read more >
Why is not working screenOrientation ? (Example) - Treehouse
I set screenOrientation to be portrait and it doesn't workin. It still can go landscape. <?xml version="1.0" encoding="utf-8"?> &l...
Read more >
ScreenOrientation - Expo Documentation
Invokes the listener function when the screen orientation changes from portrait to landscape or from landscape to portrait . For example, it won't...
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