When building for Release, constants and commands exported by a native module no longer work:
winrt::Microsoft::ReactNative::ConstantProviderDelegate winrt::reproducernwreleasebug::implementation::SimpleViewManager::ExportedViewConstants() noexcept
{
return [](winrt::Microsoft::ReactNative::IJSValueWriter const& constantWriter)
{
WriteProperty(constantWriter, L"SimpleConstName", L"Sample Name");
};
}
winrt::Windows::Foundation::Collections::IVectorView<winrt::hstring> winrt::reproducernwreleasebug::implementation::SimpleViewManager::Commands() noexcept
{
auto commands = winrt::single_threaded_vector<hstring>();
commands.Append(L"doSomething");
return commands.GetView();
}
const getConstant = (): String => {
try {
return UIManager.RNSimple.Constants.SimpleConstName;
} catch(e) {
return 'Some error occurred while getting the constant.'
}
}
const getCommand = (): String => {
try {
return UIManager.RNSimple.Commands.doSomething;
} catch(e) {
return 'Some error occurred while getting the command.'
}
}
git clone https://github.com/jaimecbernardo/reproduce-rnw64-release-issue
cd reproduce-rnw64-release-issue
yarn
npx react-native run-windows
Expected behavior on both Debug and Release:
When building for Release, the issue appears:
npx react-native run-windows --release
npx react-native init ReproduceRNWReleaseBug --template react-native@^0.64.0
cd ReproduceRNWReleaseBug
npx react-native-windows-init --overwrite
Then the Native Module code was added and App.js
was changed to call into it.
This commit has those changes:
https://github.com/jaimecbernardo/reproduce-rnw64-release-issue/commit/03c09ec886f1d998db1070b719a93f55d7ed01f0