rago182
rago182

Reputation: 185

React Native Expo lock screen orientation but still detect orientation change

I'm trying to find a way to keep my screen orientation lock in React Native Expo, but still be able to detect a change in orientation. Why? I want to simply rotate a few icons when the person puts their phone in landscape instead of Expo changing the width into height and the height into the width.

Upvotes: 4

Views: 1627

Answers (1)

JCraine
JCraine

Reputation: 1424

I'm not sure if there's a better way, but I'm using unlockAsync right after the screen locks into the desired orientation.

useEffect(() => {
    (async () => {
      if (isFullscreen) {
        await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_LEFT);
      } else {
        await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP);
      }
      ScreenOrientation.unlockAsync(); // <-- allow further rotation
    })();
  }, [isFullscreen]);

Upvotes: 1

Related Questions