AppRegistry
AppRegistry
is the JS entry point to running all React Native apps. App root components should register themselves with AppRegistry.registerComponent
, then the native system can load the bundle for the app and then actually run the app when it's ready by invoking AppRegistry.runApplication
.
import {Text, AppRegistry} from 'react-native';
const App = props => (
<View>
<Text>App1</Text>
</View>
);
AppRegistry.registerComponent('Appname', () => App);
To "stop" an application when a view should be destroyed, call AppRegistry.unmountApplicationComponentAtRootTag
with the tag that was passed into runApplication
. These should always be used as a pair.
AppRegistry
should be required early in the require
sequence to make sure the JS execution environment is setup before other modules are required.
Reference
Methodsβ
cancelHeadlessTask()
β
static cancelHeadlessTask(taskId, taskKey)
Only called from native code. Cancels a headless task.
Parameters:
Name | Type | Description |
---|---|---|
taskId Required | number | The native id for this task instance that was used when startHeadlessTask was called. |
taskKey Required | string | The key for the task that was used when startHeadlessTask was called. |
enableArchitectureIndicator()
β
static enableArchitectureIndicator(enabled)
Parameters:
Name | Type |
---|---|
enabled Required | boolean |
getAppKeys()
β
static getAppKeys()
Returns an array of strings.
getRegistry()
β
static getRegistry()
Returns a Registry object.
getRunnable()
β
static getRunnable(appKey)
Returns a Runnable object.
Parameters:
Name | Type |
---|---|
appKey Required | string |
getSectionKeys()
β
static getSectionKeys()
Returns an array of strings.
getSections()
β
static getSections()
Returns a Runnables object.
registerCancellableHeadlessTask()
β
static registerCancellableHeadlessTask(taskKey, taskProvider, taskCancelProvider)
Register a headless task which can be cancelled. A headless task is a bit of code that runs without a UI.
Parameters:
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, componentProvider, section?)
Parameters:
Name | Type |
---|---|
appKey Required | string |
componentProvider Required | ComponentProvider |
section | boolean |
registerConfig()
β
static registerConfig(config)
Parameters:
Name | Type |
---|---|
config Required | AppConfig |
registerHeadlessTask()
β
static registerHeadlessTask(taskKey, taskProvider)
Register a headless task. A headless task is a bit of code that runs without a UI.
This is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.
Parameters:
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, run)
Parameters:
Name | Type |
---|---|
appKey Required | string |
run Required | function |
registerSection()
β
static registerSection(appKey, component)
Parameters:
Name | Type |
---|---|
appKey Required | string |
component Required | ComponentProvider |
runApplication()
β
static runApplication(appKey, appParameters)
Loads the JavaScript bundle and runs the app.
Parameters:
Name | Type |
---|---|
appKey Required | string |
appParameters Required | any |
setComponentProviderInstrumentationHook()
β
static setComponentProviderInstrumentationHook(hook)
Parameters:
Name | Type |
---|---|
hook Required | function |
A valid hook
function accepts the following as arguments:
Name | Type |
---|---|
component Required | ComponentProvider |
scopedPerformanceLogger Required | IPerformanceLogger |
The function must also return a React Component.
setWrapperComponentProvider()
β
static setWrapperComponentProvider(provider)
Parameters:
Name | Type |
---|---|
provider Required | ComponentProvider |
startHeadlessTask()
β
static startHeadlessTask(taskId, taskKey, data)
Only called from native code. Starts a headless task.
Parameters:
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)
Stops an application when a view should be destroyed.
Parameters:
Name | Type |
---|---|
rootTag Required | number |
Type Definitionsβ
AppConfigβ
Application configuration for the registerConfig
method.
Type |
---|
object |
Properties:
Name | Type |
---|---|
appKey Required | string |
component | ComponentProvider |
run | function |
section | boolean |
Note: Every config is expected to set either
component
orrun
function.
Registryβ
Type |
---|
object |
Properties:
Name | Type |
---|---|
runnables | array of Runnables |
sections | array of strings |
Runnableβ
Type |
---|
object |
Properties:
Name | Type |
---|---|
component | ComponentProvider |
run | function |
Runnablesβ
An object with key of appKey
and value of type of Runnable
.
Type |
---|
object |
Taskβ
A Task
is a function that accepts any data as argument and returns a Promise that resolves to undefined
.
Type |
---|
function |
TaskCancellerβ
A TaskCanceller
is a function that accepts no argument and returns void.
Type |
---|
function |
TaskCancelProviderβ
A valid TaskCancelProvider
is a function that returns a TaskCanceller
.
Type |
---|
function |
TaskProviderβ
A valid TaskProvider
is a function that returns a Task
.
Type |
---|
function |