Saltar al contenido principal

AppRegistry

Traducción Beta No Oficial

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.

tsx
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()

tsx
static getAppKeys(): string[];

Devuelve un arreglo de cadenas.


getRegistry()

tsx
static getRegistry(): {sections: string[]; runnables: Runnable[]};

Devuelve un objeto Registry.


getRunnable()

tsx
static getRunnable(appKey: string): : Runnable | undefined;

Devuelve un objeto Runnable.

Parámetros:

NameType
appKey
Required
string

getSectionKeys()

tsx
static getSectionKeys(): string[];

Devuelve un arreglo de cadenas.


getSections()

tsx
static getSections(): Record<string, Runnable>;

Devuelve un objeto Runnables.


registerCancellableHeadlessTask()

tsx
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:

NameTypeDescription
taskKey
Required
stringThe native id for this task instance that was used when startHeadlessTask was called.
taskProvider
Required
TaskProviderA 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
TaskCancelProvidera 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()

tsx
static registerComponent(
appKey: string,
getComponentFunc: ComponentProvider,
section?: boolean,
): string;

Parámetros:

NameType
appKey
Required
string
componentProvider
Required
ComponentProvider
sectionboolean

registerConfig()

tsx
static registerConfig(config: AppConfig[]);

Parámetros:

NameType
config
Required
AppConfig[]

registerHeadlessTask()

tsx
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:

NameTypeDescription
taskKey
Required
stringThe native id for this task instance that was used when startHeadlessTask was called.
taskProvider
Required
TaskProviderA 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()

tsx
static registerRunnable(appKey: string, func: Runnable): string;

Parámetros:

NameType
appKey
Required
string
run
Required
function

registerSection()

tsx
static registerSection(
appKey: string,
component: ComponentProvider,
);

Parámetros:

NameType
appKey
Required
string
component
Required
ComponentProvider

runApplication()

tsx
static runApplication(appKey: string, appParameters: any): void;

Carga el paquete JavaScript y ejecuta la aplicación.

Parámetros:

NameType
appKey
Required
string
appParameters
Required
any

setComponentProviderInstrumentationHook()

tsx
static setComponentProviderInstrumentationHook(
hook: ComponentProviderInstrumentationHook,
);

Parámetros:

NameType
hook
Required
function

Una función hook válida acepta los siguientes argumentos:

NameType
component
Required
ComponentProvider
scopedPerformanceLogger
Required
IPerformanceLogger

La función también debe devolver un componente de React.


setWrapperComponentProvider()

tsx
static setWrapperComponentProvider(
provider: WrapperComponentProvider,
);

Parámetros:

NameType
provider
Required
ComponentProvider

startHeadlessTask()

tsx
static startHeadlessTask(
taskId: number,
taskKey: string,
data: any,
);

Solo se llama desde código nativo. Inicia una tarea sin interfaz.

Parámetros:

NameTypeDescription
taskId
Required
numberThe native id for this task instance to keep track of its execution.
taskKey
Required
stringThe key for the task to start.
data
Required
anyThe data to pass to the task.

unmountApplicationComponentAtRootTag()

tsx
static unmountApplicationComponentAtRootTag(rootTag: number);

Detiene una aplicación cuando una vista debe destruirse.

Parámetros:

NameType
rootTag
Required
number

Definiciones de tipos

AppConfig

Configuración de aplicación para el método registerConfig.

Type
object

Propiedades:

NameType
appKey
Required
string
componentComponentProvider
runfunction
sectionboolean
nota

Se espera que cada configuración establezca una función component o run.

Registry

Type
object

Propiedades:

NameType
runnablesarray of Runnables
sectionsarray of strings

Runnable

Type
object

Propiedades:

NameType
componentComponentProvider
runfunction

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