Skip to content

Commit 3125a70

Browse files
[RN][Codegen] Add docs for advanced iOS usage (facebook#4388)
* [RN][Codegen] Add docs for advanced iOS usage * Fix typo Co-authored-by: Oskar Kwaśniewski <[email protected]> --------- Co-authored-by: Oskar Kwaśniewski <[email protected]>
1 parent 99b60d0 commit 3125a70

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

docs/the-new-architecture/using-codegen.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ npx @react-native-community/cli@latest init SampleApp --version 0.76.0
3434
"jsSrcsDir": "<source_dir>",
3535
"android": {
3636
"javaPackageName": "<java.package.name>"
37+
},
38+
"ios": {
39+
"modulesConformingToProtocol": {
40+
"RCTImageURLLoader": [
41+
"<iOS-class-conforming-to-RCTImageURLLoader>",
42+
// example from react-native-camera-roll: https://github.com/react-native-cameraroll/react-native-cameraroll/blob/8a6d1b4279c76e5682a4b443e7a4e111e774ec0a/package.json#L118-L127
43+
// "RNCPHAssetLoader",
44+
],
45+
"RCTURLRequestHandler": [
46+
"<iOS-class-conforming-to-RCTURLRequestHandler>",
47+
// example from react-native-camera-roll: https://github.com/react-native-cameraroll/react-native-cameraroll/blob/8a6d1b4279c76e5682a4b443e7a4e111e774ec0a/package.json#L118-L127
48+
// "RNCPHAssetUploader",
49+
],
50+
"RCTImageDataDecoder": [
51+
"<iOS-class-conforming-to-RCTImageDataDecoder>",
52+
// we don't have a good example for this, but it works in the same way. Pass the name of the class that implements the RCTImageDataDecoder. It must be a Native Module.
53+
]
54+
},
55+
"componentProvider": {
56+
"<componentName>": "<iOS-class-implementing-the-component>"
57+
},
3758
}
3859
},
3960
```
@@ -46,7 +67,13 @@ You can add this snippet to your app and customize the various fields:
4667
- `components:` use this value if you only need to generate code for Native Fabric Components.
4768
- `all`: use this value if you have a mixture of components and modules.
4869
- `jsSrcsDir`: this is the root folder where all your specs live.
49-
- `android.javaPackageName`: this is an android specific setting to let **Codegen** generate the files in a custom package.
70+
- `android.javaPackageName`: this is an Android specific setting to let **Codegen** generate the files in a custom package.
71+
- `ios`: the `ios` field is an object that can be used by app developers and library maintainers to provide some advanced functionalities. All the following fields are **optional**.
72+
- `ios.modulesConformingToProtocol`: React Native offers some protocols that native modules can implement to customize some behaviors. These fields allow you to define the list of module that conforms to those protocols. These modules will be injected in the React Native runtime when the app starts.
73+
- `ios.modulesConformingToProtocol.RCTImageURLLoader`: list of iOS native module that implements the [`RCTImageURLLoader` protocol](https://github.com/facebook/react-native/blob/00d5caee9921b6c10be8f7d5b3903c6afe8dbefa/packages/react-native/Libraries/Image/RCTImageURLLoader.h#L26-L81). You need to pass the class names of iOS classes that implements the `RCTImageURLLoader`. They must be Native Modules.
74+
- `ios.modulesConformingToProtocol.RCTURLRequestHandler`: list of iOS native module that implements the [`RCTURLRequestHandler` protocol](https://github.com/facebook/react-native/blob/00d5caee9921b6c10be8f7d5b3903c6afe8dbefa/packages/react-native/React/Base/RCTURLRequestHandler.h#L11-L52). You need to pass the class names of iOS classes that implements the `RCTURLRequestHandler`. They must be Native Modules.
75+
- `ios.modulesConformingToProtocol.RCTImageDataDecoder`: list of iOS native module that implements the [`RCTImageDataDecoder` protocol](https://github.com/facebook/react-native/blob/00d5caee9921b6c10be8f7d5b3903c6afe8dbefa/packages/react-native/Libraries/Image/RCTImageDataDecoder.h#L15-L53). You need to pass the class names of iOS classes that implements the `RCTImageDataDecoder`. They must be Native Modules.
76+
- `ios.componentProvider`: this field is a map used to generate the association between a custom JS React component and the native class that implements it. The key of the map is the JS name of the component (for example `TextInput`), and the value is the iOS class that implements the component (for example `RCTTextInput`).
5077

5178
When **Codegen** runs, it searches among all the dependencies of the app, looking for JS files that respects some specific conventions, and it generates the required code:
5279

website/versioned_docs/version-0.76/the-new-architecture/using-codegen.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ npx @react-native-community/cli@latest init SampleApp --version 0.76.0
3434
"jsSrcsDir": "<source_dir>",
3535
"android": {
3636
"javaPackageName": "<java.package.name>"
37+
},
38+
"ios": {
39+
"modulesConformingToProtocol": {
40+
"RCTImageURLLoader": [
41+
"<iOS-class-conforming-to-RCTImageURLLoader>",
42+
// example from react-native-camera-roll: https://github.com/react-native-cameraroll/react-native-cameraroll/blob/8a6d1b4279c76e5682a4b443e7a4e111e774ec0a/package.json#L118-L127
43+
// "RNCPHAssetLoader",
44+
],
45+
"RCTURLRequestHandler": [
46+
"<iOS-class-conforming-to-RCTURLRequestHandler>",
47+
// example from react-native-camera-roll: https://github.com/react-native-cameraroll/react-native-cameraroll/blob/8a6d1b4279c76e5682a4b443e7a4e111e774ec0a/package.json#L118-L127
48+
// "RNCPHAssetUploader",
49+
],
50+
"RCTImageDataDecoder": [
51+
"<iOS-class-conforming-to-RCTImageDataDecoder>",
52+
// we don't have a good example for this, but it works in the same way. Pass the name of the class that implements the RCTImageDataDecoder. It must be a Native Modules.
53+
]
54+
}
3755
}
3856
},
3957
```
@@ -46,7 +64,12 @@ You can add this snippet to your app and customize the various fields:
4664
- `components:` use this value if you only need to generate code for Native Fabric Components.
4765
- `all`: use this value if you have a mixture of components and modules.
4866
- `jsSrcsDir`: this is the root folder where all your specs live.
49-
- `android.javaPackageName`: this is an android specific setting to let **Codegen** generate the files in a custom package.
67+
- `android.javaPackageName`: this is an Android specific setting to let **Codegen** generate the files in a custom package.
68+
- `ios`: the `ios` field is an object that can be used by app developers and library maintainers to provide some advanced functionalities. All the following fields are **optional**.
69+
- `ios.modulesConformingToProtocol`: React Native offers some protocols that native modules can implement to customize some behaviors. These fields allow you to define the list of modules that conform to those protocols. These modules will be injected in the React Native runtime when the app starts.
70+
- `ios.modulesConformingToProtocol.RCTImageURLLoader`: list of iOS native module that implements the [`RCTImageURLLoader` protocol](https://github.com/facebook/react-native/blob/00d5caee9921b6c10be8f7d5b3903c6afe8dbefa/packages/react-native/Libraries/Image/RCTImageURLLoader.h#L26-L81). You need to pass the class names of iOS classes that implements the `RCTImageURLLoader`. They must be Native Modules.
71+
- `ios.modulesConformingToProtocol.RCTURLRequestHandler`: list of iOS native module that implements the [`RCTURLRequestHandler` protocol](https://github.com/facebook/react-native/blob/00d5caee9921b6c10be8f7d5b3903c6afe8dbefa/packages/react-native/React/Base/RCTURLRequestHandler.h#L11-L52). You need to pass the class names of iOS classes that implements the `RCTURLRequestHandler`. They must be Native Modules.
72+
- `ios.modulesConformingToProtocol.RCTImageDataDecoder`: list of iOS native module that implements the [`RCTImageDataDecoder` protocol](https://github.com/facebook/react-native/blob/00d5caee9921b6c10be8f7d5b3903c6afe8dbefa/packages/react-native/Libraries/Image/RCTImageDataDecoder.h#L15-L53). You need to pass the class names of iOS classes that implements the `RCTImageDataDecoder`. They must be Native Modules.
5073

5174
When **Codegen** runs, it searches among all the dependencies of the app, looking for JS files that respects some specific conventions, and it generates the required code:
5275

0 commit comments

Comments
 (0)