Skip to content

Commit

Permalink
feat: implement multiply C# method
Browse files Browse the repository at this point in the history
This PR:
- Converts the sample app to C# so that we can use C# library as [a compatible part of the Windows support matrix](https://microsoft.github.io/react-native-windows/docs/native-code-language-choice#compatibility-matrix).
- Converts multiply method to sync method
- Fixes auto-linking
  • Loading branch information
joshuayoes authored Mar 5, 2024
2 parents 95cc50c + 9ee1c03 commit f3490a7
Show file tree
Hide file tree
Showing 43 changed files with 1,605 additions and 542 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react-dom": "18.2.0",
"react-native": "0.73.4",
"react-native-web": "~0.19.6",
"react-native-windows": "0.73.8"
"react-native-windows": "0.73.9"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
11 changes: 11 additions & 0 deletions example/react-native.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const path = require('path');

// @ts-check
/** @type {import('@react-native-community/cli-types').Config} */
module.exports = {
dependencies: {
'react-native-pos-tools': {
root: path.join(__dirname, '..'),
},
},
};
2 changes: 1 addition & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function App() {
const [result, setResult] = React.useState<number | undefined>();

React.useEffect(() => {
multiply(3, 7).then(setResult);
setResult(multiply(3, 7));
}, []);

return (
Expand Down
85 changes: 63 additions & 22 deletions example/windows/ReactNativePosToolsExample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReactNativePosToolsExample", "ReactNativePosToolsExample\ReactNativePosToolsExample.vcxproj", "{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}"
ProjectSection(ProjectDependencies) = postProject
{F7D32BD0-2749-483E-9A0D-1635EF7E3136} = {F7D32BD0-2749-483E-9A0D-1635EF7E3136}
EndProjectSection
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNativePosToolsExample", "ReactNativePosToolsExample\ReactNativePosToolsExample.csproj", "{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Folly", "..\node_modules\react-native-windows\Folly\Folly.vcxproj", "{A990658C-CE31-4BCC-976F-0FC6B1AF693D}"
EndProject
Expand All @@ -33,6 +30,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mso", "..\node_modules\reac
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Include", "..\node_modules\react-native-windows\include\Include.vcxitems", "{EF074BA1-2D54-4D49-A28E-5E040B47CD2E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.ReactNative.Managed", "..\node_modules\react-native-windows\Microsoft.ReactNative.Managed\Microsoft.ReactNative.Managed.csproj", "{F2824844-CE15-4242-9420-308923CD76C3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ReactNative.Managed.CodeGen", "..\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.csproj", "{ADED4FBE-887D-4271-AF24-F0823BCE7961}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNativePosTools", "..\..\windows\ReactNativePosTools\ReactNativePosTools.csproj", "{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9
Expand All @@ -54,24 +57,24 @@ Global
Release|ARM64 = Release|ARM64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Debug|ARM64.ActiveCfg = Debug|ARM64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Debug|ARM64.Build.0 = Debug|ARM64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Debug|ARM64.Deploy.0 = Debug|ARM64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Debug|x64.ActiveCfg = Debug|x64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Debug|x64.Build.0 = Debug|x64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Debug|x64.Deploy.0 = Debug|x64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Debug|x86.ActiveCfg = Debug|Win32
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Debug|x86.Build.0 = Debug|Win32
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Debug|x86.Deploy.0 = Debug|Win32
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Release|ARM64.ActiveCfg = Release|ARM64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Release|ARM64.Build.0 = Release|ARM64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Release|ARM64.Deploy.0 = Release|ARM64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Release|x64.ActiveCfg = Release|x64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Release|x64.Build.0 = Release|x64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Release|x64.Deploy.0 = Release|x64
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Release|x86.ActiveCfg = Release|Win32
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Release|x86.Build.0 = Release|Win32
{5B6C43BE-97A2-4B46-A7BC-7B7A4701616D}.Release|x86.Deploy.0 = Release|Win32
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Debug|ARM64.ActiveCfg = Debug|ARM64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Debug|ARM64.Build.0 = Debug|ARM64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Debug|ARM64.Deploy.0 = Debug|ARM64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Debug|x64.ActiveCfg = Debug|x64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Debug|x64.Build.0 = Debug|x64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Debug|x64.Deploy.0 = Debug|x64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Debug|x86.ActiveCfg = Debug|x86
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Debug|x86.Build.0 = Debug|x86
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Debug|x86.Deploy.0 = Debug|x86
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Release|ARM64.ActiveCfg = Release|ARM64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Release|ARM64.Build.0 = Release|ARM64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Release|ARM64.Deploy.0 = Release|ARM64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Release|x64.ActiveCfg = Release|x64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Release|x64.Build.0 = Release|x64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Release|x64.Deploy.0 = Release|x64
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Release|x86.ActiveCfg = Release|x86
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Release|x86.Build.0 = Release|x86
{FC8E39B3-BF03-49BF-8A9D-B664CF93C234}.Release|x86.Deploy.0 = Release|x86
{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|ARM64.ActiveCfg = Debug|ARM64
{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|ARM64.Build.0 = Debug|ARM64
{A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Debug|x64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -120,6 +123,30 @@ Global
{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|x64.Build.0 = Release|x64
{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|x86.ActiveCfg = Release|Win32
{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}.Release|x86.Build.0 = Release|Win32
{F2824844-CE15-4242-9420-308923CD76C3}.Debug|ARM64.ActiveCfg = Debug|ARM64
{F2824844-CE15-4242-9420-308923CD76C3}.Debug|ARM64.Build.0 = Debug|ARM64
{F2824844-CE15-4242-9420-308923CD76C3}.Debug|x64.ActiveCfg = Debug|x64
{F2824844-CE15-4242-9420-308923CD76C3}.Debug|x64.Build.0 = Debug|x64
{F2824844-CE15-4242-9420-308923CD76C3}.Debug|x86.ActiveCfg = Debug|x86
{F2824844-CE15-4242-9420-308923CD76C3}.Debug|x86.Build.0 = Debug|x86
{F2824844-CE15-4242-9420-308923CD76C3}.Release|ARM64.ActiveCfg = Release|ARM64
{F2824844-CE15-4242-9420-308923CD76C3}.Release|ARM64.Build.0 = Release|ARM64
{F2824844-CE15-4242-9420-308923CD76C3}.Release|x64.ActiveCfg = Release|x64
{F2824844-CE15-4242-9420-308923CD76C3}.Release|x64.Build.0 = Release|x64
{F2824844-CE15-4242-9420-308923CD76C3}.Release|x86.ActiveCfg = Release|x86
{F2824844-CE15-4242-9420-308923CD76C3}.Release|x86.Build.0 = Release|x86
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Debug|ARM64.ActiveCfg = Debug|ARM64
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Debug|ARM64.Build.0 = Debug|ARM64
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Debug|x64.ActiveCfg = Debug|x64
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Debug|x64.Build.0 = Debug|x64
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Debug|x86.ActiveCfg = Debug|x86
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Debug|x86.Build.0 = Debug|x86
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Release|ARM64.ActiveCfg = Release|ARM64
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Release|ARM64.Build.0 = Release|ARM64
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Release|x64.ActiveCfg = Release|x64
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Release|x64.Build.0 = Release|x64
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Release|x86.ActiveCfg = Release|x86
{ADED4FBE-887D-4271-AF24-F0823BCE7961}.Release|x86.Build.0 = Release|x86
{14B93DC8-FD93-4A6D-81CB-8BC96644501C}.Debug|ARM64.ActiveCfg = Debug|ARM64
{14B93DC8-FD93-4A6D-81CB-8BC96644501C}.Debug|ARM64.Build.0 = Debug|ARM64
{14B93DC8-FD93-4A6D-81CB-8BC96644501C}.Debug|x64.ActiveCfg = Debug|x64
Expand All @@ -134,6 +161,18 @@ Global
{14B93DC8-FD93-4A6D-81CB-8BC96644501C}.Release|x86.ActiveCfg = Release|Win32
{14B93DC8-FD93-4A6D-81CB-8BC96644501C}.Release|x86.Build.0 = Release|Win32
{14B93DC8-FD93-4A6D-81CB-8BC96644501C}.Release|x86.Deploy.0 = Release|Win32
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Debug|x64.ActiveCfg = Debug|x64
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Debug|x64.Build.0 = Debug|x64
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Debug|x86.ActiveCfg = Debug|x86
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Debug|x86.Build.0 = Debug|x86
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Debug|ARM64.ActiveCfg = Debug|ARM64
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Debug|ARM64.Build.0 = Debug|ARM64
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Release|x64.ActiveCfg = Release|x64
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Release|x64.Build.0 = Release|x64
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Release|x86.ActiveCfg = Release|x86
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Release|x86.Build.0 = Release|x86
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Release|ARM64.ActiveCfg = Release|ARM64
{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}.Release|ARM64.Build.0 = Release|ARM64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -148,6 +187,8 @@ Global
{2049DBE9-8D13-42C9-AE4B-413AE38FFFD0} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1}
{84E05BFA-CBAF-4F0D-BFB6-4CE85742A57E} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1}
{EF074BA1-2D54-4D49-A28E-5E040B47CD2E} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1}
{F2824844-CE15-4242-9420-308923CD76C3} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1}
{ADED4FBE-887D-4271-AF24-F0823BCE7961} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1}
{14B93DC8-FD93-4A6D-81CB-8BC96644501C} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
93 changes: 0 additions & 93 deletions example/windows/ReactNativePosToolsExample/App.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions example/windows/ReactNativePosToolsExample/App.h

This file was deleted.

3 changes: 0 additions & 3 deletions example/windows/ReactNativePosToolsExample/App.idl

This file was deleted.

62 changes: 62 additions & 0 deletions example/windows/ReactNativePosToolsExample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.ReactNative;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace ReactNativePosToolsExample
{
sealed partial class App : ReactApplication
{
public App()
{
#if BUNDLE
JavaScriptBundleFile = "index.windows";
InstanceSettings.UseWebDebugger = false;
InstanceSettings.UseFastRefresh = false;
#else
JavaScriptBundleFile = "index";
InstanceSettings.UseWebDebugger = true;
InstanceSettings.UseFastRefresh = true;
#endif

#if DEBUG
InstanceSettings.UseDeveloperSupport = true;
#else
InstanceSettings.UseDeveloperSupport = false;
#endif

Microsoft.ReactNative.Managed.AutolinkedNativeModules.RegisterAutolinkedNativeModulePackages(PackageProviders); // Includes any autolinked modules

PackageProviders.Add(new ReactPackageProvider());

InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
base.OnLaunched(e);
var frame = (Frame)Window.Current.Content;
frame.Navigate(typeof(MainPage), e.Arguments);
}

/// <summary>
/// Invoked when the application is activated by some means other than normal launching.
/// </summary>
protected override void OnActivated(Windows.ApplicationModel.Activation.IActivatedEventArgs e)
{
var preActivationContent = Window.Current.Content;
base.OnActivated(e);
if (preActivationContent == null && Window.Current != null)
{
// Display the initial content
var frame = (Frame)Window.Current.Content;
frame.Navigate(typeof(MainPage), null);
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// AutolinkedNativeModules.g.cs contents generated by "react-native autolink-windows"

using System.Collections.Generic;

// Namespaces from react-native-pos-tools
using ReactNativePosTools;

namespace Microsoft.ReactNative.Managed
{
internal static class AutolinkedNativeModules
{
internal static void RegisterAutolinkedNativeModulePackages(IList<IReactPackageProvider> packageProviders)
{
// IReactPackageProviders from react-native-pos-tools
packageProviders.Add(new ReactNativePosTools.ReactPackageProvider());
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- AutolinkedNativeModules.g.targets contents generated by "react-native autolink-windows" -->
<ItemGroup>
<!-- Projects from react-native-pos-tools -->
<ProjectReference Include="$(ProjectDir)..\..\..\windows\ReactNativePosTools\ReactNativePosTools.csproj">
<Project>{0BAC62B1-2A3C-451E-BA53-E30C5581AD25}</Project>
</ProjectReference>
</ItemGroup>
</Project>
Loading

0 comments on commit f3490a7

Please sign in to comment.