I am writing a React Native app (iOS only at the moment) and I want to do something whenever the screen orientation changes, where the orientations that I care about are:

  • Landscape-left
  • Portrait
  • Landscape-right
  • Portrait-upside-down

With the built-in Dimensions api, I can listen to changes in the screen dimensions like this:

import {Dimensions} from "react-native"

const dimensionListener = Dimensions.addEventListener("change", () => {
    // Do great things
})

But if I flip my device from landscape-left to landscape-right, this does not trigger, because the dimensions (height/width) have not changed.

Is there another way, e.g. to listen to any "rotation" event at all?

I've seen react-native-orientation and react-native-orientation-locker and it seems like they may be outdated/buggy. A more "native" solution would be great.

0

There are 0 best solutions below