-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add more info to Prerequisites for Libraries guide #3238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,19 @@ In general, this means you can use primitive types (strings, numbers, booleans), | |
|
|
||
| > See Appendix [I. Flow Type to Native Type Mapping](./new-architecture-appendix#i-flow-type-to-native-type-mapping). (TypeScript to Native Type Mapping will be added soon.) | ||
|
|
||
| ### Codegen helper types | ||
|
|
||
| You can use predefined types for your JavaScript spec, here is a list of them: | ||
|
|
||
| - `Double` | ||
| - `Float` | ||
| - `Int32` | ||
| - `WithDefault<Type, Value>` - Sets default value for type | ||
| - `BubblingEventHandler<T>` - For bubbling events (eg: `onChange`). | ||
| - `DirectEventHandler<T>` - For direct events (eg: `onClick`). | ||
|
|
||
| Later on those types are compiled to coresponding equivalents on target platforms. | ||
|
|
||
| ### Be Consistent Across Platforms and Eliminate Type Ambiguity | ||
|
|
||
| Before adopting the new architecture in your native module, you will need to ensure your methods are consistent across platforms. This is something you will realize as you set out to write the JavaScript spec for your native module - remember, that JavaScript spec defines what the methods will look like on all supported platforms. | ||
|
|
@@ -181,7 +194,7 @@ While we know that all deprecations are a hassle, this guide is intended to help | |
| 3. Migrating off `setNativeProps` | ||
| 4. Move the call to `requireNativeComponent` to a separate file | ||
| 5. Migrating off `dispatchViewManagerCommand` | ||
| 6. Using `codegenNativeComponent` | ||
| 6. Creating NativeCommands with `codegenNativeCommands` | ||
|
|
||
| ### Migrating `findNodeHandle` / getting a `HostComponent` | ||
|
|
||
|
|
@@ -452,9 +465,11 @@ return <RNTMyNativeViewNativeComponent />; | |
|
|
||
| ```js title="RNTMyNativeViewNativeComponent.js" | ||
| import { requireNativeComponent } from 'react-native'; | ||
|
|
||
| const RNTMyNativeViewNativeComponent = requireNativeComponent( | ||
| 'RNTMyNativeView' | ||
| ); | ||
|
|
||
| export default RNTMyNativeViewNativeComponent; | ||
| ``` | ||
|
|
||
|
|
@@ -469,6 +484,23 @@ const RCTWebViewNativeComponent: HostComponent<mixed> = | |
| requireNativeComponent < mixed > 'RNTMyNativeView'; | ||
| ``` | ||
|
|
||
| #### Later on you can replace `requireNativeComponent` | ||
|
|
||
| When you are ready to migrate to Fabric you can replace `requireNativeComponent` with `codegenNativeComponent`: | ||
|
|
||
| ```ts title="RNTMyNativeViewNativeComponent.js" | ||
| export default (codegenNativeComponent<NativeProps>( | ||
| 'RNTMyNativeView', | ||
| ): HostComponent<NativeProps>); | ||
| ``` | ||
|
|
||
| And update the main file: | ||
|
|
||
| ```ts title="RNTMyNativeNativeComponent.js" | ||
| export default require('./RNTMyNativeViewNativeComponent') | ||
| .default; | ||
|
Comment on lines
+500
to
+501
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think would be better not to mix commonjs & ES module
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so, the proper way will be ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cipolleschi maybe export { default } from './RNTMyNativeViewNativeComponent'; |
||
| ``` | ||
|
|
||
| ### Migrating off `dispatchViewManagerCommand` | ||
|
|
||
| Similar to one above, in an effort to avoid calling methods on the UIManager, all view manager methods are now called through an instance of `NativeCommands`. `codegenNativeCommands` is a new API to code-generate `NativeCommands` given an interface of your view manager’s commands. | ||
|
|
@@ -491,7 +523,7 @@ class MyComponent extends React.Component<Props> { | |
| } | ||
| ``` | ||
|
|
||
| **Creating the NativeCommands with `codegenNativeCommands`** | ||
| **Creating NativeCommands with `codegenNativeCommands`** | ||
|
|
||
| ```ts title="MyCustomMapNativeComponent.js" | ||
| import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands'; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these only Flow types? Do you know if these works in the same way for TypeScript or what are the equivalent TypeScript types?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These types for typescript are defined here: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/61466/files
So they should work the same