diff --git a/apps/expo/src/app/video-player.tsx b/apps/expo/src/app/video-player.tsx
index 7652df3..0ddefc2 100644
--- a/apps/expo/src/app/video-player.tsx
+++ b/apps/expo/src/app/video-player.tsx
@@ -1,18 +1,11 @@
import type { VideoRef } from "react-native-video";
-import React, { Component } from "react";
+import React, { useEffect, useRef, useState } from "react";
import { ActivityIndicator, StyleSheet } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import Video from "react-native-video";
import { useLocalSearchParams } from "expo-router";
import * as ScreenOrientation from "expo-screen-orientation";
-interface VideoPlayerState {
- videoUrl: string;
- fullscreen: boolean;
- isLoading: boolean;
- paused: boolean;
-}
-
interface VideoPlayerProps {
videoUrl: string;
}
@@ -22,87 +15,75 @@ export default function VideoPlayerWrapper() {
const videoUrl = typeof params.videoUrl === "string" ? params.videoUrl : "";
return ;
}
-
-class VideoPlayer extends Component {
- private videoPlayer: React.RefObject;
-
- constructor(props: VideoPlayerProps) {
- super(props);
- this.state = {
- videoUrl: props.videoUrl || "",
- fullscreen: true,
- isLoading: true,
- paused: false,
- };
- this.videoPlayer = React.createRef();
- }
-
- componentDidMount() {
- const lockOrientation = async () => {
- await ScreenOrientation.lockAsync(
- ScreenOrientation.OrientationLock.LANDSCAPE,
- );
- };
-
- const { videoUrl } = this.props;
-
- this.setState({ videoUrl }, () => {
- if (this.videoPlayer.current) {
- this.videoPlayer.current.presentFullscreenPlayer();
- void lockOrientation();
- }
- });
- }
-
- componentWillUnmount() {
- const unlockOrientation = async () => {
- await ScreenOrientation.lockAsync(
- ScreenOrientation.OrientationLock.PORTRAIT_UP,
- );
- };
-
- if (this.videoPlayer.current) {
- this.videoPlayer.current.dismissFullscreenPlayer();
- }
- void unlockOrientation();
- }
-
- onVideoLoadStart = () => {
- this.setState({ isLoading: true });
- };
-
- onReadyForDisplay = () => {
- this.setState({ isLoading: false });
- };
-
- // onVideoError = () => { // probably useful later
- // console.log("Video playback error");
- // };
-
- render() {
- return (
-
-
- {this.state.isLoading && (
-
- )}
-
- );
- }
+interface VideoPlayerProps {
+ videoUrl: string;
}
+const VideoPlayer: React.FC = ({ videoUrl }) => {
+ const [isLoading, setIsLoading] = useState(true);
+ const videoPlayer = useRef(null);
+
+ useEffect(() => {
+ const lockOrientation = async () => {
+ await ScreenOrientation.lockAsync(
+ ScreenOrientation.OrientationLock.LANDSCAPE
+ );
+ };
+
+ const unlockOrientation = async () => {
+ await ScreenOrientation.lockAsync(
+ ScreenOrientation.OrientationLock.PORTRAIT_UP
+ );
+ };
+
+ const presentFullscreenPlayer = async () => {
+ if (videoPlayer.current) {
+ videoPlayer.current.presentFullscreenPlayer();
+ await lockOrientation();
+ }
+ };
+
+ const dismissFullscreenPlayer = async () => {
+ if (videoPlayer.current) {
+ videoPlayer.current.dismissFullscreenPlayer();
+ await unlockOrientation();
+ }
+ };
+
+ setIsLoading(true);
+ void presentFullscreenPlayer();
+
+ return () => {
+ void dismissFullscreenPlayer();
+ };
+ }, [videoUrl]);
+
+ const onVideoLoadStart = () => {
+ setIsLoading(true);
+ };
+
+ const onReadyForDisplay = () => {
+ setIsLoading(false);
+ };
+
+ return (
+
+
+ {isLoading && }
+
+ );
+};
+
const styles = StyleSheet.create({
- // taken from example, probably needs to be nativewind stuff instead
container: {
flex: 1,
justifyContent: "center",