### Navigate to Project Directory Source: https://microsoft.github.io/react-native-windows/docs/0.77/getting-started Changes the current working directory to the newly created React Native project folder, which is required before executing subsequent setup commands. ```bash cd ``` -------------------------------- ### Configure GitHub Actions for RNW App CI Source: https://microsoft.github.io/react-native-windows/docs/0.77/setup-ci This YAML configuration sets up a GitHub Actions workflow for a React Native for Windows application. It checks out the code, sets up Node.js and MSBuild, installs dependencies, and then builds and runs the Windows x64 release version of the app. ```yaml name: Windows CIon: [pull_request] jobs: run-windows-tests: name: Build & run tests runs-on: windows-2022 steps: - uses: actions/checkout@v2 name: Checkout Code - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: '^18' - name: Setup MSBuild uses: microsoft/setup-msbuild@v2 - name: Install node modules run: yarn --frozen-lockfile - name: Run Windows x64 release run: npx react-native run-windows --arch x64 --release --logging ``` -------------------------------- ### Install React Native Windows Dependency with NPM Source: https://microsoft.github.io/react-native-windows/docs/0.77/getting-started Adds react-native-windows package version 0.77.0 to project dependencies using NPM package manager as an alternative to Yarn for dependency management. ```bash npm install --save react-native-windows@^0.77.0 ``` -------------------------------- ### Run React Native Windows Application Source: https://microsoft.github.io/react-native-windows/docs/0.77/getting-started Launches the React Native Windows application from the command line without Visual Studio. Opens a new Command Prompt with the React packager and compiles the entire project with dependencies. ```bash npx react-native run-windows ``` -------------------------------- ### Initialize React Native Project with Community CLI Source: https://microsoft.github.io/react-native-windows/docs/0.77/getting-started Creates a new React Native project with version 0.77.0 using the React Native Community CLI. This command scaffolds the base project structure in a new directory specified by projectName parameter. ```bash npx --yes @react-native-community/cli@latest init --version ^0.77.0 ``` -------------------------------- ### Install React Native Windows Dependency with Yarn Source: https://microsoft.github.io/react-native-windows/docs/0.77/getting-started Adds react-native-windows package version 0.77.0 to project dependencies using Yarn package manager. Yarn is the recommended approach for managing React Native Windows dependencies. ```bash yarn add react-native-windows@^0.77.0 ``` -------------------------------- ### Initialize React Native Windows Native Projects Source: https://microsoft.github.io/react-native-windows/docs/0.77/getting-started Executes the init-windows command to scaffold Windows-specific native code and Visual Studio project files. The --overwrite flag ensures the metro.config.js is properly configured for Windows development. ```bash npx react-native init-windows --overwrite ``` -------------------------------- ### Configure VS Code Debug Launch Configuration Source: https://microsoft.github.io/react-native-windows/docs/0.77/getting-started Defines a launch configuration file for VS Code to enable React Native Windows debugging. Creates a .vscode/launch.json file with platform-specific debug settings for Windows development. ```json { "version": "0.2.0", "configurations": [ { "name": "Debug Windows", "cwd": "${workspaceFolder}", "type": "reactnative", "request": "launch", "platform": "windows" } ] } ``` -------------------------------- ### Install React Native Windows Dependencies with PowerShell Script Source: https://microsoft.github.io/react-native-windows/docs/0.77/rnw-dependencies This PowerShell script automates the installation of development dependencies for React Native for Windows. It requires an elevated PowerShell window to run and downloads the script from a provided URL. ```powershell Set-ExecutionPolicy Unrestricted -Scope Process -Force; iex (New-Object System.Net.WebClient).DownloadString('https://aka.ms/rnw-vs2022-deps.ps1'); ``` -------------------------------- ### Install Dependencies for React Native Library Source: https://microsoft.github.io/react-native-windows/docs/0.77/native-modules-setup Installs all required dependencies for the newly created React Native library project. This command should be run from within the library project directory after creation and before proceeding with Windows support initialization. ```bash yarn install ``` -------------------------------- ### Install Node.js LTS using WinGet Source: https://microsoft.github.io/react-native-windows/docs/0.77/rnw-dependencies This command uses the Windows Package Manager (WinGet) to install the Long-Term Support (LTS) version of Node.js, specifically version 18.18.0. This is the recommended method for installing Node.js for React Native development. ```bash winget install OpenJS.NodeJS.LTS --version 18.18.0 ``` -------------------------------- ### Build Signed RNW App with Certificate - Yarn CLI Source: https://microsoft.github.io/react-native-windows/docs/0.77/setup-ci Configures a React Native Windows build to use a certificate for app signing via the yarn windows command. The `PackageCertificateKeyFile` MSBuild property specifies the path to the PFX certificate file, enabling release builds with x64 architecture and logging enabled. ```yaml steps: - name: run-windows (Release) - CI run: yarn windows --no-launch --arch x64 --logging --release --msbuildprops PackageCertificateKeyFile=ProjectDirectoryPath\GitHubActionsWorkflow.pfx ``` -------------------------------- ### Base64 Encode PFX Certificate for GitHub Secrets Source: https://microsoft.github.io/react-native-windows/docs/0.77/setup-ci This PowerShell script reads a PFX certificate file, converts its content to a Base64 encoded string, and saves it to a text file. This is necessary for securely storing certificate data as a secret in GitHub Actions or other CI/CD platforms. ```powershell $fileContentBytes = get-content '' -Encoding Byte [System.Convert]::ToBase64String($fileContentBytes) | Out-File pfx-encoded-bytes.txt ``` -------------------------------- ### Register Native Module with Simplified API (C#) Source: https://microsoft.github.io/react-native-windows/docs/0.77/native-modules-advanced This C# example presents the most concise way to register native module constants and methods by abstracting away readers and writers using a `MethodCallContext`. It simplifies the developer experience but may incur boxing overhead. ```csharp namespace NativeModuleSample { public sealed class FancyMathPackageProvider : IReactPackageProvider { public void CreatePackage(IReactPackageBuilder packageBuilder) { packageBuilder.AddModule("FancyMath", (IReactModuleBuilder moduleBuilder) => { var module = new FancyMath(); moduleBuilder.AddConstantProvider(() => new Dictionary { ["E"] = module.E, ["Pi"] = module.PI }); moduleBuilder.AddMethod("add", MethodReturnType.Callback, (MethodCallContext callContext) => { double result = module.Add((double)callContext.Args[0], (double)callContext.Args[1]); callContext.resolve(result); }); return module; }); } } } ``` -------------------------------- ### react-native.config.js Example for MyApp Project Source: https://microsoft.github.io/react-native-windows/docs/0.77/config Example implementation of react-native.config.js override file for a Windows project named MyApp. Exports module configuration with Windows-specific paths including source directory, solution file, and project file location relative to the app root. ```javascript module.exports = { project: { windows: { sourceDir: 'windows', solutionFile: 'MyApp.sln', project: { projectFile: 'MyApp\\MyApp.vcxproj', }, }, }, }; ``` -------------------------------- ### Verify Platform Installation with React Native CLI Source: https://microsoft.github.io/react-native-windows/docs/0.77/metro-config-out-tree-platforms This command, `npx react-native config`, outputs the current React Native configuration, including detected platforms. It's used to verify that platform-specific packages like 'react-native-macos' or 'react-native-windows' are correctly recognized and registered by the CLI. ```bash npx react-native config ``` -------------------------------- ### Decode Base64 Certificate to PFX File - PowerShell Source: https://microsoft.github.io/react-native-windows/docs/0.77/setup-ci Decodes a Base64-encoded certificate stored as a GitHub Secret and writes it to a PFX file for use in signing operations. This step retrieves the encoded string from `secrets.Base64_Encoded_Pfx`, converts it from Base64 to bytes, and saves it to the specified project directory path. ```powershell - name: Decode the pfx run: | $PfxBytes = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}") $PfxPath = [System.IO.Path]::GetFullPath( (Join-Path -Path ProjectDirectoryPath -ChildPath GitHubActionsWorkflow.pfx) ) [System.IO.File]::WriteAllBytes("$PfxPath", $PfxBytes) ``` -------------------------------- ### Create New React Native Library Project with create-react-native-library CLI Source: https://microsoft.github.io/react-native-windows/docs/0.77/native-modules-setup Creates a new React Native library project named 'my-library' using the create-react-native-library third-party CLI tool. This generates a base library structure that can be extended with Windows native module support. The command uses npx to execute the latest version of the tool without installation. ```bash npx --yes create-react-native-library@latest my-library ``` -------------------------------- ### Initialize React Native Windows Project (Old Architecture) Source: https://microsoft.github.io/react-native-windows/docs/0.77/new-architecture This command initializes a new React Native for Windows project using the old architecture, which relies on the Universal Windows Platform (UWP). This template is suitable for maintaining existing projects or for developers who do not yet need to adopt the New Architecture. ```bash yarn react-native init-windows --overwrite ``` -------------------------------- ### Remove Certificate File from Pipeline - PowerShell Source: https://microsoft.github.io/react-native-windows/docs/0.77/setup-ci Removes the PFX certificate file from the pipeline after signing is complete. Uses PowerShell to construct the certificate path, output it for verification, and delete the file to ensure sensitive certificate data is not left in the pipeline artifacts. ```powershell - name: Remove the pfx run: | $certificatePath = Join-Path -Path ProjectDirectoryPath -ChildPath GitHubActionsWorkflow.pfx Write-Host $certificatePath Remove-Item -path $certificatePath ``` -------------------------------- ### Initialize React Native Windows Project (New Architecture) Source: https://microsoft.github.io/react-native-windows/docs/0.77/new-architecture This command initializes a new React Native for Windows project with the New Architecture, utilizing the 'cpp-app' template. This template leverages the Windows App SDK (WinAppSDK) and the Fabric renderer, offering a modern development experience and improved performance. It is recommended for new projects starting with React Native 0.76+. ```bash yarn react-native init-windows --template cpp-app --overwrite ``` -------------------------------- ### ReactInstanceSettings Constructors and Events Source: https://microsoft.github.io/react-native-windows/docs/0.77/native-api/ReactInstanceSettings Details on how to construct a ReactInstanceSettings object and information about the events that can be subscribed to. ```APIDOC ## Constructors and Events for ReactInstanceSettings ### Constructors #### ReactInstanceSettings **`ReactInstanceSettings`**() ### Events #### InstanceCreated Type: `InstanceCreatedEventArgs` #### InstanceDestroyed Type: `InstanceDestroyedEventArgs` #### InstanceLoaded Type: `InstanceLoadedEventArgs` ``` -------------------------------- ### Use useColorScheme Hook for Theme Sensitivity in React Native Source: https://microsoft.github.io/react-native-windows/docs/0.77/windowsbrush-and-theme This example demonstrates how to use the `useColorScheme` hook in React Native to dynamically adjust component styles based on the system's color scheme (light or dark). It's a simple way to make your app theme-aware without complex setup. Note that `useColorScheme()` returns 'light' during remote debugging. ```javascript import { useColorScheme } from 'react-native'; const MyAppComponent = () => { const colorScheme = useColorScheme(); return (