mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-05-02 05:16:28 +01:00
Merge pull request #177 from fredrikburmester/fix/video-rotation-bug
fix: video rotation bug by updating screen dimensions dynamically using an event listener
This commit is contained in:
@@ -2,6 +2,7 @@ import { Controls } from "@/components/video-player/Controls";
|
|||||||
import { useAndroidNavigationBar } from "@/hooks/useAndroidNavigationBar";
|
import { useAndroidNavigationBar } from "@/hooks/useAndroidNavigationBar";
|
||||||
import { useOrientation } from "@/hooks/useOrientation";
|
import { useOrientation } from "@/hooks/useOrientation";
|
||||||
import { useOrientationSettings } from "@/hooks/useOrientationSettings";
|
import { useOrientationSettings } from "@/hooks/useOrientationSettings";
|
||||||
|
import useScreenDimensions from "@/hooks/useScreenDimensions";
|
||||||
import { useWebSocket } from "@/hooks/useWebsockets";
|
import { useWebSocket } from "@/hooks/useWebsockets";
|
||||||
import { apiAtom } from "@/providers/JellyfinProvider";
|
import { apiAtom } from "@/providers/JellyfinProvider";
|
||||||
import {
|
import {
|
||||||
@@ -17,7 +18,13 @@ import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api";
|
|||||||
import * as Haptics from "expo-haptics";
|
import * as Haptics from "expo-haptics";
|
||||||
import { useFocusEffect } from "expo-router";
|
import { useFocusEffect } from "expo-router";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import React, { useCallback, useMemo, useRef, useState } from "react";
|
import React, {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
import { Dimensions, Pressable, StatusBar, View } from "react-native";
|
import { Dimensions, Pressable, StatusBar, View } from "react-native";
|
||||||
import { useSharedValue } from "react-native-reanimated";
|
import { useSharedValue } from "react-native-reanimated";
|
||||||
import Video, {
|
import Video, {
|
||||||
@@ -34,8 +41,7 @@ export default function page() {
|
|||||||
const poster = usePoster(playSettings, api);
|
const poster = usePoster(playSettings, api);
|
||||||
const videoSource = useVideoSource(playSettings, api, poster, playUrl);
|
const videoSource = useVideoSource(playSettings, api, poster, playUrl);
|
||||||
const firstTime = useRef(true);
|
const firstTime = useRef(true);
|
||||||
|
const screenDimensions = useScreenDimensions();
|
||||||
const screenDimensions = Dimensions.get("screen");
|
|
||||||
|
|
||||||
const [isPlaybackStopped, setIsPlaybackStopped] = useState(false);
|
const [isPlaybackStopped, setIsPlaybackStopped] = useState(false);
|
||||||
const [showControls, setShowControls] = useState(true);
|
const [showControls, setShowControls] = useState(true);
|
||||||
|
|||||||
27
hooks/useScreenDimensions.ts
Normal file
27
hooks/useScreenDimensions.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { Dimensions, ScaledSize } from "react-native";
|
||||||
|
|
||||||
|
const useScreenDimensions = (): ScaledSize => {
|
||||||
|
const [screenDimensions, setScreenDimensions] = useState(
|
||||||
|
Dimensions.get("screen")
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const updateDimensions = () => {
|
||||||
|
setScreenDimensions(Dimensions.get("screen"));
|
||||||
|
};
|
||||||
|
|
||||||
|
const dimensionsListener = Dimensions.addEventListener(
|
||||||
|
"change",
|
||||||
|
updateDimensions
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
dimensionsListener.remove();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return screenDimensions;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useScreenDimensions;
|
||||||
Reference in New Issue
Block a user