Commit 66e7d44a authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Se creó un hook que verifica la orientación del telefono

parent 0f3c12da
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
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 };
};