Skip to content

Commit 370defe

Browse files
Apply suggestions from code review
Co-authored-by: Riccardo Cipolleschi <[email protected]>
1 parent 22edd2c commit 370defe

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

proposals/0000-swift-turbo-modules.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ This RFC aims to allow developers to write Turbo Modules using Swift. This will
1717
The primary motivations for introducing Swift Turbo Modules are:
1818
- Enhance developer experience for iOS developers working with React Native
1919
- Allow the use of more modern language
20-
- Make barrier to entry lower
20+
- Lower the entry barrier to write a native turbo module
2121

2222

2323
## Detailed design
2424

25-
One of the problem why we can't adopt Swift in TurboModules is the contamination of C++ ending up in user-space.
25+
One of the reasons why we can't adopt Swift in TurboModules is the contamination of C++ types ending up in user-space.
2626

2727
### Current Situation
2828
The interfaces we generate for an Objective-C turbomodules have this shape:
@@ -31,20 +31,20 @@ The interfaces we generate for an Objective-C turbomodules have this shape:
3131
@end
3232
```
3333

34-
Where the `RCTTurboModule` protocol requires the conforming object to implement a method with this signature:
34+
The `RCTTurboModule` protocol requires the conforming object to implement a method with this signature:
3535
```objc
3636
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
3737
(const facebook::react::ObjCTurboModule::InitParams &)params;
3838
```
3939

40-
As you can see, the signature of this method contains two types from C++:
40+
The signature of this method contains two types from C++:
4141

4242
* `std::shared_ptr<facebook::react::TurboModule>`
4343
* `facebook::react::ObjCTurboModule::InitParams`
4444

4545
### Solution
4646

47-
The idea is to wrap the `getTurboModule` invocation in a `TurboModuleWrapper` object.
47+
The idea is to wrap the `getTurboModule` invocation in a `ModuleFactory` object.
4848

4949
The `TurboModuleWrapper` object is a base class that is supposed to be extended by a companion object for TurboModules. The base class has this interface:
5050
```objc
@@ -65,7 +65,7 @@ When it comes to the implementation, the user-defined TurboModule won't have to
6565
6666
```objc
6767
@implementation MyTurboModule
68-
- (TurboModuleWrapper *)getWrapper
68+
- (TurboModuleWrapper *)moduleFactory
6969
{
7070
return [[MyTurboModuleWrapper alloc] init];
7171
}
@@ -121,9 +121,9 @@ Finally, we will have to update the `RCTTurboModuleManager` to take this new obj
121121
Additionally we need to make sure that `React_Codegen` module is compatible with importing to Swift. I did a small test and adding few ifdefs to React_Codegen headers allows us to use Swift.
122122

123123
```swift
124-
import protocol React_Codegen.NativeSwiftTestLibrarySpec
125-
import protocol React_Codegen.TurboModuleWrapper
126-
import class React_Codegen.NativeSwiftTestLibraryWrapper
124+
import protocol ReactCodegen.NativeSwiftTestLibrarySpec
125+
import protocol ReactCodegen.TurboModuleWrapper
126+
import class ReactCodegen.NativeSwiftTestLibraryWrapper
127127

128128
@objc public class SwiftTestLibrary: NSObject, NativeSwiftTestLibrarySpec {
129129
@objc public func multiply(_ a: Double, b: Double) -> NSNumber! {

0 commit comments

Comments
 (0)