Open trevor-coleman opened 1 year ago
Yeah, I discovered that RCT_EXPORT_MODULE
when used with a custom module name doesn't work well with TurboModules and we need to fix them, but we haven't had time to do so yet.
Sorry for the disruption in the example.
It's possible that the issue is that I have a PascalCase module name, or that it begins with a T?
I don't think that that's the case. I think that it actually ignores the string that it is passed when the module is a TurboModule. My suggestion, so far is to use only the RCT_EXPORT_MODULE()
version and export a turbomodule in javascript with the same name.
I was able to correct the error after changing the code of my-module/src/index.js to include the RN prefix:
// tf-litening/src/index.js import {NativeModules} from 'react-native' export default NativeModules.RNTfLitening;
Note that by doing this (☝️) you are not using TurboModules, but you are still using the Old Architecture's Native Modules.
Summary:
feat/back-turbomodule-070
branchRNTfLitening
so I replaced all examples ofCalculator
withTfLitening
RNTfLitening
so accessingNativeModules.TfLitening
insrc/index.js
returns null.NativeModules.RNTfLitening
seems to fix the issue.Suggestion: Either change the example code to include the RN prefix, OR if the issue is with having a pascal-case module name then include a warning about selecting appropriate module names.
Background:
Per the react native docs:
In the example code the module is named
RNCalculator
but then accessed vialNativeModules.Calculator
But because the prefix is
RN
and notRCT
orRK
the prefix isn't removed.My steps to reproduce
Follow the example in the
feat/back-turbomodule-070
branch, but changing the name fromCalculator
toTfLitening
(AndRNCalculator
toRNTfLitening
etc.)On the step [Native Module] Test The Native Module running the command
npx react-native run-ios
throws this error when you press the "Calculate" button.I was able to correct the error after changing the code of
my-module/src/index.js
to include theRN
prefix:Notes
It's possible that the issue is that I have a PascalCase module name, or that it begins with a T?
If so then maybe changing the example code isn't necessary, but instead a small warning or hint about choosing the module name carefully could be helpful. Something like:
Happy to submit a draft PR if this a seems worthwhile change.