-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
👻 Flow Typing NativeModules #24875
Comments
@RSNara any examples on how to handle event emitter classes? |
eric: I changed the comment for listeners to be generic |
Also worth noting: there are some places in the code base that directly access constants in JS, they need to be changed to be grabbed from getConstants. Example: const DeviceInfo = require('./DeviceInfo');
dims = DeviceInfo.Dimensions; becomes: const DeviceInfo = require('./DeviceInfo');
dims = DeviceInfo.getConstants().Dimensions; luckily, flow will complain about these if you do your typing right! So, just update the callsites. |
Hey! I'd like to help with |
Hi, I would like to help with |
@michalchudziak, @gedeagas both were done by &ericlewis’ PRs |
PermissionAndroid/TimePickerAndroid are still open I think |
I'll go with |
Sure, no problem! Is it possible to work on Edit: I'm working on it :) |
I work on |
Taking |
Working on |
Working on |
This comment has been minimized.
This comment has been minimized.
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for TVNavigationEventEmitter Pull Request resolved: facebook#24898 Reviewed By: fkgozali Differential Revision: D15391716 Pulled By: rickhanlonii fbshipit-source-id: 015120c755894a5c8f75a99c2670a6ac5545b454
Summary: Part of facebook#24875. ## Changelog [General] [Added] - add TM spec for FileReaderModule Pull Request resolved: facebook#24904 Reviewed By: fkgozali Differential Revision: D15391738 Pulled By: rickhanlonii fbshipit-source-id: 69e6ff53aba2d2227607905e1f70310bdd01d224
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for SourceCode Pull Request resolved: facebook#24901 Reviewed By: fkgozali Differential Revision: D15391727 Pulled By: rickhanlonii fbshipit-source-id: 9d4622d809efdc3955d435c5a51b72c38cedccc5
Summary: Part of facebook#24875. ## Changelog [General] [Added] - add TM spec for JSDevSupport Pull Request resolved: facebook#24905 Reviewed By: fkgozali Differential Revision: D15391754 Pulled By: rickhanlonii fbshipit-source-id: afca6ce3d6bcfaaf097e13c148496cdd1f062465
Summary: part of facebook#24875. iOS only it appears, but not really used by RN itself. Should be fine? ## Changelog [General] [Added] - Add TM spec for KeyboardObserver Pull Request resolved: facebook#24881 Reviewed By: fkgozali Differential Revision: D15391769 Pulled By: rickhanlonii fbshipit-source-id: 557507f6063b40d1c68ec8739e23b33bc22ade39
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for TimePickerAndroid Pull Request resolved: facebook#24897 Reviewed By: fkgozali Differential Revision: D15424335 Pulled By: RSNara fbshipit-source-id: a846de9353af58ad7d5e09678dd810ac33532105
Summary: Part of facebook#24875, adds a spec for ExceptionsManager ## Changelog [General] [Added] - TM Add spec for ExceptionsManager Pull Request resolved: facebook#24900 Reviewed By: fkgozali Differential Revision: D15434006 Pulled By: RSNara fbshipit-source-id: 1a505744a84c0c4ac3a9fac6c91a391fbd8a9f46
Summary: Part of facebook#24875. Not sure that the id’s types are necessarily correct here… ## Changelog [General] [Added] - Add TM spec for BlobModule Pull Request resolved: facebook#24909 Reviewed By: fkgozali Differential Revision: D15433753 Pulled By: RSNara fbshipit-source-id: 68193d1a82fc7c66d6cc7ba4f22a0d3786987599
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for AccessibilityInfo Pull Request resolved: facebook#24891 Reviewed By: fkgozali Differential Revision: D15394913 Pulled By: RSNara fbshipit-source-id: e66e7b7fc4451575b5022695f125c15f9f4b707e
Summary: Part of facebook#24875, adds a spec for HeapCapture ## Changelog [General] [Added] - TM Spec for HeapCapture Pull Request resolved: facebook#24899 Reviewed By: fkgozali Differential Revision: D15393464 Pulled By: RSNara fbshipit-source-id: d8778285753ce8dbc87204ecfbddfa7339acd264
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for Timing Pull Request resolved: facebook#24889 Reviewed By: fkgozali Differential Revision: D15379559 Pulled By: RSNara fbshipit-source-id: d254fb4d1cae3533bbd63bf7ec739cebc6ca14b0
Summary: Part of facebook#24875. Added `strict-local` to the NativeModuleHelper btw. ## Changelog [General] [Added] - TM add spec for AnimatedModule Pull Request resolved: facebook#24911 Reviewed By: rickhanlonii Differential Revision: D15434114 Pulled By: fkgozali fbshipit-source-id: ea9215306ebf969795ce755270b8fdc14c52da9c
Summary: Part of facebook#24875. ## Changelog [General] [Added] - TM add spec for DialogManagerAndroid Pull Request resolved: facebook#24912 Reviewed By: fkgozali Differential Revision: D15433854 Pulled By: RSNara fbshipit-source-id: e7234debe16de5afbc770f8feee2471f41b54427
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for AlertManager Pull Request resolved: facebook#24906 Reviewed By: lunaleaps Differential Revision: D15471065 Pulled By: fkgozali fbshipit-source-id: bb22e6454b1f748987f3a8cd957bfd4e027493a5
Summary: This PR solves part of this issue: facebook#24875 ## Changelog [General] [Added] - TM Spec for ImageEditor Pull Request resolved: facebook#24921 Reviewed By: rickhanlonii Differential Revision: D15471058 Pulled By: fkgozali fbshipit-source-id: f01539fc8acea95fca27ce7bb4b4169ffe138d93
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for ModalManager Pull Request resolved: facebook#24896 Reviewed By: rickhanlonii Differential Revision: D15471097 Pulled By: fkgozali fbshipit-source-id: 99671583ddc2a6fc32fd1bcf9a6e340ad93a27c2
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for AccessibilityManager Pull Request resolved: facebook#24894 Reviewed By: rickhanlonii Differential Revision: D15471243 Pulled By: fkgozali fbshipit-source-id: 33f39d41d70da9380f29f2eb47e8c7682b323030
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for PermissionsAndroid Pull Request resolved: facebook#24886 Reviewed By: RSNara Differential Revision: D15542996 Pulled By: fkgozali fbshipit-source-id: cab02d97e70d65347f63e891cff98c17adc1fdba
Summary: part of facebook#24875. I again, am not completely sure how the call site here works- appears settings can be directly accessed? ## Changelog [General] [Added] - Add TM spec for Settings Pull Request resolved: facebook#24879 Reviewed By: RSNara Differential Revision: D15543012 Pulled By: fkgozali fbshipit-source-id: a1df3096a2fc5fe8e65d0ed2398912530bd3911a
Summary: part of facebook#24875 ## Changelog [General] [Added] - Add TM spec for AndroidToast Pull Request resolved: facebook#24888 Reviewed By: RSNara Differential Revision: D15543043 Pulled By: fkgozali fbshipit-source-id: 6636dd913f7c006704ead1aa92d37e42a4edf70e
Summary: Part of facebook#24875, adds a spec for Networking. Since `sendRequest` methods are different for both platforms, I had to create 2 spec files as Flow would merge their definitions even when I added `Platform.OS` check ## Changelog [General] [Added] - TM spec for Networking Pull Request resolved: facebook#24892 Reviewed By: RSNara Differential Revision: D15543067 Pulled By: fkgozali fbshipit-source-id: 2b91114dfa45e7899bbb139656a30a6fd52e31db
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for WebSocketModule Pull Request resolved: facebook#24893 Reviewed By: RSNara Differential Revision: D15551329 Pulled By: fkgozali fbshipit-source-id: 59a921c50cc162528b2181fdd4cb1e41e3f1f6eb
Summary: part of facebook#24875. ## Changelog [General] [Added] - add TM spec for PlatformConstants Pull Request resolved: facebook#24928 Reviewed By: RSNara Differential Revision: D15551340 Pulled By: fkgozali fbshipit-source-id: 9de15ff4cfe717f963332868bd873d5147a37506
Summary: part of facebook#24875. Because some of the methods are rewriteable, I dropped the `+` from the signature, this doesn't feel right to me, but I am not sure if the codegen requires that. If it does, it will probably be better to extend the spec and allow those specific methods to be overriden in a UIManager.js interface. Thoughts on that fkgozali or RSNara? ## Changelog [General] [Added] - Add TM spec for UIManager Pull Request resolved: facebook#24902 Reviewed By: hramos Differential Revision: D15551356 Pulled By: fkgozali fbshipit-source-id: 076c4ce635aa7ea41e21cbd67c47ecd562fc320d
Summary: Part of facebook#24875, adds a spec for DevSettings. ## Changelog [General] [Added] - TM spec for DevSettings Pull Request resolved: facebook#25084 Reviewed By: hramos Differential Revision: D15558093 Pulled By: fkgozali fbshipit-source-id: 3adcb640a6ad80c84c831905bda114e27177f1fe
Summary: This PR solves part of this issue: facebook#24875 ## Changelog [General] [Added] - add TM spec for ImageStore Pull Request resolved: facebook#25101 Reviewed By: hramos Differential Revision: D15583463 Pulled By: fkgozali fbshipit-source-id: 17e87e8fecb35d42a981b1fb348e40d2b1e91cc6
Summary: Part of facebook#24875. ## Changelog [General] [Added] - add TM spec for I18nManager Pull Request resolved: facebook#24908 Reviewed By: fkgozali Differential Revision: D15395163 Pulled By: RSNara fbshipit-source-id: 8fd3a5a8ce5d0f74132efff4fae7224eab03405b
Summary: Note: iOS only. This spec file (.h/.mm) was generated via FB internal codegen tool for TurboModule. The tool itself is not yet ready to be opensourced, but at least the generated file is. The output is based on all the Flow types added via facebook#24875. This file can be used by each ObjC NativeModule to be TurboModule compliant. Reviewed By: rickhanlonii Differential Revision: D15978911 fbshipit-source-id: 9e97495287bc406e0ed0ccf89cf370753b538772
Flow Typing NativeModules
The TurboModule system is nearly feature-complete on both Android and iOS. Before we rollout the system, we'd like to migrate all our OSS NativeModules to use it. As a prerequisite for this migration, all the the NativeModules must have spec files. There are currently 41 NativeModules in total, so there is a bunch of work to do. We'd love to use this as an opportunity to help get more people involved by contributing to React Native.
Instructions
NativeXYZ.js
, whereXYZ
is the name of the NativeModule.NativeModules.XYZ
toNativeXYZ
What is a Spec file?
A Spec file looks like this:
NativeAnalytics.js
Observations
TurboModuleRegistry.getEnforcing<Spec>('Analytics')
as opposed toNativeModules.Analytics
to require the NativeModule.TurboModuleRegistry.getEnforcing
is an indirection that allows us to require both NativeModules and TurboModules. It throws if the NativeModule isn't there. In the case that a NativeModule is platform-specific, please use Platform.OS and conditionally callTurboModuleRegistry.getEnforcing
.interface
calledSpec
that extendsTurboModule
. This interface contains typings for methods exposed by the NativeModule/TurboModule.getConstants()
method. The old way of accessing constants as properties on NativeModule objects is deprecated and unsupported by the TurboModule system. On iOS, these constants map to the return type ofconstantsToExport
in iOS andgetConstants
in Android.Native*.js
. The filename matters because our codegen uses it to name the generated Java interfaces, ObjC protocols, and C++ TurboModule subclasses.NativeAnalytics.js
, for instance, will generate a Java interface and ObjC protocol calledNativeAnalyticsSpec
, and a C++ TurboModule class calledNativeAnalyticsSpecJSI
. After these Spec files are typed, we'll generate and check in the codegen output into this repository. Then, after we open source our codegen, we'll delete the generated interfaces, protocols, and C++ classes from this repository.Supported Types
string
boolean
number
Object
Array<*>*
Function
and typed function:?string
?Object
?Array<*>*
?Function
and nullable typed functionnumber
andboolean
are not supported(x: {|foo: string, ... |}) => void
Promise<*>*
string
number
boolean
Object
Array<*>*
How do you type NativeModules?
You have to deduce the types by looking at the NativeModule implementations on iOS and Android. Some NativeModules already have JS wrappers, so you could also look at those for writing the Spec files.
Guidelines
How do you know which methods are exported to JS?
@ReactMethod
.RCT_EXPORT_*_METHOD
macros .How do you know when a method should have a
Promise
return type?Promise
object.RCTPromiseResolveBlock
andRCTPromiseRejectBlock
What should the JS method name be?
NSDictionary
on iOS, andReadableMap
andWritableMap
on Android translate to object literals in JS.RCTResponseSenderBlock
andRCTResponseErrorBlock
on iOS, andCallback
on Android translate to function literals in JS.Try to avoid using
Function
andObject
whenever possible.In the case that a method or constant is unavailable on one platform, make it optional.
In the case that a NativeModule is unavailable on one platform, make it optional.
Where do you put the Spec file?
react-native-github/Libraries/NativeModules/specs
.Platform-specific NativeModules
For platform-specific NativeModules, use
Platform.OS
to conditionally callTurboModuleRegistry.getEnforcing<Spec>
. When changing the call-sites of these NativeModules, you may have to guard them with null checks to please flow.Call-site Before
Call-site After
NativeModule List
Please claim a NativeModule from the list below.
⬜️ - Unclaimed
🚧 - Claimed / PR in progress
✅ - PR Merged
The text was updated successfully, but these errors were encountered: