1/** 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 * 7 * @format 8 */ 9 10import type * as React from 'react'; 11import type {IPerformanceLogger} from '../Utilities/IPerformanceLogger'; 12 13type Task = (taskData: any) => Promise<void>; 14type TaskProvider = () => Task; 15type TaskCanceller = () => void; 16type TaskCancelProvider = () => TaskCanceller; 17 18export type ComponentProvider = () => React.ComponentType<any>; 19 20export type Runnable = (appParameters: any) => void; 21 22export type AppConfig = { 23 appKey: string; 24 component?: ComponentProvider | undefined; 25 run?: Runnable | undefined; 26}; 27 28export type ComponentProviderInstrumentationHook = ( 29 component: ComponentProvider, 30 scopedPerformanceLogger: IPerformanceLogger, 31) => React.ComponentType<any>; 32 33export type WrapperComponentProvider = ( 34 appParameters: any, 35) => React.ComponentType<any>; 36 37/** 38 * `AppRegistry` is the JS entry point to running all React Native apps. App 39 * root components should register themselves with 40 * `AppRegistry.registerComponent`, then the native system can load the bundle 41 * for the app and then actually run the app when it's ready by invoking 42 * `AppRegistry.runApplication`. 43 * 44 * To "stop" an application when a view should be destroyed, call 45 * `AppRegistry.unmountApplicationComponentAtRootTag` with the tag that was 46 * pass into `runApplication`. These should always be used as a pair. 47 * 48 * `AppRegistry` should be `require`d early in the `require` sequence to make 49 * sure the JS execution environment is setup before other modules are 50 * `require`d. 51 */ 52export namespace AppRegistry { 53 export function setWrapperComponentProvider( 54 provider: WrapperComponentProvider, 55 ): void; 56 57 export function registerConfig(config: AppConfig[]): void; 58 59 export function registerComponent( 60 appKey: string, 61 getComponentFunc: ComponentProvider, 62 section?: boolean, 63 ): string; 64 65 export function registerRunnable(appKey: string, func: Runnable): string; 66 67 export function registerSection( 68 appKey: string, 69 component: ComponentProvider, 70 ): void; 71 72 export function getAppKeys(): string[]; 73 74 export function getSectionKeys(): string[]; 75 76 export function getSections(): Record<string, Runnable>; 77 78 export function unmountApplicationComponentAtRootTag(rootTag: number): void; 79 80 export function runApplication(appKey: string, appParameters: any): void; 81 82 export function setSurfaceProps( 83 appKey: string, 84 appParameters: any, 85 displayMode?: number, 86 ): void; 87 88 export function registerHeadlessTask( 89 appKey: string, 90 task: TaskProvider, 91 ): void; 92 93 export function getRunnable(appKey: string): Runnable | undefined; 94 95 export function getRegistry(): {sections: string[]; runnables: Runnable[]}; 96 97 export function setComponentProviderInstrumentationHook( 98 hook: ComponentProviderInstrumentationHook, 99 ): void; 100 101 export function registerHeadlessTask( 102 taskKey: string, 103 taskProvider: TaskProvider, 104 ): void; 105 106 export function registerCancellableHeadlessTask( 107 taskKey: string, 108 taskProvider: TaskProvider, 109 taskCancelProvider: TaskCancelProvider, 110 ): void; 111 112 export function startHeadlessTask( 113 taskId: number, 114 taskKey: string, 115 data: any, 116 ): void; 117 118 export function cancelHeadlessTask(taskId: number, taskKey: string): void; 119} 120