diff --git a/apps/mobile/global.d.ts b/apps/mobile/global.d.ts index 8e9d706bf..9aed8ba26 100644 --- a/apps/mobile/global.d.ts +++ b/apps/mobile/global.d.ts @@ -1,7 +1,8 @@ import type { DOMProps } from "expo/dom" import type { FC } from "react" +import type WebView from "react-native-webview" declare global { - export type WebComponent

= FC

+ export type WebComponent

= FC

> } export {} diff --git a/apps/mobile/package.json b/apps/mobile/package.json index 861c9e8ab..e021e9862 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -42,7 +42,7 @@ "expo-blur": "~14.0.1", "expo-build-properties": "^0.13.1", "expo-clipboard": "~7.0.0", - "expo-constants": "~17.0.3", + "expo-constants": "~17.0.4", "expo-dev-client": "^5.0.9", "expo-file-system": "~18.0.6", "expo-font": "~13.0.1", diff --git a/apps/mobile/src/components/common/FollowWebView.tsx b/apps/mobile/src/components/common/FollowWebView.tsx index 474f2fba2..2bfbd02e6 100644 --- a/apps/mobile/src/components/common/FollowWebView.tsx +++ b/apps/mobile/src/components/common/FollowWebView.tsx @@ -1,14 +1,13 @@ import { callWebviewExpose } from "@follow/shared" -import { parseSafeUrl, transformVideoUrl } from "@follow/utils" import * as Linking from "expo-linking" import type { RefObject } from "react" import { useCallback, useEffect, useState } from "react" import { Platform } from "react-native" -import type { WebViewNavigation, WebViewProps } from "react-native-webview" +import type { WebViewProps } from "react-native-webview" import { WebView } from "react-native-webview" +import { useWebViewNavigation } from "@/src/hooks/useWebViewNavigation" import { signOut } from "@/src/lib/auth" -import { useOpenLink } from "@/src/lib/hooks/use-open-link" const presetUri = Platform.select({ ios: "rn-web/index.html", @@ -16,8 +15,6 @@ const presetUri = Platform.select({ default: "https://app.follow.is", }) -const allowHosts = new Set(["app.follow.is"]) - interface FollowWebViewProps extends WebViewProps { customUrl?: string } @@ -80,32 +77,6 @@ export const FollowWebView = ({ ) } -const useWebViewNavigation = ({ webViewRef }: { webViewRef: RefObject }) => { - const openLink = useOpenLink() - - const onNavigationStateChange = useCallback( - (newNavState: WebViewNavigation) => { - const { url: urlStr } = newNavState - const url = parseSafeUrl(urlStr) - if (!url) return - if (url.protocol === "file:") return - if (allowHosts.has(url.host)) return - - webViewRef.current?.stopLoading() - - const formattedUrl = transformVideoUrl({ url: urlStr }) - if (formattedUrl) { - openLink(formattedUrl) - return - } - openLink(urlStr) - }, - [openLink, webViewRef], - ) - - return { onNavigationStateChange } -} - // We only need to handle deep link at the first time the app is opened let lastInitialUrl: string | null = null const useDeepLink = ({ diff --git a/apps/mobile/src/components/ui/grouped/GroupedList.tsx b/apps/mobile/src/components/ui/grouped/GroupedList.tsx index 5fa9525a8..348d734b8 100644 --- a/apps/mobile/src/components/ui/grouped/GroupedList.tsx +++ b/apps/mobile/src/components/ui/grouped/GroupedList.tsx @@ -84,3 +84,20 @@ export const GroupedInsetListNavigationLink: FC<{ ) } + +export const GroupedInsetListNavigationLinkIcon: FC< + { + backgroundColor: string + } & PropsWithChildren +> = ({ backgroundColor, children }) => { + return ( + + {children} + + ) +} diff --git a/apps/mobile/src/components/ui/typography/Markdown.tsx b/apps/mobile/src/components/ui/typography/Markdown.tsx new file mode 100644 index 000000000..2baf6552c --- /dev/null +++ b/apps/mobile/src/components/ui/typography/Markdown.tsx @@ -0,0 +1,41 @@ +import type { FC } from "react" +import { useRef } from "react" +import { Linking } from "react-native" +import type { WebView } from "react-native-webview" + +import MarkdownWeb from "./MarkdownWeb" + +export const Markdown: FC<{ + value: string + style?: React.CSSProperties + className?: string + + webViewProps?: import("expo/dom").DOMProps +}> = ({ value, style, className, webViewProps }) => { + const ref = useRef(null) + + return ( + { + const { type, url } = JSON.parse(event.nativeEvent.data) + if (type === "openLinkInModal") { + Linking.openURL(url) + } + }, + injectedJavaScriptBeforeContentLoaded: `window.openLinkInModal = (url) => { + window.ReactNativeWebView.postMessage(JSON.stringify({ + type: "openLinkInModal", + url, + })) + }`, + }} + /> + ) +} diff --git a/apps/mobile/src/components/ui/typography/MarkdownWeb.tsx b/apps/mobile/src/components/ui/typography/MarkdownWeb.tsx index e09a17e63..e50ea7988 100644 --- a/apps/mobile/src/components/ui/typography/MarkdownWeb.tsx +++ b/apps/mobile/src/components/ui/typography/MarkdownWeb.tsx @@ -8,28 +8,58 @@ import { useDarkMode } from "usehooks-ts" import { useCSSInjection } from "@/src/theme/web" -const MarkdownWeb: WebComponent<{ value: string; style?: React.CSSProperties }> = ({ - value, - style, -}) => { +declare const window: { + openLinkInModal: (url: string) => void +} +/** + * @internal + */ +const MarkdownWeb: WebComponent<{ + value: string + style?: React.CSSProperties + className?: string +}> = ({ value, style, className }) => { useCSSInjection() const { isDarkMode } = useDarkMode() return (