Skip to content

Latest commit

 

History

History
130 lines (122 loc) · 5.85 KB

File metadata and controls

130 lines (122 loc) · 5.85 KB

Native Module C++/WinRT Sample - React Native for Windows

See ../README.md for details of this sample.

See ../csharp/ for a C# version of this sample.

Note: Don't build your own projects directly out of this sample. When you publish a native module (as source), you'll want to create a new project with the correct metadata. This will also make sure that you're using unique identifiers in your project files to avoid conflicts with other native modules.

Setup

See ../README.md#Setup.

Run

See ../README.md#Run.

Upgrade

To upgrade this sample to the latest version of RNW:

  1. Open a command prompt and navigate to this folder.
  2. Delete the windows folder:
    rd /s /q windows
  3. Upgrade dev dependencies to the versions of react and react-native needed by react-native-windows@latest:
    1. Option A: Use the UpgradeSmokeTest.ps1 helper script (Recommended on Windows Powershell):
      ..\..\..\.github\scripts\UpgradeSmokeTest.ps1 latest
    2. Option B: Update the package.json by hand:
      1. Look up the version of react required by react-native-windows@latest:
        npm info react-native-windows@latest devDependencies.react
      2. Upgrade react to that version:
        yarn upgrade react@VERSIONFROMLASTSTEP
      3. Look up the version of react-native required by react-native-windows@latest:
        npm info react-native-windows@latest devDependencies.react-native
      4. Upgrade react-native to that version:
        yarn upgrade react-native@VERSIONFROMLASTSTEP
      5. Upgrade react-native-windows to the latest version:
        yarn upgrade react-native-windows@latest
  4. Re-run the RNW CLI:
    npx @react-native-community/cli@latest init-windows --template old/uwp-cpp-lib --overwrite
  5. Restore these original native header files (representing the native module samples):
    git restore windows\NativeModuleSample\AsyncMethodExamples.h
    git restore windows\NativeModuleSample\DataMarshallingExamples.h
    git restore windows\NativeModuleSample\FancyMath.h
    
  6. Remove these new native header files:
    del windows\NativeModuleSample\ReactNativeModule.h
    
  7. Referring to a diff of the modified files, make the following updates:
    1. For windows\NativeModuleSample\NativeModuleSample.vcxproj:
      1. Restore the <ClInclude> entries for the files restored in Step 5:
        + <ClInclude Include="AsyncMethodExamples.h" />
        + <ClInclude Include="DataMarshallingExamples.h" />
        + <ClInclude Include="FancyMath.h" />
      2. Remove the <ClInclude> entries for the files removed in Step 6:
        - <ClInclude Include="ReactNativeModule.h" />
      3. Check if the <ProjectGuid> property at the top of the file has been updated. If so, take note of the new Guid (for later) and restore the original Guid.
    2. For windows\NativeModuleSample\NativeModuleSample.vcxproj.filters:
      1. Restore the <ClInclude> entries for the headers restored in Step 5:
        + <ClInclude Include="AsyncMethodExamples.h" />
        + <ClInclude Include="DataMarshallingExamples.h" />
        + <ClInclude Include="FancyMath.h" />
      2. Remove the <ClInclude> entries for the headers removed in Step 6:
        - <ClInclude Include="ReactNativeModule.h" />
    3. For windows\NativeModuleSample\NativeModulesSample.sln:
      1. If the project guid was changed in Step 7.1.3 above, you'll want to restore the original Guid here too. The easiest way to do this is to just do a find-replace on the new Guid with the (uppercased) old one.
    4. For ReactPackageProvider.h:
      1. Restore the copyright notice at the top of the file:
        + // Copyright (c) Microsoft Corporation. All rights reserved.
        + // Licensed under the MIT License.
        + 
    5. For ReactPackageProvider.cpp:
      1. Restore the copyright notice at the top of the file:
        + // Copyright (c) Microsoft Corporation. All rights reserved.
        + // Licensed under the MIT License.
        + 
      2. Restore the #include entries for the headers restored in Step 5:
        + #include "FancyMath.h"
        + #include "DataMarshallingExamples.h"
        + #include "AsyncMethodExamples.h"
      3. Remove the #include entries for the headers removed in Step 6:
        - #include "ReactNativeModule.h"
    6. For pch.h:
      1. Restore the copyright notice at the top of the file:
        + // Copyright (c) Microsoft Corporation. All rights reserved.
        + // Licensed under the MIT License.
        + 
      2. Restore the extra #include entries used by the sample:
        + #include <winrt/Windows.System.Threading.h>
        + #include <winrt/Windows.Web.Http.h>
        + #include <winrt/Windows.Web.Http.Headers.h>
  8. Verify the updated sample builds:
    npx @react-native-community/cli@latest run-windows --no-deploy --no-launch --no-packager --no-autolink --proj "NativeModuleSample\NativeModuleSample.vcxproj"
    
  9. Update the main readme with the new major version at the top.