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.StartScreen
Windows.Foundation.Uri
Windows.Storage
Windows.Foundation.Diagnostics
Windows.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 install
C:\react-native-winrt\samples\RNWinRTTestApp> yarn install
NOTE: Because this project references local file contents for the
react-native-winrt
package, you must runyarn install
as opposed tonpm install
, otherwise you may get build errors -
If using the command line:
C:\react-native-winrt\samples\RNWinRTTestApp> npx react-native run-windows
If using Visual Studio:
- Open the solution file
\windows\RNWinRTTestApp.sln
in Visual Studio. - Build the solution.
- If running Debug: run
yarn start
in 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: