/
Expo.fx.tsx
104 lines (90 loc) · 3.69 KB
/
Expo.fx.tsx
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import './environment/validate.fx';
// load remote logging for compatibility with custom development clients
import './environment/logging.fx';
import './environment/react-native-logs.fx';
// load expo-asset immediately to set a custom `source` transformer in React Native
import 'expo-asset';
import { NativeModulesProxy, Platform } from '@unimodules/core';
import Constants, { ExecutionEnvironment } from 'expo-constants';
import * as Font from 'expo-font';
import { installWebGeolocationPolyfill } from 'expo-location';
import React from 'react';
import { AppRegistry, StyleSheet } from 'react-native';
import DevAppContainer from './environment/DevAppContainer';
// install globals
declare let module: any;
// Represents an app running in the store client or an app built with the legacy `expo build` command.
// `false` when running in bare workflow, custom dev clients, or `eas build`s (managed or bare).
// This should be used to ensure code that _should_ exist is treated as such.
const isManagedEnvironment =
Constants.executionEnvironment === ExecutionEnvironment.Standalone ||
Constants.executionEnvironment === ExecutionEnvironment.StoreClient;
// Legacy convenience warning, this will be stripped in production.
if (__DEV__) {
// @ts-ignore: TODO: not on the schema
if (Constants.manifest?.experiments?.redesignedLogBox) {
console.warn(
'LogBox is enabled by default on SDK 39 and higher. You can now remove the experiments.redesignedLogBox from your app configuration to get rid of this warning.'
);
}
}
// If expo-font is installed and the style preprocessor is available, use it to parse fonts.
if (StyleSheet.setStyleAttributePreprocessor) {
StyleSheet.setStyleAttributePreprocessor('fontFamily', Font.processFontFamily);
}
// polyfill navigator.geolocation
// TODO: Deprecate this in the future because the side effect is just a convenience.
installWebGeolocationPolyfill();
if (module && module.exports && global) {
try {
// This is more risky so we wrap it in a try/catch in bare workflow.
// No one should be using this global anymore and it'll be deprecated.
const globals = require('./globals');
// @ts-ignore
global.__exponent = globals;
// @ts-ignore
global.__expo = globals;
// @ts-ignore
global.Expo = globals;
} catch (error) {
if (isManagedEnvironment) {
throw error;
}
}
}
// Asserts if bare workflow isn't setup correctly.
if (NativeModulesProxy.ExpoUpdates?.isMissingRuntimeVersion) {
const message =
'expo-updates is installed but there is no runtime or SDK version configured. ' +
"You'll need to configure one of these two properties in " +
Platform.select({ ios: 'Expo.plist', android: 'AndroidManifest.xml' }) +
' before OTA updates will work properly.';
if (__DEV__) {
console.warn(message);
} else {
throw new Error(message);
}
}
// Having two if statements will enable terser to remove the entire block.
if (__DEV__) {
// Only enable the fast refresh indicator for managed iOS apps in dev mode.
if (isManagedEnvironment && Platform.OS === 'ios') {
// add the dev app container wrapper component on ios
// @ts-ignore
AppRegistry.setWrapperComponentProvider(() => DevAppContainer);
// @ts-ignore
const originalSetWrapperComponentProvider = AppRegistry.setWrapperComponentProvider;
// @ts-ignore
AppRegistry.setWrapperComponentProvider = provider => {
function PatchedProviderComponent(props: any) {
const ProviderComponent = provider();
return (
<DevAppContainer>
<ProviderComponent {...props} />
</DevAppContainer>
);
}
originalSetWrapperComponentProvider(() => PatchedProviderComponent);
};
}
}