附录
¥Appendix
I. 术语
¥I. Terminology
-
Spec - 描述 Turbo Native Module 或 Fabric Native 组件 API 的 TypeScript 或 Flow 代码。由 Codegen 用于生成样板代码。
¥Spec - TypeScript or Flow code that describes the API for a Turbo Native Module or Fabric Native component. Used by Codegen to generate boilerplate code.
-
原生模块 - 没有用户界面 (UI) 的原生库。示例包括持久存储、通知、网络事件。这些可以作为函数和对象供你的 JavaScript 应用代码访问。
¥Native Modules - Native libraries that have no User Interface (UI) for the user. Examples would be persistent storage, notifications, network events. These are accessible to your JavaScript application code as functions and objects.
-
原生组件 - 通过 React Components 可供你的应用 JavaScript 代码使用的原生平台视图。
¥Native Component - Native platform views that are available to your application JavaScript code through React Components.
-
旧版原生组件 - 在旧的 React Native 架构上运行的组件。
¥Legacy Native Components - Components which are running on the old React Native architecture.
-
旧版原生模块 - 在旧的 React Native 架构上运行的模块。
¥Legacy Native Modules - Modules which are running on the old React Native architecture.
II.Codegen 类型
¥II. Codegen Typings
你可以使用下表作为参考,了解支持哪些类型以及它们在每个平台上映射到什么:
¥You may use the following table as a reference for which types are supported and what they map to in each platform:
Flow | TypeScript | Flow Nullable Support | TypeScript Nullable Support | Android (Java) | iOS (ObjC) |
---|---|---|---|---|---|
string | string | ?string | string | null | string | NSString |
boolean | boolean | ?boolean | boolean | null | Boolean | NSNumber |
Object Literal{| foo: string, ...|} | { foo: string, ...} as const | ?{| foo: string, ...|} | ?{ foo: string, ...} as const | - | - |
Object [1] | Object [1] | ?Object | Object | null | ReadableMap | @ (untyped dictionary) |
Array<T> | Array<T> | ?Array<T> | Array<T> | null | ReadableArray | NSArray (or RCTConvertVecToArray when used inside objects) |
Function | Function | ?Function | Function | null | - | - |
Promise<T> | Promise<T> | ?Promise<T> | Promise<T> | null | com.facebook.react.bridge.Promise | RCTPromiseResolve and RCTPromiseRejectBlock |
Type Unions'SUCCESS'|'FAIL' | Type Unions'SUCCESS'|'FAIL' | Only as callbacks | - | - | |
Callbacks() => | Callbacks() => | Yes | com.facebook.react.bridge.Callback | RCTResponseSenderBlock | |
number | number | No | double | NSNumber |
注意事项:
¥Notes:
[1] 我们强烈建议使用对象字面量而不是对象。
¥[1] We strongly recommend using Object literals instead of Objects.
你可能还会发现参考 React Native 中核心模块的 JavaScript 规范很有用。这些位于 React Native 存储库中的 Libraries/
目录中。
¥You may also find it useful to refer to the JavaScript specifications for the core modules in React Native. These are located inside the Libraries/
directory in the React Native repository.