This sample demonstrates how to use the react-native-winrt package to consume projected WinRT APIs with Javascript in a React Native for Windows app.
The WinRT APIs demonstrated in this sample include:
Windows.UI.StartScreenWindows.Foundation.UriWindows.StorageWindows.Foundation.DiagnosticsWindows.UI.Notifications
- See System Requirements for React Native for Windows development
-
Open an 'x64 Native Tools Command Prompt for VS 2022' (or whichever version of Visual Studio you have installed)
-
Clone or download the react-native-winrt repository.
C:\> git clone https://github.com/microsoft/react-native-winrt.git C:\> cd react-native-winrt
-
"Build" the local package by executing the script:
C:\react-native-winrt> scripts\build-npm-package.cmd -
Change the working directory to this directory
C:\react-native-winrt> cd samples\RNWinRTTestApp
-
Run
yarn installC:\react-native-winrt\samples\RNWinRTTestApp> yarn installNOTE: Because this project references local file contents for the
react-native-winrtpackage, you must runyarn installas opposed tonpm install, otherwise you may get build errors -
If using the command line:
C:\react-native-winrt\samples\RNWinRTTestApp> npx react-native run-windowsIf using Visual Studio:
- Open the solution file
\windows\RNWinRTTestApp.slnin Visual Studio. - Build the solution.
- If running Debug: run
yarn startin the command prompt from this directory. - F5 deploy the sample app (RNWinRTTestApp).
- Open the solution file
You will see something similar to below after successfully building and running the sample:
