Expo SDK 36: Error with ScreenOrientation

The app I’m creating is primarily in portrait mode, however, there is one screen that needs to be locked in landscape mode due to its functionality. I have installed the appropriate modules expo install expo-screen-orientation, but still seem to get an error that I’m unable to resolve. I get the following error

Error: The method or property ScreenOrientation.lockAsync is not available on ios, are you sure you’ve linked all the native dependencies properly?

Below is a snippet of my code.

import React, { useEffect } from 'react'
import { View, Text } from 'react-native'
import * as ScreenOrientation from 'expo-screen-orientation'

const GameModeScreen = () => {
  useEffect(() => {
    const changeScreenOrientation = async () => {
      await ScreenOrientation.lockAsync(
        ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT
      )
    }
    changeScreenOrientation()
  })

  return (
    <View>
      <Text>Hello from the GameModeScreen</Text>
    </View>
  )
}

export default GameModeScreen

Any suggestions on how to solve this issue???

1 Like

It’s hard for me to tell from what you’ve shared, but maybe check that you’ve set to require full screen? Details here: https://docs.expo.io/versions/latest/sdk/screen-orientation/#installation

I’ve set require to full screen but I still get the same error. I get a similar error when I run the app on android.

Error: The method or property ScreenOrientation.lockAsync is not available on android, are you sure you’ve linked all the native dependencies properly?

What can I provide for you to get a better understanding of this issue?

My problem turned out to be that I was referring to the incorrect Expo SDK version. I was referring to SDK version 37 where the import statement is as follows:

import * as ScreenOrientation from 'expo-screen-orientation'

when I should have been referring to SDK 36 where the import statement is as follows:

import { ScreenOrientation } from 'expo'
2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.