AppRegistry
AppRegistry
是所有 React Native 应用的 JS 入口。应用的根组件应当通过AppRegistry.registerComponent
方法注册自己,然后原生系统才可以加载应用的代码包并且在启动完成之后通过调用AppRegistry.runApplication
来真正运行应用。
import { Text, AppRegistry } from 'react-native';
const App = (props) => (
<View>
<Text>App1</Text>
</View>
);
AppRegistry.registerComponent('Appname', () => App);
要“结束”一个应用并销毁视图的话,请调用AppRegistry.unmountApplicationComponentAtRootTag
方法,参数为在runApplication
中使用的标签名。它们必须严格匹配。
AppRegistry
应当在require
序列中尽可能早的被 require 到,以确保 JS 运行环境在其它模块之前被准备好。
文档
方法
cancelHeadlessTask()
static cancelHeadlessTask(taskId, taskKey)
Only called from native code. Cancels a headless task. @param taskId the native id for this task instance that was used when startHeadlessTask was called @param taskKey the key for the task that was used when startHeadlessTask was called
参数:
名称 | 类型 | 说明 |
---|---|---|
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)
参数:
名称 | 类型 |
---|---|
enabled Required | boolean |
getAppKeys()
static getAppKeys()
Returns an Array of AppKeys
getRegistry()
static getRegistry()
Returns a Registry object.
getRunnable()
static getRunnable(appKey)
Returns a Runnable object.
参数:
名称 | 类型 |
---|---|
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.
参数:
名称 | 类型 | 说明 |
---|---|---|
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. |