You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FancyMath walkthrough in docs has drifted from what's checked into the samples #797
I believe this is intentional to showcase that you can override the projected name:
The [ReactConstant] attribute is how you can define constants. Here FancyMath has defined two constants: E and Pi. By default, the name exposed to JS will be the same name as the field (E for E), but you can override the name like this: [ReactConstant("Pi")].
changed the title [-]FancyMath example doc mixes use of `Pi` and `PI`[/-][+]FancyMath walkthrough in docs has drifted from what's checked into the samples[/+]on Mar 15, 2023
#include"pch.h"
#include"ReactPackageProvider.h"
#include"ReactPackageProvider.g.cpp"
#include<ModuleRegistration.h>// NOTE: You must include the headers of your native modules here in// order for the AddAttributedModules call below to find them.
#include"FancyMath.h"namespacewinrt::NativeModuleSample::implementation
{
voidReactPackageProvider::CreatePackage(IReactPackageBuilder const& packageBuilder) noexcept
{
AddAttributedModules(packageBuilder, true);
}
}
// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License.
#include"pch.h"
#include"ReactPackageProvider.h"
#include"FancyMath.h"
#include"DataMarshallingExamples.h"
#include"AsyncMethodExamples.h"
#if __has_include("ReactPackageProvider.g.cpp")
#include"ReactPackageProvider.g.cpp"
#endifusingnamespacewinrt::Microsoft::ReactNative;namespacewinrt::NativeModuleSample::implementation
{
voidReactPackageProvider::CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept
{
AddAttributedModules(packageBuilder, true);
}
} // namespace winrt::NativeModuleSample::implementation
Why the difference in include of ReactPackageProvider.g.cpp and lack of .h? Why the difference in <ModuleRegistration.h>? Are these meaningful differences?
Additionally the ReactPackageProvider is defined differently between this and what the app template creates. Which is correct?
Use of constants is wrong for Turbo Modules (which will be the behavior in release mode):
<View><Text>FancyMath says PI = {FancyMath.Pi}</Text><Text>FancyMath says E = {FancyMath.E}</Text><ButtononPress={this._onPressHandler}title="Click me!"/></View>);
Should use FancyMath.getConstants().Pi, for example.
Activity
asklar commentedon Mar 14, 2023
I believe this is intentional to showcase that you can override the projected name:
chrisglein commentedon Mar 14, 2023
I get the remapping with
ReactConstant("Pi"). But shouldn't the native spec use the "Pi" version and not "PI"?If you look at the implementation in the repo it says "Pi" in the native spec.
But also it has syntax I don't understand with +'s and |'s in there. So... 🤷♂️
chrisglein commentedon Mar 14, 2023
Also took me awhile to find out what else needed to change:
To this:
[-]FancyMath example doc mixes use of `Pi` and `PI`[/-][+]FancyMath walkthrough in docs has drifted from what's checked into the samples[/+]chrisglein commentedon Mar 15, 2023
Updating title beyond
Pi, because there seem to be other descrepencies:from the docs
from the sample
Why the difference in include of
ReactPackageProvider.g.cppand lack of.h? Why the difference in<ModuleRegistration.h>? Are these meaningful differences?Additionally the
ReactPackageProvideris defined differently between this and what the app template creates. Which is correct?from the docs/sample
from the template
chrisglein commentedon Mar 16, 2023
Use of constants is wrong for Turbo Modules (which will be the behavior in release mode):
Should use
FancyMath.getConstants().Pi, for example.Update some of the TurboModule documentation (#799)