Live video on the AT Protocol
1import {
2 Link,
3 NavigationProp,
4 ParamListBase,
5 useNavigation,
6} from "@react-navigation/native";
7import usePlatform from "hooks/usePlatform";
8import { useEffect } from "react";
9import { Pressable, StyleProp, ViewStyle } from "react-native";
10import Loading from "./loading/loading";
11
12export type LinkParams = { screen: string; params?: Record<string, string> };
13
14// Web and native have some disagreements about link styling
15// so we have a custom component that handles that
16export default function AQLink({
17 children,
18 to,
19 style,
20}: {
21 children: React.ReactNode;
22 to: LinkParams;
23 style?: StyleProp<ViewStyle>;
24}) {
25 const { isWeb } = usePlatform();
26 const navigation = useNavigation<NavigationProp<ParamListBase>>();
27 const baseStyle: StyleProp<ViewStyle> = {
28 display: "flex",
29 };
30
31 if (isWeb) {
32 return (
33 <Link style={[baseStyle, style]} to={to as any}>
34 {children}
35 </Link>
36 );
37 }
38
39 return (
40 <Pressable
41 style={[baseStyle, style]}
42 onPress={() => navigation.navigate(to.screen, to.params)}
43 >
44 {children}
45 </Pressable>
46 );
47}
48
49export function Redirect({ to }: { to: LinkParams }) {
50 const navigation = useNavigation<NavigationProp<ParamListBase>>();
51 useEffect(() => {
52 console.log("redirecting to", to);
53 navigation.navigate(to.screen, to.params);
54 }, []);
55 return <Loading />;
56}