AppRegistry
Esta página fue traducida por PageTurner AI (beta). No está respaldada oficialmente por el proyecto. ¿Encontraste un error? Reportar problema →
AppRegistry es el punto de entrada en JavaScript para ejecutar todas las aplicaciones de React Native. Los componentes raíz de la aplicación deben registrarse mediante AppRegistry.registerComponent. Luego, el sistema nativo puede cargar el paquete de la aplicación y ejecutarla cuando esté listo invocando AppRegistry.runApplication.
import {Text, AppRegistry} from 'react-native';
const App = () => (
<View>
<Text>App1</Text>
</View>
);
AppRegistry.registerComponent('Appname', () => App);
Para "detener" una aplicación cuando una vista debe destruirse, llama a AppRegistry.unmountApplicationComponentAtRootTag con la etiqueta que se pasó a runApplication. Estos métodos siempre deben usarse en pareja.
AppRegistry debe requerirse al principio de la secuencia de require para garantizar que el entorno de ejecución de JavaScript esté configurado antes de requerir otros módulos.
Referencia
Métodos
getAppKeys()
static getAppKeys(): string[];
Devuelve un arreglo de cadenas.
getRegistry()
static getRegistry(): {sections: string[]; runnables: Runnable[]};
Devuelve un objeto Registry.
getRunnable()
static getRunnable(appKey: string): : Runnable | undefined;
Devuelve un objeto Runnable.
Parámetros:
| Name | Type |
|---|---|
| appKey Required | string |
getSectionKeys()
static getSectionKeys(): string[];
Devuelve un arreglo de cadenas.
getSections()
static getSections(): Record<string, Runnable>;
Devuelve un objeto Runnables.
registerCancellableHeadlessTask()
static registerCancellableHeadlessTask(
taskKey: string,
taskProvider: TaskProvider,
taskCancelProvider: TaskCancelProvider,
);
Registra una tarea sin interfaz (headless) que puede cancelarse. Una tarea sin interfaz es un fragmento de código que se ejecuta sin UI.
Parámetros:
| Name | Type | Description |
|---|---|---|
| taskKey Required | string | The native id for this task instance that was used when startHeadlessTask was called. |
| taskProvider Required | TaskProvider | A promise returning function that takes some data passed from the native side as the only argument. When the promise is resolved or rejected the native side is notified of this event and it may decide to destroy the JS context. |
| taskCancelProvider Required | TaskCancelProvider | a void returning function that takes no arguments; when a cancellation is requested, the function being executed by taskProvider should wrap up and return ASAP. |
registerComponent()
static registerComponent(
appKey: string,
getComponentFunc: ComponentProvider,
section?: boolean,
): string;
Parámetros:
| Name | Type |
|---|---|
| appKey Required | string |
| componentProvider Required | ComponentProvider |
| section | boolean |
registerConfig()
static registerConfig(config: AppConfig[]);
Parámetros:
| Name | Type |
|---|---|
| config Required | AppConfig[] |
registerHeadlessTask()
static registerHeadlessTask(
taskKey: string,
taskProvider: TaskProvider,
);
Registra una tarea sin interfaz (headless). Una tarea sin interfaz es un fragmento de código que se ejecuta sin UI.
Esta es una forma de ejecutar tareas en JavaScript mientras tu aplicación está en segundo plano. Puede usarse, por ejemplo, para sincronizar datos nuevos, gestionar notificaciones push o reproducir música.
Parámetros:
| Name | Type | Description |
|---|---|---|
| taskKey Required | string | The native id for this task instance that was used when startHeadlessTask was called. |
| taskProvider Required | TaskProvider | A promise returning function that takes some data passed from the native side as the only argument. When the promise is resolved or rejected the native side is notified of this event and it may decide to destroy the JS context. |
registerRunnable()
static registerRunnable(appKey: string, func: Runnable): string;
Parámetros:
| Name | Type |
|---|---|
| appKey Required | string |
| run Required | function |
registerSection()
static registerSection(
appKey: string,
component: ComponentProvider,
);
Parámetros:
| Name | Type |
|---|---|
| appKey Required | string |
| component Required | ComponentProvider |
runApplication()
static runApplication(appKey: string, appParameters: any): void;
Carga el paquete JavaScript y ejecuta la aplicación.
Parámetros:
| Name | Type |
|---|---|
| appKey Required | string |
| appParameters Required | any |
setComponentProviderInstrumentationHook()
static setComponentProviderInstrumentationHook(
hook: ComponentProviderInstrumentationHook,
);
Parámetros:
| Name | Type |
|---|---|
| hook Required | function |
Una función hook válida acepta los siguientes argumentos:
| Name | Type |
|---|---|
| component Required | ComponentProvider |
| scopedPerformanceLogger Required | IPerformanceLogger |
La función también debe devolver un componente de React.
setWrapperComponentProvider()
static setWrapperComponentProvider(
provider: WrapperComponentProvider,
);
Parámetros:
| Name | Type |
|---|---|
| provider Required | ComponentProvider |
startHeadlessTask()
static startHeadlessTask(
taskId: number,
taskKey: string,
data: any,
);
Solo se llama desde código nativo. Inicia una tarea sin interfaz.
Parámetros:
| Name | Type | Description |
|---|---|---|
| taskId Required | number | The native id for this task instance to keep track of its execution. |
| taskKey Required | string | The key for the task to start. |
| data Required | any | The data to pass to the task. |
unmountApplicationComponentAtRootTag()
static unmountApplicationComponentAtRootTag(rootTag: number);
Detiene una aplicación cuando una vista debe destruirse.
Parámetros:
| Name | Type |
|---|---|
| rootTag Required | number |
Definiciones de tipos
AppConfig
Configuración de aplicación para el método registerConfig.
| Type |
|---|
| object |
Propiedades:
| Name | Type |
|---|---|
| appKey Required | string |
| component | ComponentProvider |
| run | function |
| section | boolean |
Nota: Se espera que cada configuración defina ya sea
componento la funciónrun.
Registry
| Type |
|---|
| object |
Propiedades:
| Name | Type |
|---|---|
| runnables | array of Runnables |
| sections | array of strings |
Runnable
| Type |
|---|
| object |
Propiedades:
| Name | Type |
|---|---|
| component | ComponentProvider |
| run | function |
Runnables
Objeto con clave appKey y valor de tipo Runnable.
| Type |
|---|
| object |
Task
Una Task es una función que acepta cualquier dato como argumento y devuelve una Promise que se resuelve en undefined.
| Type |
|---|
| function |
TaskCanceller
Un TaskCanceller es una función que no acepta argumentos y devuelve void.
| Type |
|---|
| function |
TaskCancelProvider
Un TaskCancelProvider válido es una función que devuelve un TaskCanceller.
| Type |
|---|
| function |
TaskProvider
Un TaskProvider válido es una función que devuelve una Task.
| Type |
|---|
| function |