Skip to content

Commit d1ab100

Browse files
authored
Add more info to Prerequisites for Libraries guide (#3238)
* Add spaces in the example * Add section about codegen types * Correct section title * Add information about requireNativeComponent
1 parent ac29dab commit d1ab100

File tree

3 files changed

+68
-6
lines changed

3 files changed

+68
-6
lines changed

docs/new-architecture-library-intro.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ In general, this means you can use primitive types (strings, numbers, booleans),
130130
131131
> 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.)
132132
133+
### Codegen helper types
134+
135+
You can use predefined types for your JavaScript spec, here is a list of them:
136+
137+
- `Double`
138+
- `Float`
139+
- `Int32`
140+
- `WithDefault<Type, Value>` - Sets default value for type
141+
- `BubblingEventHandler<T>` - For bubbling events (eg: `onChange`).
142+
- `DirectEventHandler<T>` - For direct events (eg: `onClick`).
143+
144+
Later on those types are compiled to coresponding equivalents on target platforms.
145+
133146
### Be Consistent Across Platforms and Eliminate Type Ambiguity
134147
135148
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
181194
3. Migrating off `setNativeProps`
182195
4. Move the call to `requireNativeComponent` to a separate file
183196
5. Migrating off `dispatchViewManagerCommand`
184-
6. Using `codegenNativeComponent`
197+
6. Creating NativeCommands with `codegenNativeCommands`
185198
186199
### Migrating `findNodeHandle` / getting a `HostComponent`
187200
@@ -452,9 +465,11 @@ return <RNTMyNativeViewNativeComponent />;
452465
453466
```js title="RNTMyNativeViewNativeComponent.js"
454467
import { requireNativeComponent } from 'react-native';
468+
455469
const RNTMyNativeViewNativeComponent = requireNativeComponent(
456470
'RNTMyNativeView'
457471
);
472+
458473
export default RNTMyNativeViewNativeComponent;
459474
```
460475
@@ -469,6 +484,23 @@ const RCTWebViewNativeComponent: HostComponent<mixed> =
469484
requireNativeComponent < mixed > 'RNTMyNativeView';
470485
```
471486
487+
#### Later on you can replace `requireNativeComponent`
488+
489+
When you are ready to migrate to Fabric you can replace `requireNativeComponent` with `codegenNativeComponent`:
490+
491+
```ts title="RNTMyNativeViewNativeComponent.js"
492+
export default (codegenNativeComponent<NativeProps>(
493+
'RNTMyNativeView',
494+
): HostComponent<NativeProps>);
495+
```
496+
497+
And update the main file:
498+
499+
```ts title="RNTMyNativeNativeComponent.js"
500+
export default require('./RNTMyNativeViewNativeComponent')
501+
.default;
502+
```
503+
472504
### Migrating off `dispatchViewManagerCommand`
473505
474506
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> {
491523
}
492524
```
493525

494-
**Creating the NativeCommands with `codegenNativeCommands`**
526+
**Creating NativeCommands with `codegenNativeCommands`**
495527

496528
```ts title="MyCustomMapNativeComponent.js"
497529
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';

website/versioned_docs/version-0.68/new-architecture-library-intro.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ In general, this means you can use primitive types (strings, numbers, booleans),
8181
8282
> See Appendix [I. Flow Type to Native Type Mapping](#i-flow-type-to-native-type-mapping).
8383
84+
### Codegen helper types
85+
86+
You can use predefined types for your JavaScript spec, here is a list of them:
87+
88+
- `Double`
89+
- `Float`
90+
- `Int32`
91+
- `WithDefault<Type, Value>` - Sets default value for type
92+
- `BubblingEventHandler<T>` - For bubbling events (eg: `onChange`).
93+
- `DirectEventHandler<T>` - For direct events (eg: `onClick`).
94+
95+
Later on those types are compiled to coresponding equivalents on target platforms.
96+
8497
### Be Consistent Across Platforms and Eliminate Type Ambiguity
8598
8699
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.
@@ -132,7 +145,7 @@ While we know that all deprecations are a hassle, this guide is intended to help
132145
3. Migrating off `setNativeProps`
133146
4. Move the call to `requireNativeComponent` to a separate file
134147
5. Migrating off `dispatchViewManagerCommand`
135-
6. Using `codegenNativeComponent`
148+
6. Creating NativeCommands with `codegenNativeCommands`
136149
137150
### Migrating `findNodeHandle` / getting a `HostComponent`
138151
@@ -403,9 +416,11 @@ return <RNTMyNativeViewNativeComponent />;
403416
404417
```js title="RNTMyNativeViewNativeComponent.js"
405418
import { requireNativeComponent } from 'react-native';
419+
406420
const RNTMyNativeViewNativeComponent = requireNativeComponent(
407421
'RNTMyNativeView'
408422
);
423+
409424
export default RNTMyNativeViewNativeComponent;
410425
```
411426
@@ -442,7 +457,7 @@ class MyComponent extends React.Component<Props> {
442457
}
443458
```
444459

445-
**Creating the NativeCommands with `codegenNativeCommands`**
460+
**Creating NativeCommands with `codegenNativeCommands`**
446461

447462
```ts title="MyCustomMapNativeComponent.js"
448463
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';

website/versioned_docs/version-0.69/new-architecture-library-intro.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ In general, this means you can use primitive types (strings, numbers, booleans),
130130
131131
> 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.)
132132
133+
### Codegen helper types
134+
135+
You can use predefined types for your JavaScript spec, here is a list of them:
136+
137+
- `Double`
138+
- `Float`
139+
- `Int32`
140+
- `WithDefault<Type, Value>` - Sets default value for type
141+
- `BubblingEventHandler<T>` - For bubbling events (eg: `onChange`).
142+
- `DirectEventHandler<T>` - For direct events (eg: `onClick`).
143+
144+
Later on those types are compiled to coresponding equivalents on target platforms.
145+
133146
### Be Consistent Across Platforms and Eliminate Type Ambiguity
134147
135148
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
181194
3. Migrating off `setNativeProps`
182195
4. Move the call to `requireNativeComponent` to a separate file
183196
5. Migrating off `dispatchViewManagerCommand`
184-
6. Using `codegenNativeComponent`
197+
6. Creating NativeCommands with `codegenNativeCommands`
185198
186199
### Migrating `findNodeHandle` / getting a `HostComponent`
187200
@@ -452,9 +465,11 @@ return <RNTMyNativeViewNativeComponent />;
452465
453466
```js title="RNTMyNativeViewNativeComponent.js"
454467
import { requireNativeComponent } from 'react-native';
468+
455469
const RNTMyNativeViewNativeComponent = requireNativeComponent(
456470
'RNTMyNativeView'
457471
);
472+
458473
export default RNTMyNativeViewNativeComponent;
459474
```
460475
@@ -491,7 +506,7 @@ class MyComponent extends React.Component<Props> {
491506
}
492507
```
493508

494-
**Creating the NativeCommands with `codegenNativeCommands`**
509+
**Creating NativeCommands with `codegenNativeCommands`**
495510

496511
```ts title="MyCustomMapNativeComponent.js"
497512
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';

0 commit comments

Comments
 (0)