Handle bsky.app links natively
parent
b4a8da4c27
commit
f41ba844b3
|
@ -198,7 +198,7 @@ export function toShortUrl(url: string): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toShareUrl(url: string) {
|
export function toShareUrl(url: string): string {
|
||||||
if (!url.startsWith('https')) {
|
if (!url.startsWith('https')) {
|
||||||
const urlp = new URL('https://bsky.app')
|
const urlp = new URL('https://bsky.app')
|
||||||
urlp.pathname = url
|
urlp.pathname = url
|
||||||
|
@ -206,3 +206,15 @@ export function toShareUrl(url: string) {
|
||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function convertBskyAppUrlIfNeeded(url: string): string {
|
||||||
|
if (url.startsWith('https://bsky.app/')) {
|
||||||
|
try {
|
||||||
|
const urlp = new URL(url)
|
||||||
|
return urlp.pathname
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Unexpected error in convertBskyAppUrlIfNeeded()', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import {
|
||||||
TextStyle,
|
TextStyle,
|
||||||
ViewStyle,
|
ViewStyle,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import {useStores} from '../../../state'
|
import {useStores, RootStoreModel} from '../../../state'
|
||||||
import {RootStoreModel} from '../../../state'
|
import {convertBskyAppUrlIfNeeded} from '../../../lib/strings'
|
||||||
|
|
||||||
export const Link = observer(function Link({
|
export const Link = observer(function Link({
|
||||||
style,
|
style,
|
||||||
|
@ -66,6 +66,7 @@ export const TextLink = observer(function Link({
|
||||||
})
|
})
|
||||||
|
|
||||||
function handleLink(store: RootStoreModel, href: string, longPress: boolean) {
|
function handleLink(store: RootStoreModel, href: string, longPress: boolean) {
|
||||||
|
href = convertBskyAppUrlIfNeeded(href)
|
||||||
if (href.startsWith('http')) {
|
if (href.startsWith('http')) {
|
||||||
Linking.openURL(href)
|
Linking.openURL(href)
|
||||||
} else if (longPress) {
|
} else if (longPress) {
|
||||||
|
|
Loading…
Reference in New Issue