mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {GestureResponderEvent, Linking} from 'react-native'
2
3import {isNative, isWeb} from './detection'
4
5export async function getInitialURL(): Promise<string | undefined> {
6 if (isNative) {
7 const url = await Linking.getInitialURL()
8 if (url) {
9 return url
10 }
11 return undefined
12 } else {
13 // @ts-ignore window exists -prf
14 if (window.location.pathname !== '/') {
15 return window.location.pathname
16 }
17 return undefined
18 }
19}
20
21export function clearHash() {
22 if (isWeb) {
23 // @ts-ignore window exists -prf
24 window.location.hash = ''
25 }
26}
27
28export function shouldClickOpenNewTab(e: GestureResponderEvent) {
29 /**
30 * A `GestureResponderEvent`, but cast to `any` to avoid using a bunch
31 * of @ts-ignore below.
32 */
33 const event = e as any
34 const isMiddleClick = isWeb && event.button === 1
35 const isMetaKey =
36 isWeb && (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
37 return isMetaKey || isMiddleClick
38}