import { useEffect, useState } from "react";
import * as ScreenOrientation from "expo-screen-orientation";

export const useScreenOrientation = () => {
  const [isPortrait, setIsPortrait] = useState<boolean>(true);
  useEffect(() => {
    const listener = ScreenOrientation.addOrientationChangeListener((event) => {
      if (
        event.orientationInfo.orientation ===
        ScreenOrientation.Orientation.PORTRAIT_UP
      ) {
        setIsPortrait(true);
      } else {
        setIsPortrait(false);
      }
    });
    return () => {
      ScreenOrientation.removeOrientationChangeListener(listener);
    };
  }, []);
  return { isPortrait };
};
