AppRegistry
Ta strona została przetłumaczona przez PageTurner AI (beta). Nie jest oficjalnie zatwierdzona przez projekt. Znalazłeś błąd? Zgłoś problem →
AppRegistry to punkt wejścia JavaScript do uruchamiania wszystkich aplikacji React Native. Główne komponenty aplikacji powinny rejestrować się za pomocą AppRegistry.registerComponent, wtedy system natywny może załadować paczkę aplikacji i faktycznie uruchomić aplikację, gdy będzie gotowa, wywołując AppRegistry.runApplication.
import {Text, AppRegistry} from 'react-native';
const App = () => (
<View>
<Text>App1</Text>
</View>
);
AppRegistry.registerComponent('Appname', () => App);
Aby "zatrzymać" aplikację, gdy widok powinien zostać zniszczony, wywołaj AppRegistry.unmountApplicationComponentAtRootTag z tagiem przekazanym do runApplication. Te funkcje powinny być zawsze używane jako para.
AppRegistry powinien być załadowany wcześnie w sekwencji require, aby zapewnić, że środowisko wykonawcze JavaScript jest skonfigurowane przed załadowaniem innych modułów.
Dokumentacja
Metody
getAppKeys()
static getAppKeys(): string[];
Zwraca tablicę ciągów znaków.
getRegistry()
static getRegistry(): {sections: string[]; runnables: Runnable[]};
Zwraca obiekt Registry.
getRunnable()
static getRunnable(appKey: string): : Runnable | undefined;
Zwraca obiekt Runnable.
Parametry:
| Name | Type |
|---|---|
| appKey Required | string |
getSectionKeys()
static getSectionKeys(): string[];
Zwraca tablicę ciągów znaków.
getSections()
static getSections(): Record<string, Runnable>;
Zwraca obiekt Runnables.
registerCancellableHeadlessTask()
static registerCancellableHeadlessTask(
taskKey: string,
taskProvider: TaskProvider,
taskCancelProvider: TaskCancelProvider,
);
Rejestruje anulowalne zadanie bez interfejsu (headless task). Zadanie bez interfejsu to fragment kodu działający bez UI.
Parametry:
| 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;
Parametry:
| Name | Type |
|---|---|
| appKey Required | string |
| componentProvider Required | ComponentProvider |
| section | boolean |
registerConfig()
static registerConfig(config: AppConfig[]);
Parametry:
| Name | Type |
|---|---|
| config Required | AppConfig[] |
registerHeadlessTask()
static registerHeadlessTask(
taskKey: string,
taskProvider: TaskProvider,
);
Rejestruje zadanie bez interfejsu (headless task). Zadanie bez interfejsu to fragment kodu działający bez UI.
Jest to sposób na uruchamianie zadań w JavaScript, gdy aplikacja działa w tle. Może być używane na przykład do synchronizacji świeżych danych, obsługi powiadomień push lub odtwarzania muzyki.
Parametry:
| 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;
Parametry:
| Name | Type |
|---|---|
| appKey Required | string |
| run Required | function |
registerSection()
static registerSection(
appKey: string,
component: ComponentProvider,
);
Parametry:
| Name | Type |
|---|---|
| appKey Required | string |
| component Required | ComponentProvider |
runApplication()
static runApplication(appKey: string, appParameters: any): void;
Ładuje paczkę JavaScript i uruchamia aplikację.
Parametry:
| Name | Type |
|---|---|
| appKey Required | string |
| appParameters Required | any |
setComponentProviderInstrumentationHook()
static setComponentProviderInstrumentationHook(
hook: ComponentProviderInstrumentationHook,
);
Parametry:
| Name | Type |
|---|---|
| hook Required | function |
Poprawna funkcja hook akceptuje następujące argumenty:
| Name | Type |
|---|---|
| component Required | ComponentProvider |
| scopedPerformanceLogger Required | IPerformanceLogger |
Funkcja musi również zwracać komponent React.
setWrapperComponentProvider()
static setWrapperComponentProvider(
provider: WrapperComponentProvider,
);
Parametry:
| Name | Type |
|---|---|
| provider Required | ComponentProvider |
startHeadlessTask()
static startHeadlessTask(
taskId: number,
taskKey: string,
data: any,
);
Wywoływane wyłącznie z kodu natywnego. Uruchamia zadanie bez interfejsu.
Parametry:
| 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);
Zatrzymuje aplikację, gdy widok powinien zostać zniszczony.
Parametry:
| Name | Type |
|---|---|
| rootTag Required | number |
Definicje Typów
AppConfig
Konfiguracja aplikacji dla metody registerConfig.
| Type |
|---|
| object |
Właściwości:
| Name | Type |
|---|---|
| appKey Required | string |
| component | ComponentProvider |
| run | function |
| section | boolean |
Uwaga: Każda konfiguracja powinna zawierać funkcję
componentlubrun.
Registry
| Type |
|---|
| object |
Właściwości:
| Name | Type |
|---|---|
| runnables | array of Runnables |
| sections | array of strings |
Runnable
| Type |
|---|
| object |
Właściwości:
| Name | Type |
|---|---|
| component | ComponentProvider |
| run | function |
Runnables
Obiekt z kluczem appKey i wartością typu Runnable.
| Type |
|---|
| object |
Task
Task to funkcja akceptująca dowolne dane jako argument i zwracająca Promise, który rozwiązuje się do undefined.
| Type |
|---|
| function |
TaskCanceller
TaskCanceller to funkcja, która nie przyjmuje argumentów i zwraca void.
| Type |
|---|
| function |
TaskCancelProvider
Prawidłowy TaskCancelProvider to funkcja zwracająca TaskCanceller.
| Type |
|---|
| function |
TaskProvider
Prawidłowy TaskProvider to funkcja zwracająca Task.
| Type |
|---|
| function |