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