feat: play video via url

This commit is contained in:
Adrian Castro
2024-04-02 08:51:00 +02:00
parent 21169c6caa
commit df4fe312fc
3 changed files with 30 additions and 17 deletions

View File

@@ -1,6 +1,8 @@
import { useEffect } from "react";
import { Platform } from "react-native"; import { Platform } from "react-native";
import * as Haptics from "expo-haptics"; import * as Haptics from "expo-haptics";
import { Tabs } from "expo-router"; import * as Linking from "expo-linking";
import { Tabs, useRouter } from "expo-router";
import * as ScreenOrientation from "expo-screen-orientation"; import * as ScreenOrientation from "expo-screen-orientation";
import { useTheme, View } from "tamagui"; import { useTheme, View } from "tamagui";
@@ -11,20 +13,21 @@ import TabBarIcon from "~/components/TabBarIcon";
export default function TabLayout() { export default function TabLayout() {
const theme = useTheme(); const theme = useTheme();
// const url = Linking.useURL(); const router = useRouter();
// const router = useRouter();
// useEffect(() => {
// if (url) { const handleOpenURL = (event: Linking.EventType) => {
// const { hostname, queryParams } = Linking.parse(url); const { hostname, queryParams } = Linking.parse(event.url);
// if (hostname === "media") {
// switch (hostname) { router.push({
// case "media": pathname: "/videoPlayer",
// return router.push({ params: { data: JSON.stringify(queryParams) },
// pathname: "/videoPlayer", });
// params: { data: JSON.stringify(queryParams) } }
// }); };
// }
// } Linking.addEventListener("url", handleOpenURL);
}, [router]);
return ( return (
<Tabs <Tabs

View File

@@ -1,7 +1,9 @@
import * as Linking from "expo-linking";
import { Link, Stack } from "expo-router"; import { Link, Stack } from "expo-router";
import { Text, View } from "tamagui"; import { Text, View } from "tamagui";
export default function NotFoundScreen() { export default function NotFoundScreen() {
if (Linking.useURL()) return null;
return ( return (
<> <>
<Stack.Screen options={{ title: "Oops!" }} /> <Stack.Screen options={{ title: "Oops!" }} />

View File

@@ -14,13 +14,21 @@ export const BackButton = () => {
onPress={() => { onPress={() => {
dismissFullscreenPlayer() dismissFullscreenPlayer()
.then(() => { .then(() => {
router.back(); if (router.canGoBack()) {
router.back();
} else {
router.replace("/");
}
return setTimeout(() => { return setTimeout(() => {
Keyboard.dismiss(); Keyboard.dismiss();
}, 100); }, 100);
}) })
.catch(() => { .catch(() => {
router.back(); if (router.canGoBack()) {
router.back();
} else {
router.replace("/");
}
return setTimeout(() => { return setTimeout(() => {
Keyboard.dismiss(); Keyboard.dismiss();
}, 100); }, 100);