refactor(mobile): allow do not open links in app (#3101)

This commit is contained in:
Stephen Zhou 2025-03-13 17:20:07 +08:00 committed by GitHub
parent 087906aeb4
commit 76ebd6969d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 19 deletions

View File

@ -29,8 +29,8 @@ const createDefaultSettings = (): GeneralSettings => ({
// TTS
voice: "en-US-AndrewMultilingualNeural",
// Video
openVideoInApp: true,
// Content
openLinksInApp: true,
})
export const {

View File

@ -18,8 +18,5 @@ export interface GeneralSettings {
*/
autoExpandLongSocialMedia: boolean
/**
* Open YouTube/Bilibili videos in their respective apps rather than in-app browser
*/
openVideoInApp: boolean
openLinksInApp: boolean
}

View File

@ -1,4 +1,7 @@
import { requireNativeModule } from "expo"
import { openURL } from "expo-linking"
import { getGeneralSettings } from "@/src/atoms/settings/general"
interface NativeModule {
openLink: (url: string) => Promise<{
@ -9,6 +12,11 @@ interface NativeModule {
}
const nativeModule = requireNativeModule("Helper") as NativeModule
export const openLink = (url: string, onDismiss?: () => void) => {
const { openLinksInApp } = getGeneralSettings()
if (!openLinksInApp) {
openURL(url)
return
}
nativeModule.openLink(url).then((res) => {
if (res.type === "dismiss") {
onDismiss?.()

View File

@ -1,7 +1,7 @@
import { transformVideoUrl } from "@follow/utils"
import { Linking } from "react-native"
import { useGeneralSettingKey } from "@/src/atoms/settings/general"
import { getGeneralSettings } from "@/src/atoms/settings/general"
import { Image } from "@/src/components/ui/image/Image"
import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable"
import { openLink } from "@/src/lib/native"
@ -14,7 +14,6 @@ import { EntryGridFooter } from "../../entry-content/EntryGridFooter"
export function EntryVideoItem({ id }: { id: string }) {
const item = useEntry(id)
const needOpenVideoInApp = useGeneralSettingKey("openVideoInApp")
if (!item || !item.media) {
return null
@ -30,7 +29,7 @@ export function EntryVideoItem({ id }: { id: string }) {
toast.error("No video URL found")
return
}
openVideo(item.url, needOpenVideoInApp)
openVideo(item.url)
}}
>
<Image
@ -72,8 +71,9 @@ const parseSchemeLink = (url: string) => {
}
}
const openVideo = async (url: string, openVideoInApp = false) => {
if (openVideoInApp) {
const openVideo = async (url: string) => {
const { openLinksInApp } = getGeneralSettings()
if (!openLinksInApp) {
const schemeLink = parseSchemeLink(url)
try {
const isInstalled = !!schemeLink && (await Linking.canOpenURL(schemeLink))

View File

@ -25,7 +25,7 @@ export const GeneralScreen = () => {
const expandLongSocialMedia = useGeneralSettingKey("autoExpandLongSocialMedia")
const markAsReadWhenScrolling = useGeneralSettingKey("scrollMarkUnread")
const markAsReadWhenInView = useGeneralSettingKey("renderMarkUnread")
const openVideoInApp = useGeneralSettingKey("openVideoInApp")
const openLinksInApp = useGeneralSettingKey("openLinksInApp")
return (
<SafeNavigationScrollView className="bg-system-grouped-background">
@ -147,17 +147,14 @@ export const GeneralScreen = () => {
{/* Content Behavior */}
<View className="mt-8">
<GroupedInsetListSectionHeader label="Video" />
<GroupedInsetListSectionHeader label="Content" />
<GroupedInsetListCard>
<GroupedInsetListCell
label="Open videos in app"
description="Open videos in their respective apps, if available, instead of the in-app browser."
>
<GroupedInsetListCell label="Open Links in app">
<Switch
size="sm"
value={openVideoInApp}
value={openLinksInApp}
onValueChange={(value) => {
setGeneralSetting("openVideoInApp", value)
setGeneralSetting("openLinksInApp", value)
}}
/>
</GroupedInsetListCell>