Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(windows) Fix autolinking and remove legacy projects #521

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 7 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ Linking the package manually is not required anymore with [Autolinking](https://

- **Windows Platform:**

Autolinking status is unknown on Windows. If you need to manually link, see the [Manual linking steps for Windows](#manual-linking-windows) below.
Autolinking works on RNW >= 0.63. If you need to manually link, see the [Manual linking steps for Windows](#manual-linking-windows) below.

<details id='manual-linking-windows'>
<summary>Manually link the library on Windows</summary>

#### Link C++ implementation
#### Link to your C++ app (RNW >= 0.62)
* Open the solution in Visual Studio for your Windows apps
* Right click in the Explorer and click Add > Existing Project...
* Navigate to `./<app-name>/node_modules/@react-native-community/netinfo/windows/RNCNetInfoCPP/` and add `RNCNetInfoCPP.vcxproj`
Expand All @@ -75,23 +75,14 @@ Linking the package manually is not required anymore with [Autolinking](https://
* Open `pch.h`, add `#include "winrt/ReactNativeNetInfo.h"`
* Open `App.cpp`, add `PackageProviders().Append(winrt::ReactNativeNetInfo::ReactPackageProvider());` before `InitializeComponent();`

#### Link C# implementation
#### Link C# to your C# app (RNW >= 0.62)
* Open the solution in Visual Studio for your Windows apps
* Right click in the Explorer and click Add > Existing Project...
* Navigate to `./<app-name>/node_modules/@react-native-community/netinfo/windows/RNCNetInfo/` and add `RNCNetInfo.csproj`
* Navigate to `./<app-name>/node_modules/@react-native-community/netinfo/windows/RNCNetInfoCPP/` and add `RNCNetInfoCPP.vcxproj`
* This time right click on your React Native Windows app under your solutions directory and click Add > Reference...
* Check the `RNCNetInfo` you just added and press ok
* Open up `MainReactNativeHost.cs` for your app and edit the file like so:

```diff
+ using ReactNativeCommunity.NetInfo;
......
protected override List<IReactPackage> Packages => new List<IReactPackage>
{
new MainReactPackage(),
+ new RNCNetInfoPackage(),
};
```
* Check the `RNCNetInfoCPP` you just added and press ok
* Open up `App.xaml.cs` for your app and add `using ReactNativeNetInfo;` to the top.
* Open up `App.xaml.cs` for your app and add `PackageProviders.Add(new ReactNativeNetInfo.ReactPackageProvider());` before `InitializeComponent();`

</details>

Expand Down
1 change: 0 additions & 1 deletion example/windows/NetInfoExample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9
..\..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{37e37094-01b3-44a5-aab7-f0379b1ce8fa}*SharedItemsImports = 4
..\..\node_modules\react-native-windows\Mso\Mso.vcxitems*{84e05bfa-cbaf-4f0d-bfb6-4ce85742a57e}*SharedItemsImports = 9
..\..\node_modules\react-native-windows\Chakra\Chakra.vcxitems*{c38970c0-5fbf-4d69-90d8-cbac225ae895}*SharedItemsImports = 9
..\..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{da8b35b3-da00-4b02-bde6-6a397b3fd46b}*SharedItemsImports = 9
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"react-native-codegen": "^0.0.8",
"react-native-macos": "0.60.0-microsoft.50",
"react-native-web": "^0.17.5",
"react-native-windows": "0.65.6",
"react-native-windows": "0.65.8",
"react-test-renderer": "17.0.2",
"rimraf": "^2.6.3",
"semantic-release": "^17.4.6",
Expand Down
9 changes: 8 additions & 1 deletion react-native.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ let config = {
},
android:{
sourceDir: 'example/android',
}
},
windows:{
sourceDir: 'example\\windows',
solutionFile: 'NetInfoExample.sln',
project: {
projectFile: 'NetInfoExample\\NetInfoExample.vcxproj',
Copy link
Contributor

@namrog84 namrog84 Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonthysell @mikehardy
I am not sure if this has been fixed in newer versions of react native. But the usage of \\ here could be problematic for ios users in other indirect scenarios.

See my other PR where we ran into similar issues, we ended up having to patch for a while.
wonday/react-native-orientation-locker#188

Was this fixed in newer versions of RNW? Could this still be problematic for anyone on RNW63 and RNW64 or whichever versions that are still supported but older?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to patch this immediately it was painful here c9a2966

},
},
},
}
if (process.argv.includes(macSwitch)) {
Expand Down