Przejdź do treści głównej
Wersja: 0.78

AppRegistry

Nieoficjalne Tłumaczenie Beta

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.

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

tsx
static getAppKeys(): string[];

Zwraca tablicę ciągów znaków.


getRegistry()

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

Zwraca obiekt Registry.


getRunnable()

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

Zwraca obiekt Runnable.

Parametry:

NameType
appKey
Required
string

getSectionKeys()

tsx
static getSectionKeys(): string[];

Zwraca tablicę ciągów znaków.


getSections()

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

Zwraca obiekt Runnables.


registerCancellableHeadlessTask()

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

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;

Parametry:

NameType
appKey
Required
string
componentProvider
Required
ComponentProvider
sectionboolean

registerConfig()

tsx
static registerConfig(config: AppConfig[]);

Parametry:

NameType
config
Required
AppConfig[]

registerHeadlessTask()

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

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;

Parametry:

NameType
appKey
Required
string
run
Required
function

registerSection()

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

Parametry:

NameType
appKey
Required
string
component
Required
ComponentProvider

runApplication()

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

Ładuje paczkę JavaScript i uruchamia aplikację.

Parametry:

NameType
appKey
Required
string
appParameters
Required
any

setComponentProviderInstrumentationHook()

tsx
static setComponentProviderInstrumentationHook(
hook: ComponentProviderInstrumentationHook,
);

Parametry:

NameType
hook
Required
function

Poprawna funkcja hook akceptuje następujące argumenty:

NameType
component
Required
ComponentProvider
scopedPerformanceLogger
Required
IPerformanceLogger

Funkcja musi również zwracać komponent React.


setWrapperComponentProvider()

tsx
static setWrapperComponentProvider(
provider: WrapperComponentProvider,
);

Parametry:

NameType
provider
Required
ComponentProvider

startHeadlessTask()

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

Wywoływane wyłącznie z kodu natywnego. Uruchamia zadanie bez interfejsu.

Parametry:

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);

Zatrzymuje aplikację, gdy widok powinien zostać zniszczony.

Parametry:

NameType
rootTag
Required
number

Definicje Typów

AppConfig

Konfiguracja aplikacji dla metody registerConfig.

Type
object

Właściwości:

NameType
appKey
Required
string
componentComponentProvider
runfunction
sectionboolean

Uwaga: Każda konfiguracja powinna zawierać funkcję component lub run.

Registry

Type
object

Właściwości:

NameType
runnablesarray of Runnables
sectionsarray of strings

Runnable

Type
object

Właściwości:

NameType
componentComponentProvider
runfunction

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