chore: add mobile app

This commit is contained in:
2026-02-07 22:33:02 +01:00
parent db34640acc
commit e89384ad4e
29327 changed files with 3886944 additions and 12 deletions
+93
View File
@@ -0,0 +1,93 @@
import type { ExpoConfig } from 'expo/config';
import type {
EmbeddedManifest,
EASConfig,
ExpoGoConfig,
ExpoUpdatesManifest,
} from 'expo-manifests';
import type { Manifest as UpdatesManifest } from 'expo-updates';
import {
AndroidManifest,
AppOwnership,
Constants,
ExecutionEnvironment,
IOSManifest,
NativeConstants,
PlatformManifest,
UserInterfaceIdiom,
WebManifest,
} from './Constants.types';
import ExponentConstants from './ExponentConstants.web.js';
type DevLauncherManifest = ExpoUpdatesManifest;
export {
AndroidManifest,
AppOwnership,
Constants,
ExecutionEnvironment,
IOSManifest,
NativeConstants,
PlatformManifest,
UserInterfaceIdiom,
WebManifest,
};
type RawManifest = UpdatesManifest | DevLauncherManifest | ExpoConfig;
const PARSED_MANIFEST: RawManifest = (() => {
if (typeof ExponentConstants?.manifest === 'string') {
return JSON.parse(ExponentConstants.manifest);
}
return ExponentConstants?.manifest as any;
})();
const constants: Constants = ExponentConstants;
Object.defineProperties(constants, {
/**
* Use `manifest` property by default.
* This property is only used for internal purposes.
* It behaves similarly to the original one, but suppresses warning upon no manifest available.
* `expo-asset` uses it to prevent users from seeing mentioned warning.
*/
__unsafeNoWarnManifest: {
get(): EmbeddedManifest | null {
return PARSED_MANIFEST as any;
},
enumerable: false,
},
manifest: {
get(): EmbeddedManifest | null {
return PARSED_MANIFEST as any;
},
enumerable: true,
},
expoConfig: {
get():
| (ExpoConfig & {
/**
* Only present during development using @expo/cli.
*/
hostUri?: string;
})
| null {
return PARSED_MANIFEST as any;
},
enumerable: true,
},
expoGoConfig: {
get(): ExpoGoConfig | null {
return PARSED_MANIFEST as any;
},
enumerable: true,
},
easConfig: {
get(): EASConfig | null {
return PARSED_MANIFEST as any;
},
enumerable: true,
},
});
export default constants as Constants;
+257
View File
@@ -0,0 +1,257 @@
import type { ExpoConfig } from 'expo/config';
// @ts-ignore -- optional interface, will gracefully degrade to `any` if not installed
import type {
EmbeddedManifest,
EASConfig,
ExpoGoConfig,
ExpoUpdatesManifest,
// @ts-ignore -- optional interface, will gracefully degrade to `any` if not installed
} from 'expo-manifests';
import { CodedError, requireOptionalNativeModule } from 'expo-modules-core';
// @ts-ignore -- optional interface, will gracefully degrade to `any` if not installed
import type { Manifest as UpdatesManifest, ExpoUpdatesModule } from 'expo-updates';
import { Platform, NativeModules } from 'react-native';
import {
AndroidManifest,
AppOwnership,
Constants,
ExecutionEnvironment,
IOSManifest,
NativeConstants,
PlatformManifest,
UserInterfaceIdiom,
WebManifest,
} from './Constants.types';
import ExponentConstants from './ExponentConstants';
type DevLauncherManifest = ExpoUpdatesManifest;
export {
AndroidManifest,
AppOwnership,
Constants,
ExecutionEnvironment,
IOSManifest,
NativeConstants,
PlatformManifest,
UserInterfaceIdiom,
WebManifest,
};
if (!ExponentConstants) {
console.warn(
"No native ExponentConstants module found, are you sure the expo-constants's module is linked properly?"
);
}
const ExpoUpdates = requireOptionalNativeModule<ExpoUpdatesModule>('ExpoUpdates');
let rawUpdatesManifest: UpdatesManifest | null = null;
// If expo-updates defines a non-empty manifest, prefer that one
if (ExpoUpdates) {
let updatesManifest: object | undefined;
if (ExpoUpdates.manifest) {
updatesManifest = ExpoUpdates.manifest;
} else if (ExpoUpdates.manifestString) {
updatesManifest = JSON.parse(ExpoUpdates.manifestString);
}
if (updatesManifest && Object.keys(updatesManifest).length > 0) {
rawUpdatesManifest = updatesManifest as any;
}
}
// If dev-launcher defines a non-empty manifest, prefer that one
let rawDevLauncherManifest: DevLauncherManifest | null = null;
if (NativeModules.EXDevLauncher) {
let devLauncherManifest;
if (NativeModules.EXDevLauncher.manifestString) {
devLauncherManifest = JSON.parse(NativeModules.EXDevLauncher.manifestString);
}
if (devLauncherManifest && Object.keys(devLauncherManifest).length > 0) {
rawDevLauncherManifest = devLauncherManifest as any;
}
}
// Fall back to ExponentConstants.manifest if we don't have one from Updates
let rawAppConfig: ExpoConfig | null = null;
if (ExponentConstants && ExponentConstants.manifest) {
const appConfig: object | string = ExponentConstants.manifest;
// On Android we pass the manifest in JSON form so this step is necessary
if (typeof appConfig === 'string') {
rawAppConfig = JSON.parse(appConfig);
} else {
rawAppConfig = appConfig as any;
}
}
type RawManifest = UpdatesManifest | DevLauncherManifest | ExpoConfig;
let rawManifest: RawManifest | null = rawUpdatesManifest ?? rawDevLauncherManifest ?? rawAppConfig;
const { name, appOwnership, ...nativeConstants } = (ExponentConstants || {}) as any;
const constants: Constants = {
...nativeConstants,
// Ensure this is null in bare workflow
appOwnership: appOwnership ?? null,
};
Object.defineProperties(constants, {
/**
* Use `manifest` property by default.
* This property is only used for internal purposes.
* It behaves similarly to the original one, but suppresses warning upon no manifest available.
* `expo-asset` uses it to prevent users from seeing mentioned warning.
*/
__unsafeNoWarnManifest: {
get(): EmbeddedManifest | null {
const maybeManifest = getManifest(true);
if (!maybeManifest || !isEmbeddedManifest(maybeManifest)) {
return null;
}
return maybeManifest;
},
enumerable: false,
},
__unsafeNoWarnManifest2: {
get(): ExpoUpdatesManifest | null {
const maybeManifest = getManifest(true);
if (!maybeManifest || !isExpoUpdatesManifest(maybeManifest)) {
return null;
}
return maybeManifest;
},
enumerable: false,
},
manifest: {
get(): EmbeddedManifest | null {
const maybeManifest = getManifest();
if (!maybeManifest || !isEmbeddedManifest(maybeManifest)) {
return null;
}
return maybeManifest;
},
enumerable: true,
},
manifest2: {
get(): ExpoUpdatesManifest | null {
const maybeManifest = getManifest();
if (!maybeManifest || !isExpoUpdatesManifest(maybeManifest)) {
return null;
}
return maybeManifest;
},
enumerable: true,
},
expoConfig: {
get():
| (ExpoConfig & {
/**
* Only present during development using @expo/cli.
*/
hostUri?: string;
})
| null {
const maybeManifest = getManifest(true);
if (!maybeManifest) {
return null;
}
// if running an embedded update, maybeManifest is a EmbeddedManifest which doesn't have
// the expo config. Instead, the embedded expo-constants app.config should be used.
if (ExpoUpdates && ExpoUpdates.isEmbeddedLaunch) {
return rawAppConfig;
}
if (isExpoUpdatesManifest(maybeManifest)) {
return maybeManifest.extra?.expoClient ?? null;
} else if (isEmbeddedManifest(maybeManifest)) {
return maybeManifest as any;
}
return null;
},
enumerable: true,
},
expoGoConfig: {
get(): ExpoGoConfig | null {
const maybeManifest = getManifest(true);
if (!maybeManifest) {
return null;
}
if (isExpoUpdatesManifest(maybeManifest)) {
return maybeManifest.extra?.expoGo ?? null;
} else if (isEmbeddedManifest(maybeManifest)) {
return maybeManifest as any;
}
return null;
},
enumerable: true,
},
easConfig: {
get(): EASConfig | null {
const maybeManifest = getManifest(true);
if (!maybeManifest) {
return null;
}
if (isExpoUpdatesManifest(maybeManifest)) {
return maybeManifest.extra?.eas ?? null;
} else if (isEmbeddedManifest(maybeManifest)) {
return maybeManifest as any;
}
return null;
},
enumerable: true,
},
__rawManifest_TEST: {
get(): RawManifest | null {
return rawManifest;
},
set(value: RawManifest | null) {
rawManifest = value;
},
enumerable: false,
},
});
function isEmbeddedManifest(manifest: RawManifest): manifest is EmbeddedManifest {
return !isExpoUpdatesManifest(manifest);
}
function isExpoUpdatesManifest(manifest: RawManifest): manifest is ExpoUpdatesManifest {
return 'metadata' in manifest;
}
function getManifest(suppressWarning = false): RawManifest | null {
if (!rawManifest) {
const invalidManifestType = rawManifest === null ? 'null' : 'undefined';
if (
nativeConstants.executionEnvironment === ExecutionEnvironment.Bare &&
Platform.OS !== 'web'
) {
if (!suppressWarning) {
console.warn(
`Constants.manifest is ${invalidManifestType} because the embedded app.config could not be read. Ensure that you have installed the expo-constants build scripts if you need to read from Constants.manifest.`
);
}
} else if (
nativeConstants.executionEnvironment === ExecutionEnvironment.StoreClient ||
nativeConstants.executionEnvironment === ExecutionEnvironment.Standalone
) {
// If we somehow get here, this is a truly exceptional state to be in.
// Constants.manifest should *always* be defined in those contexts.
throw new CodedError(
'ERR_CONSTANTS_MANIFEST_UNAVAILABLE',
`Constants.manifest is ${invalidManifestType}, must be an object.`
);
}
}
return rawManifest;
}
export default constants as Constants;
+253
View File
@@ -0,0 +1,253 @@
import type { ExpoConfig } from 'expo/config';
import type {
EASConfig as ManifestsEASConfig,
ExpoGoConfig as ManifestsExpoGoConfig,
ExpoUpdatesManifest,
EmbeddedManifest,
ManifestAsset as ManifestAssetForReExport,
ManifestExtra as ManifestExtraForReExport,
ClientScopingConfig as ClientScopingConfigForReExport,
ExpoGoPackagerOpts as ExpoGoPackagerOptsForReExport,
// @ts-ignore -- optional interface, will gracefully degrade to `any` not installed
} from 'expo-manifests';
export enum AppOwnership {
/**
* The experience is running inside the Expo Go app.
* @deprecated Use [`Constants.executionEnvironment`](#executionenvironment) instead.
*/
Expo = 'expo',
}
// @docsMissing
export enum ExecutionEnvironment {
Bare = 'bare',
Standalone = 'standalone',
StoreClient = 'storeClient',
}
// @needsAudit
/**
* Current supported values are `handset`, `tablet`, `desktop` and `tv`. CarPlay will show up
* as `unsupported`.
*/
export enum UserInterfaceIdiom {
Handset = 'handset',
Tablet = 'tablet',
Desktop = 'desktop',
TV = 'tv',
Unsupported = 'unsupported',
}
// @needsAudit
/**
* @platform ios
*/
export type IOSManifest = {
/**
* The build number specified in the embedded **Info.plist** value for `CFBundleVersion` in this app.
* In a standalone app, you can set this with the `ios.buildNumber` value in **app.json**. This
* may differ from the value in `Constants.expoConfig.ios.buildNumber` because the manifest
* can be updated, whereas this value will never change for a given native binary.
* The value is set to `null` in case you run your app in Expo Go.
*/
buildNumber: string | null;
/**
* The Apple internal model identifier for this device.
* @example
* `iPhone1,1`
* @deprecated Use `expo-device`'s [`Device.modelId`](./device/#devicemodelid).
*/
platform: string;
/**
* The human-readable model name of this device. For example, `"iPhone 7 Plus"` if it can be determined,
* otherwise will be `null`.
* @deprecated Moved to `expo-device` as [`Device.modelName`](./device/#devicemodelname).
*/
model: string | null;
/**
* The user interface idiom of the current device, such as whether the app is running on an iPhone, iPad, Mac or Apple TV.
* @deprecated Use `expo-device`'s [`Device.getDeviceTypeAsync()`](./device/#devicegetdevicetypeasync).
*/
userInterfaceIdiom: UserInterfaceIdiom;
/**
* The version of iOS running on this device.
* @example
* `10.3`
* @deprecated Use `expo-device`'s [`Device.osVersion`](./device/#deviceosversion).
*/
systemVersion: string;
} & Record<string, any>;
// @needsAudit
/**
* @platform android
*/
export type AndroidManifest = {
/**
* The version code set by `android.versionCode` in app.json.
* The value is set to `null` in case you run your app in Expo Go.
* @deprecated Use `expo-application`'s [`Application.nativeBuildVersion`](./application/#applicationnativebuildversion).
*/
versionCode: number;
} & Record<string, any>;
/**
* @platform web
*/
export type WebManifest = Record<string, any>;
// type re-exports to prevent breaking change
export type ManifestAsset = ManifestAssetForReExport;
export type Manifest = ExpoUpdatesManifest;
export type ManifestExtra = ManifestExtraForReExport;
export type EASConfig = ManifestsEASConfig;
export type ClientScopingConfig = ClientScopingConfigForReExport;
export type ExpoGoConfig = ManifestsExpoGoConfig;
export type ExpoGoPackagerOpts = ExpoGoPackagerOptsForReExport;
// @needsAudit @docsMissing
export type PlatformManifest = {
ios?: IOSManifest;
android?: AndroidManifest;
web?: WebManifest;
detach?: {
scheme?: string;
[key: string]: any;
};
scheme?: string;
hostUri?: string;
developer?: string;
} & Record<string, any>;
// @needsAudit @docsMissing
export type NativeConstants = {
/**
* @hidden
*/
name: 'ExponentConstants';
/**
* Returns `expo` when running in Expo Go, otherwise `null`.
* @deprecated Use [`Constants.executionEnvironment`](#executionenvironment) instead.
*/
appOwnership: AppOwnership | null;
/**
* Returns `true` when the app is running in debug mode (`__DEV__`). Otherwise, returns `false`.
*/
debugMode: boolean;
/**
* A human-readable name for the device type.
*/
deviceName?: string;
/**
* The [device year class](https://github.com/facebook/device-year-class) of this device.
* @deprecated Moved to `expo-device` as [`Device.deviceYearClass`](./device/#deviceyearclass).
*/
deviceYearClass: number | null;
/**
* Returns the current execution environment.
*/
executionEnvironment: ExecutionEnvironment;
experienceUrl: string;
/**
* Nullable only on the web.
*/
expoRuntimeVersion: string | null;
/**
* The version string of the Expo Go app currently running.
* Returns `null` in bare workflow and web.
*/
expoVersion: string | null;
isDetached?: boolean;
intentUri?: string;
/**
* Returns `true` if the app is running in headless mode. Otherwise, returns `false`.
*/
isHeadless: boolean;
linkingUri: string;
/**
* @hidden
* Manifest embedded in the build. Returns `null` when `manifest2` is non-null.
* @deprecated Use `Constants.expoConfig` instead, which behaves more consistently across EAS Build
* and EAS Update.
*/
manifest: EmbeddedManifest | null;
/**
* Manifest for Expo apps using modern Expo Updates from a remote source, such as apps that
* use EAS Update. `Constants.expoConfig` should be used for accessing the Expo config object.
*/
manifest2: ExpoUpdatesManifest | null;
/**
* The standard Expo config object defined in **app.json** and **app.config.js** files. For both
* classic and modern manifests, whether they are embedded or remote.
*/
expoConfig:
| (ExpoConfig & {
/**
* Only present during development using @expo/cli.
*/
hostUri?: string;
})
| null;
/**
* The standard Expo Go config object populated when running in Expo Go.
*/
expoGoConfig: ManifestsExpoGoConfig | null;
/**
* The standard EAS config object populated when using EAS.
*/
easConfig: ManifestsEASConfig | null;
/**
* A string that is unique to the current session of your app. It is different across apps and
* across multiple launches of the same app.
*/
sessionId: string;
/**
* The default status bar height for the device. Does not factor in changes when location tracking
* is in use or a phone call is active.
*/
statusBarHeight: number;
/**
* A list of the system font names available on the current device.
*/
systemFonts: string[];
systemVersion?: number;
/**
* @hidden
*/
supportedExpoSdks?: string[];
/**
* Returns the specific platform manifest object.
*
* > **Note**: This is distinct from the `manifest` and `manifest2`.
*/
platform?: PlatformManifest;
/**
* Gets the user agent string which would be included in requests sent by a web view running on
* this device. This is probably not the same user agent you might be providing in your JS `fetch`
* requests.
*/
getWebViewUserAgentAsync: () => Promise<string | null>;
} & Record<string, any>;
/**
* @hidden
*/
export type Constants = NativeConstants & {
/**
* > **Warning**: Do not use this property. Use `manifest` by default.
*
* In certain cases accessing manifest via this property
* suppresses important warning about missing manifest.
*/
__unsafeNoWarnManifest?: EmbeddedManifest;
/**
* > **Warning**: Do not use this property. Use `manifest2` by default.
*
* In certain cases accessing manifest via this property
* suppresses important warning about missing manifest.
*/
__unsafeNoWarnManifest2?: ExpoUpdatesManifest;
};
+3
View File
@@ -0,0 +1,3 @@
import { requireOptionalNativeModule } from 'expo-modules-core';
export default requireOptionalNativeModule('ExponentConstants');
+103
View File
@@ -0,0 +1,103 @@
import { ExecutionEnvironment, NativeConstants, WebManifest } from './Constants.types';
declare let __DEV__: boolean;
declare let process: { env: any };
declare let navigator: Navigator;
declare let location: Location;
const _sessionId = (Date.now() + '-' + Math.floor(Math.random() * 1000000000)).toString();
function getBrowserName(): string | undefined {
if (typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string') {
const agent = navigator.userAgent.toLowerCase();
if (agent.includes('edge')) {
return 'Edge';
} else if (agent.includes('edg')) {
return 'Chromium Edge';
} else if (agent.includes('opr') && 'opr' in window && !!window['opr']) {
return 'Opera';
} else if (agent.includes('chrome') && 'chrome' in window && !!window['chrome']) {
return 'Chrome';
} else if (agent.includes('trident')) {
return 'IE';
} else if (agent.includes('firefox')) {
return 'Firefox';
} else if (agent.includes('safari')) {
return 'Safari';
}
}
return undefined;
}
export default {
get appOwnership() {
return null;
},
get executionEnvironment() {
return ExecutionEnvironment.Bare;
},
get sessionId(): string {
return _sessionId;
},
get isHeadless(): boolean {
if (typeof navigator === 'undefined') return true;
return /\bHeadlessChrome\//.test(navigator.userAgent);
},
get expoVersion(): string | null {
return (this.manifest as any)!.sdkVersion || null;
},
get linkingUri(): string {
if (typeof location !== 'undefined') {
// On native this is `exp://`
// On web we should use the protocol and hostname (location.origin)
return location.origin;
} else {
return '';
}
},
get expoRuntimeVersion(): string | null {
return this.expoVersion;
},
get deviceName(): string | undefined {
return getBrowserName();
},
get systemFonts(): string[] {
// TODO: Bacon: Maybe possible.
return [];
},
get statusBarHeight(): number {
return 0;
},
get deviceYearClass(): number | null {
// TODO: Bacon: The android version isn't very accurate either, maybe we could try and guess this value.
return null;
},
get manifest(): WebManifest {
// This is defined by @expo/webpack-config or babel-preset-expo.
// If your site is bundled with a different config then you may not have access to the app.json automatically.
return process.env.APP_MANIFEST || {};
},
get manifest2(): null {
return null;
},
get experienceUrl(): string {
if (typeof location !== 'undefined') {
return location.origin;
} else {
return '';
}
},
get debugMode(): boolean {
return __DEV__;
},
async getWebViewUserAgentAsync(): Promise<string | null> {
if (typeof navigator !== 'undefined') {
return navigator.userAgent;
} else {
return null;
}
},
} as NativeConstants;