UNPKG

1.71 kBPlain TextView Raw
1'use strict';
2import { Platform } from 'react-native';
3
4// This type is necessary since some libraries tend to do a lib check
5// and this file causes type errors on `global` access.
6type localGlobal = typeof global & Record<string, unknown>;
7
8export function isJest(): boolean {
9 return !!process.env.JEST_WORKER_ID;
10}
11
12// `isChromeDebugger` also returns true in Jest environment, so `isJest()` check should always be performed first
13export function isChromeDebugger(): boolean {
14 return (
15 (!(global as localGlobal).nativeCallSyncHook ||
16 !!(global as localGlobal).__REMOTEDEV__) &&
17 !(global as localGlobal).RN$Bridgeless
18 );
19}
20
21export function isWeb(): boolean {
22 return Platform.OS === 'web';
23}
24
25export function isAndroid(): boolean {
26 return Platform.OS === 'android';
27}
28
29function isWindows(): boolean {
30 return Platform.OS === 'windows';
31}
32
33export function shouldBeUseWeb() {
34 return isJest() || isChromeDebugger() || isWeb() || isWindows();
35}
36
37export function isFabric() {
38 return !!(global as localGlobal)._IS_FABRIC;
39}
40
41export function isWindowAvailable() {
42 // the window object is unavailable when building the server portion of a site that uses SSG
43 // this function shouldn't be used to conditionally render components
44 // https://www.joshwcomeau.com/react/the-perils-of-rehydration/
45 // @ts-ignore Fallback if `window` is undefined.
46 return typeof window !== 'undefined';
47}
48
49export function isReducedMotion() {
50 return isWeb()
51 ? isWindowAvailable()
52 ? // @ts-ignore Fallback if `window` is undefined.
53 !window.matchMedia('(prefers-reduced-motion: no-preference)').matches
54 : false
55 : !!(global as localGlobal)._REANIMATED_IS_REDUCED_MOTION;
56}