-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <[email protected]>
- Loading branch information
Showing
13 changed files
with
271 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<P = object> = FC<P & { dom?: DOMProps }> | ||
export type WebComponent<P = object> = FC<P & { dom?: DOMProps } & React.RefAttributes<WebView>> | ||
} | ||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<WebView>(null) | ||
|
||
return ( | ||
<MarkdownWeb | ||
value={value} | ||
ref={ref} | ||
style={style} | ||
className={className} | ||
dom={{ | ||
...webViewProps, | ||
|
||
onMessage: (event) => { | ||
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, | ||
})) | ||
}`, | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { parseSafeUrl, transformVideoUrl } from "@follow/utils" | ||
import type { RefObject } from "react" | ||
import { useCallback } from "react" | ||
import type WebView from "react-native-webview" | ||
import type { WebViewNavigation } from "react-native-webview" | ||
|
||
import { useOpenLink } from "../lib/hooks/use-open-link" | ||
|
||
const allowHosts = new Set(["app.follow.is"]) | ||
export function useWebViewNavigation({ webViewRef }: { webViewRef: RefObject<WebView> }) { | ||
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 } | ||
} |
19 changes: 0 additions & 19 deletions
19
apps/mobile/src/modules/settings/SettingNavigationLink.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.