2020-06-02 01:17:26 +03:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
2020-06-04 05:39:30 +03:00
|
|
|
#pragma warning disable CS8625 // This file is compiled both without and with nullable
|
|
|
|
#pragma warning disable CS8618 // This file is compiled both without and with nullable
|
|
|
|
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
namespace Microsoft.ReactNative.Managed
|
|
|
|
{
|
|
|
|
[AttributeUsage(AttributeTargets.Class)]
|
2020-05-07 20:22:40 +03:00
|
|
|
public class ReactModuleAttribute : Attribute
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
{
|
|
|
|
public ReactModuleAttribute(string moduleName = null)
|
|
|
|
{
|
|
|
|
ModuleName = moduleName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string ModuleName { get; set; }
|
|
|
|
|
|
|
|
public string EventEmitterName { get; set; }
|
|
|
|
}
|
|
|
|
|
2020-02-20 02:30:14 +03:00
|
|
|
[AttributeUsage(AttributeTargets.Method)]
|
2020-05-07 20:22:40 +03:00
|
|
|
public class ReactInitializerAttribute : Attribute
|
2020-02-20 02:30:14 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
|
2020-05-07 20:22:40 +03:00
|
|
|
public class ReactConstantAttribute : Attribute
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
{
|
|
|
|
public ReactConstantAttribute(string constantName = null)
|
|
|
|
{
|
|
|
|
ConstantName = constantName;
|
|
|
|
}
|
|
|
|
|
2020-02-20 02:30:14 +03:00
|
|
|
public string ConstantName { get; set; }
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Method)]
|
2020-05-07 20:22:40 +03:00
|
|
|
public class ReactConstantProviderAttribute : Attribute
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-26 07:23:09 +03:00
|
|
|
[AttributeUsage(AttributeTargets.Method)]
|
|
|
|
public class ReactGetConstantsAttribute : Attribute
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
[AttributeUsage(AttributeTargets.Method)]
|
2020-05-07 20:22:40 +03:00
|
|
|
public class ReactMethodAttribute : Attribute
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
{
|
|
|
|
public ReactMethodAttribute(string methodName = null)
|
|
|
|
{
|
|
|
|
MethodName = methodName;
|
|
|
|
}
|
|
|
|
|
2020-02-20 02:30:14 +03:00
|
|
|
public string MethodName { get; set; }
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Method)]
|
2020-05-07 20:22:40 +03:00
|
|
|
public class ReactSyncMethodAttribute : Attribute
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
{
|
|
|
|
public ReactSyncMethodAttribute(string methodName = null)
|
|
|
|
{
|
|
|
|
MethodName = methodName;
|
|
|
|
}
|
|
|
|
|
2020-02-20 02:30:14 +03:00
|
|
|
public string MethodName { get; set; }
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
}
|
|
|
|
|
2019-12-12 02:38:29 +03:00
|
|
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
2020-05-07 20:22:40 +03:00
|
|
|
public class ReactEventAttribute : Attribute
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
{
|
|
|
|
public ReactEventAttribute(string eventName = null)
|
|
|
|
{
|
|
|
|
EventName = eventName;
|
|
|
|
}
|
|
|
|
|
2020-02-20 02:30:14 +03:00
|
|
|
public string EventName { get; set; }
|
|
|
|
|
|
|
|
public string EventEmitterName { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
2020-05-07 20:22:40 +03:00
|
|
|
public class ReactFunctionAttribute : Attribute
|
2020-02-20 02:30:14 +03:00
|
|
|
{
|
|
|
|
public ReactFunctionAttribute(string functionName = null)
|
|
|
|
{
|
|
|
|
FunctionName = functionName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string FunctionName { get; set; }
|
|
|
|
|
|
|
|
public string ModuleName { get; set; }
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
}
|
2022-10-26 07:23:09 +03:00
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
|
|
|
|
public class ReactPropertyAttribute : Attribute
|
|
|
|
{
|
|
|
|
public ReactPropertyAttribute(string propertyName = null)
|
|
|
|
{
|
|
|
|
PropertyName = propertyName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string PropertyName { get; set; }
|
|
|
|
}
|
Native Modules in C# and C++ (#3403)
This prototype is built on top of @jonthysell and @micahl prototypes.
It has two main points:
- Simplify native module creation by supporting plain C++ and C# with custom attributes for the module and its members.
- Make efficient data sending between native modules and the ReactNative DLL by using IJSValueReader and IJSValueWriter interfaces that allow to avoid data boxing and thus to avoid extra memory allocations.
This is an example for the C# native modules with custom attributes:
[ReactModule]
class CsStrings
{
[ReactMethod]
public int Length(string value)
{
return value.Length;
}
[ReactMethod]
public string Concat(string x, string y)
{
return x + y;
}
[ReactMethod]
public void Substr(string value, int length, ReactCallback<string> resolve, ReactCallback<string> reject)
{
if (length <= value.Length)
resolve(value.Substring(0, length));
else
reject("length must be less or equal to string length");
}
}
We use here ReactModule and ReaactMethod attributes. We also have ReactConstant and ReactEvent attributes to mark a field or event to be a constant or an event. The ReactConstantProvider can be added to a method that provides a set of constants.
In C++ we have similar syntax:
REACT_MODULE(MyModule);
struct MyModule {
REACT_CONSTANT(m_fieldConst);
const int m_fieldConst = 42;
REACT_CONSTANT_JSNAME(m_fldConst, "fldConst");
const int m_fldConst = 43;
REACT_CONST_PROVIDER(SimpleConstants);
void SimpleConstants(
const winrt::Microsoft::ReactNative::Bridge::IJSValueWriter
&writer) noexcept {
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst1", 5);
::Microsoft::ReactNative::WriteProperty(writer, "simpleConst2", "World");
}
REACT_EVENT(OnChanged);
std::function<void(int)> OnChanged;
REACT_METHOD(Add);
int Add(int x, int y) noexcept {
OnChanged(x + y);
return x + y;
}
We use macros as custom attributes.
The related docs are in the vnext\docs\NativeModules.md file.
From @jonthysell's commit message:
* Replaced NativeModuleBase with INativeModule
* Added Microsoft.ReactNative.Managed project
* Removed Microsoft.ReactNative solution, added projects into ReactWindows-Universal #3237
* Moved sample native modules from sample apps into sample libraries #3226, #3223
* Created C# native module sample with all method return types, #3207, #3218, #3231, #3230, #3232
* SampleApp(CS/CPP) get native modules from SampleLibrary(CS/CPP) #3227
* Created FancyMathABI native module on top of INativeModule #3224
* Removed marshaling of native method parameters via json #3331
Squash comments:
* Initial import from prototype
* Replaced NativeModuleBase with INativeModule
* FancyMath now works E2E
* Initial NativeModules.md docs
* Update NativeModules.md
* Started View Manager documentation
* Cleaned up ViewManagers, updated docs
* Update NativeModules.md
* Added stubs for IVM.NativeProps
* number fix
* Added new C# SampleModule
* Addresses #3230, #3231, #3232
* Starts #3226
* Removed C++/WinRT modules from app #3226 added new SampleLibraryCPP #3223
* Fixed solution files
* SampleApp package manifest updates
* Fixed issue with having an app with 0 native modules
* Adding SampleModuleABI to SampleLibraryCPP
* Clangify
* Added some links to docs
* Fixed compilation issue for C++ code.
* Added Reader/Writer interfaces and DynamicReader.
* Added DynamicWriter
* Added NativeModuleBuilder implementation
* Added Microsoft copyright notices
* Added the INativeModulePackage for the new native modules.
* Added C# shared code to support native module creation
* Added shared C++ project to support native module development.
* Added cpp FancyMathABI stub
* clangify
* SampleLibraryCPP work
* clangify
* lintify
* Change files
* Enable MSBuild - SampleApps in CI loop
* Enabled run of Calculator methods from SampleLibraryCPP in SampleAppCPP
* Enabled C++ module to be used from C# project
* Switch to x86 tools for SampleApps build
* Align sampleapp windows min versions
* Fix SampleAppCPP dependencies
* Enabled calling C++ and C# modules from C++ code
* Remove SampleAppCPP and SampleLibraryCPP from build
* Fix propertysheets
* Removed Microsoft.ReactNative solution, added projects to ReactWindows-Universal
* Added JSI projects to SampleApps
* Disabled SampleApps build
* Fixed issue that C# called resolve callback instead of reject
* Fixed a few spelling issues
* Improved the Debug message output
* Provide better error info for C# code
* Implemented Error object message for C++ and C# code
* Enabled modules events and added a test for it.
* Renamed attribute macros to start with REACT_
* Added MyCtorModule to register module members in constructor.
* Initial changes to NativeModules.md documentation
* Changed ReactModule attribute to use public property setters
* Updated the documentation with the example how to use the new native modules.
* Removed JSON marshaling, issue #3331
* clangify
* Added docs for the C++ code.
* Started to work on the new IReactPackageProvider interface
* Work in progress: new package providers
* Implemented IReactPackageProvider
* Fixed event registration in JS
* Make sure that C# test app works
* Added REACT_MODULE macro-attribute for C++ code
* Changed C++ macros to use variable set of parameters
* Fixed code after the merge
* Fixed code after merge with master branch
* Extracted JSValueReader and JSValueWriter into separate files.
* Changed REACT_CONSTANT to accept variable set of parameters
* Changed REACT_EVENT macro to accept variable parameters
* Renamed INativeModuleBuilder to IReactModuleBuilder
* Removed SetName method
* Renamed AddConstantWriter to AddConstantProvider
* Renamed AddEventRegister to AddEventSetter
* Renaming Event setting related delegates
* Removed C++ native module registration that can be done from constructor.
* Fixed file code formatting
2019-10-15 01:58:23 +03:00
|
|
|
}
|