-
Notifications
You must be signed in to change notification settings - Fork 138
Description
Introduction
#40 gives a primer the high level overview and architecture of Turbo Modules, but there doesn't seem to be a single place that discusses each of the developer scenarios around Turbo Modules. The purpose of this issue is to outline a set of scenarios and articulate how Turbo Modules fits in with each.
I've included answers (often partial) to the best of my knowledge, but I'm happy to be told I'm wrong or to receive more up-to-date information.
The Core of It
Scenario 1: Update existing module
The author of an existing native module react-native-foo has heard about Turbo Modules and the Leancore effort. Since react-native-foo is such a highly used module, they want to ensure that their module works when Turbo Modules come online.
Q: What work does react-native-foo need to do to be compatible with Turbo Modules? Do they need to rewrite their whole android and iOS implementations?
A: At a high level, the module author will need to write a JS spec, which will then generate some interfaces. The module author then copy/pastes the existing business logic to fill in the stubs. The signatures of the module's methods should not change (except minor ones that should be caught by Codegen)
Q: How will community module authors know that they need to update to Turbo Modules?
A: TBD. No step-by-step docs have been written yet.
Scenario 2: Writing new Module w/ platform-specific APIs
Alex has a great idea for a totally new module react-native-bar that has platform-specific implementations for iOS/Android/Windows.
Q: How does somebody write a new Turbo Module that has platform-specific APIs?
A: Same as scenario 1.
Scenario 3: Writing a new Module w/ platform-agnostic APIs
Bryce has a bunch of legacy C++ code that is platform-agnostic. Bryce would like to create a module that encapsulates this code and hopes it can be shared on iOS/Android/Windows.
Q: How does somebody write a new Turbo Module that has platform-agnostic/C++ APIs? Is the story different than Scenario 2?
A: Same as Scenario 1. Codegen will also produce C++ stubs from the JS spec.
Scenario 4: Existing App using Native Modules already
An app author wrote their app using the native module react-native-foo. Per Scenario 1, react-native-foo has been updated to become a turbo module.
Q: What (if anything) does an app author need to do to migrate from NM react-native-foo to TM react-native-foo?
A: ?
Scenario 5: App using Turbo Modules
Sage is working on an app written in React Native and wants to use react-native-foo. Sage knows that "ye olde" native modules can be included by performing “yarn add” + “react-native link foo” but isn’t sure how to include a Turbo Module.
Q: How does an app developer integrate TMs into their app?
A: TBD, but at a high level there will be an additional build-script that maintains packages and will have a straightforward way to auto-link as before.
Sceario 6: Native Modules + Turbo Moduels within the same app
An app author is using both react-native-camera and react-native-async-storage. Lets say that camera has been updated to support turbo modules, but let’s say AsyncStorage has not.
Q: What does this app author need to do? (Do they stay on the old version of camera? Can they mix and match?)
A: The app will opt in with a flag. The app will ignore non-migrated modules. Note that modules that are TM capable are also NM capable, meaning modules that migrate to TM will work everywhere.
Q: How are they expected to handle this transition over time?
A: See above. The app will need to determine if all of their modules are TM - if they are, they can then opt in with a flag. If not, the app shouldn't opt in yet.
Scenario 7: Platform developers ie. Windows support for TM
Andrew is working on updating React Native 4 Windows to support Turbo Modules.
Q: At a high-level, what steps are involved in making RN4W (or any out of tree platform) work with TMs?
A: ?
Discussion points
Q: What is the timeframe for Turbo Modules? (When will the codegen be ready? Docs? Guidance? Etc.?)
A: Generally, first half of 2020. However, it's unclear exactly what will be in that first release.
Q: Turbo Modules have a shared C++ layer. Is the expectation that authors will write significantly more shared code? Or will they still write mostly platform-specific code?
A: ?
Useful links
- plugin system: React Native “Plugins” for Native Libraries #125
- ObjC++ OSS modules generated code: https://github.com/facebook/react-native/tree/d72e078df41f1ba2eb94e4eb4fb28b8d0232a8a1/Libraries/FBReactNativeSpec/FBReactNativeSpec
- Java modules generated code: https://github.com/facebook/react-native/tree/d3ac9fa0c3780b43b73de97831b75cf0a7efe9c4/ReactAndroid/src/main/java/com/facebook/fbreact/specs