1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
This commit is contained in:
xmflsct
2022-12-20 23:09:21 +01:00
parent 2ac1d49f9f
commit 54c99eb054
4 changed files with 17 additions and 21 deletions

View File

@ -7,6 +7,7 @@ import { SearchResult } from '@utils/queryHooks/search'
import { getSettingsBrowser } from '@utils/slices/settingsSlice'
import * as Linking from 'expo-linking'
import * as WebBrowser from 'expo-web-browser'
import validUrl from 'valid-url'
export let loadingLink = false
@ -86,18 +87,21 @@ const openLink = async (url: string, navigation?: any) => {
}
loadingLink = false
switch (getSettingsBrowser(store.getState())) {
// Some links might end with an empty space at the end that triggers an error
case 'internal':
await WebBrowser.openBrowserAsync(encodeURI(url), {
dismissButtonStyle: 'close',
enableBarCollapsing: true,
...(await browserPackage())
})
break
case 'external':
await Linking.openURL(encodeURI(url))
break
const validatedUrl = validUrl.isWebUri(url)
if (validatedUrl) {
switch (getSettingsBrowser(store.getState())) {
// Some links might end with an empty space at the end that triggers an error
case 'internal':
await WebBrowser.openBrowserAsync(validatedUrl, {
dismissButtonStyle: 'close',
enableBarCollapsing: true,
...(await browserPackage())
})
break
case 'external':
await Linking.openURL(validatedUrl)
break
}
}
}