Skip to content

Commit 0dcaa91

Browse files
committed
Create Native Platform docs
1 parent 2ef6410 commit 0dcaa91

14 files changed

+568
-40
lines changed

.spelling

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ initializer
4646
interop
4747
iOS
4848
ItemGroup
49+
JSValue
4950
KeyEvents
5051
lifecycle
5152
macOS
@@ -80,6 +81,7 @@ Quickstart
8081
react-native
8182
react-native-macos
8283
react-native-windows
84+
reactnative.dev
8385
RefreshControl
8486
repo
8587
repos

docs/autolink-windows-cli.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ Here are the options that `react-native autolink-windows` takes:
3131
| `--no-telemetry` | boolean | Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI |
3232
| `-h`, `--help` | boolean | Display help for command |
3333

34-
This sends telemetry to Microsoft by default. You can prevent the telemetry from being sent by using the `--no-telemetry` command line option. See below for more details.
34+
## Telemetry Notice
35+
36+
This command sends telemetry to Microsoft by default. You can prevent the telemetry from being sent by using the `--no-telemetry` command line option. See below for more details.
3537

3638
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
3739

docs/codegen-windows-cli.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,51 @@ Here are the options that `react-native codegen-windows` takes:
2727
| `--no-telemetry` | boolean | Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI |
2828
| `-h`, `--help` | boolean | Display help for command |
2929

30-
This sends telemetry to Microsoft by default. You can prevent the telemetry from being sent by using the `--no-telemetry` command line option. See below for more details.
30+
## Codegen Config
31+
32+
The `react-native codegen-windows` command is configured by the `codegenConfig` object in the project's `package.json` file. This `codegenConfig` object is shared by all platforms, but the relevant parts for React Native for Windows is configured as follows:
33+
34+
| Field | Type| Description |
35+
|:------|:---:|:------------|
36+
| `type` | string | `"modules"` for Native Modules, `"components"` for Native Components, or `"all"` for both |
37+
| `jsSrcDir` | string | Path to the TypeScript spec input files |
38+
| `windows` | object | Windows-specific codegen configuration |
39+
40+
The `windows` object is configured as follows:
41+
42+
| Field | Type| Description |
43+
|:------|:---:|:------------|
44+
| `namespace` | string | The C++ namespace to contain the generated code |
45+
| cppStringType` | string | Optional, the string type to use in C++ code, either `"std::string"` or `std::wstring`. Defaults to `"std::string"` |
46+
| `generators` | array | Optional, array of codegen generator strings, accepting `"modulesWindows"` for Native Modules, `"componentsWindows"` for Native Components. Defaults to `[ "modulesWindows" ]` |
47+
| `outputDirectory` | string | Optional, path to place the generated code. Defaults to `./codegen/` of the working directory |
48+
| `separateDataTypes` | boolean | Optional, specify whether to create separate files to define custom data types. Defaults to `false` |
49+
50+
> **Note:** For more information on how to configure the `codegenConfig` object for other platforms, see the [reactnative.dev Configuring Codegen](https://reactnative.dev/docs/the-new-architecture/using-codegen#configuring-codegen) page.
51+
52+
### Example Codegen Config
53+
54+
```json
55+
"codegenConfig": {
56+
"name": "NativeModuleSampleSpec",
57+
"type": "all",
58+
"jsSrcsDir": "src",
59+
"includesGeneratedCode": true,
60+
"windows": {
61+
"namespace": "NativeModuleSampleCodegen",
62+
"generators": [
63+
"modulesWindows",
64+
"componentsWindows"
65+
],
66+
"outputDirectory": "windows/NativeModuleSample/codegen",
67+
"separateDataTypes": true
68+
}
69+
},
70+
```
71+
72+
## Telemetry Notice
73+
74+
This command sends telemetry to Microsoft by default. You can prevent the telemetry from being sent by using the `--no-telemetry` command line option. See below for more details.
3175

3276
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
3377

docs/getting-started.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ For information around how to set up React Native, see the [React Native Getting
1515
1616
## Create a new React Native project
1717

18-
Remember to call `@react-native-community/cli init` from the place you want your project directory to live.
18+
Call the following from the place where you want your project directory to live:
1919

2020
<!-- Note, make sure both `@react-native-community/cli@ABC` and `--version "XYZ"` are pointing to the correct NPM tags in the command below. -->
2121

2222
<!-- 1. For the next version (i.e. in docs/getting-started.md) use "next" for the CLI and "nightly" for the RN version -->
23-
<!-- 2. For the latest stable version in versioned_docs use "latest" for both the CLI and RN version -->
24-
<!-- 3. For older stable versions you'll have to look up the CLI version, but for the RN version use the stable tag name, i.e. "0.73-stable" -->
23+
<!-- 2. For stable versions in versioned_docs use "latest" for the CLI and the semantic version, i.e. "^0.73.0" for the RN version -->
2524

2625
<!-- See https://www.npmjs.com/package/@react-native-community/cli?activeTab=versions for the CLI version tags. -->
2726
<!-- See https://www.npmjs.com/package/react-native?activeTab=versions for the RN version tags. -->
@@ -119,7 +118,7 @@ npx react-native init-windows --overwrite
119118

120119
## Authoring Native Modules
121120

122-
See [Native Modules and React Native Windows](native-modules.md).
121+
See [Native Platform: Overview](native-platform.md).
123122

124123
## Building a standalone React Native Windows App
125124

docs/init-windows-cli.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ Here are the options that `react-native init-windows` takes:
3030
| `--no-telemetry` | boolean | Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI |
3131
| `-h`, `--help` | boolean | Display help for command |
3232

33-
### Templates
33+
## Templates
3434

3535
The following templates are available for use with `init-windows` by replacing `--template XYZ`, where `XYZ` can be:
3636

3737
| Template | Name |
3838
|:-:|:--|
39-
| `cpp-app` | React Native Windows Application (New Arch, C++, Win32, Hermes) |
40-
| `cpp-lib` | React Native Windows Turbo Module (New Arch, C++) |
39+
| `cpp-app` | React Native Windows Application (New Arch, WinAppSDK, C++) |
40+
| `cpp-lib` | React Native Windows Library (C++) |
4141
| `old/uwp-cpp-app` | React Native Windows Application (Old Arch, UWP, C++) |
42-
| `old/uwp-cpp-lib` | React Native Windows Library (Old Arch, UWP, C++) |
4342
| `old/uwp-cs-app` | React Native Windows Application (Old Arch, UWP, C#) |
44-
| `old/uwp-cs-lib` | React Native Windows Library (Old Arch, UWP, C#) |
4543

46-
This sends telemetry to Microsoft by default. You can prevent the telemetry from being sent by using the `--no-telemetry` command line option. See below for more details.
44+
## Telemetry Notice
45+
46+
This command sends telemetry to Microsoft by default. You can prevent the telemetry from being sent by using the `--no-telemetry` command line option. See below for more details.
4747

4848
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
4949

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: native-platform-components-paper
3+
title: "Native Platform: Native Components (Paper)"
4+
sidebar_label: Native Components (Paper)
5+
---
6+
7+
![Architecture](https://img.shields.io/badge/architecture-old_only-yellow)
8+
9+
This guide covers exposing native UI views from Windows to React Native by implementing a *Native Component* for the Windows platform. For a higher-level overview of native development on Windows, see [Native Platform: Overview](native-platform.md) before reading this guide.
10+
11+
> **Note**: See the [reactnative.dev Native Components guide](https://reactnative.dev/docs/fabric-native-components-introduction) for steps for implementing new Native Components for both the Android and iOS platforms.
12+
13+
> **Architecture Note:** This guide shows how to create a *Paper Native Component* to support React Native's Old Architecture. To support React Native for Windows apps targeting the New Architecture, see [Native Platform: Native Components (Fabric)](native-platform-components.md). For more information on React Native architectures in React Native for Windows, see [New vs. Old Architecture](new-architecture.md).
14+
15+
## High-Level Overview
16+
17+
In order to implement Windows support for a Native Component, you'll need to:
18+
19+
<!-- TODO -->
20+
21+
## Step by Step Guide
22+
23+
### 0. Setup
24+
25+
You'll need a React Native library project initialized with Windows support. The rest of this guide assumes you've followed the [Native Platform: Getting Started](native-platform-getting-started.md) guide to set up a new library.
26+
27+
<!-- TODO -->
28+
29+
## Next Steps
30+
31+
After you've implemented your native library, the final step is consume it in your React Native for Windows app. Continue with [Native Platform: Using Native Libraries](native-platform-using.md).

docs/native-platform-components.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
id: native-platform-components
3+
title: "Native Platform: Native Components (Fabric)"
4+
sidebar_label: Native Components (Fabric)
5+
---
6+
7+
![Architecture](https://img.shields.io/badge/architecture-new_only-blue)
8+
9+
This guide covers exposing native UI views from Windows to React Native by implementing a *Native Component* for the Windows platform. For a higher-level overview of native development on Windows, see [Native Platform: Overview](native-platform.md) before reading this guide.
10+
11+
> **Note**: See the [reactnative.dev Native Components guide](https://reactnative.dev/docs/fabric-native-components-introduction) for steps for implementing new Native Components for both the Android and iOS platforms.
12+
13+
> **Architecture Note:** This guide follows the recommendation to create a *Fabric Native Component* to support React Native's New Architecture. To support React Native for Windows apps targeting the Old Architecture, see [Native Platform: Native Components (Paper)](native-platform-components-paper.md). For more information on React Native architectures in React Native for Windows, see [New vs. Old Architecture](new-architecture.md).
14+
15+
## High-Level Overview
16+
17+
In order to implement Windows support for a Native Component, you'll need to:
18+
19+
1. Define the API surface for your Native Component in one or more TypeScript spec files
20+
2. Use React Native for Windows' Native Module Codegen to take those TypeScript spec files and create the C++ headers for the Windows code
21+
3. Write the Windows C++ code to implement the *Component View* specified by the generated headers
22+
4. Use the Native Component in your JavaScript
23+
24+
## Step by Step Guide
25+
26+
### 0. Setup
27+
28+
You'll need a React Native library project initialized with Windows support. The rest of this guide assumes you've followed the [Native Platform: Getting Started](native-platform-getting-started.md) guide to set up a new library.
29+
30+
### 1. Define the API surface in TypeScript
31+
32+
<!-- TODO -->
33+
34+
### 2. Use React Native for Windows' Native Module Codegen
35+
36+
<!-- TODO -->
37+
38+
### 3. Implement the Windows C++ code
39+
40+
<!-- TODO -->
41+
42+
### 4. Use the Native Component in your JavaScript
43+
44+
<!-- TODO -->
45+
46+
## Next Steps
47+
48+
After you've implemented your native library, the final step is consume it in your React Native for Windows app. Continue with [Native Platform: Using Native Libraries](native-platform-using.md).
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
id: native-platform-getting-started
3+
title: "Native Platform: Getting Started"
4+
sidebar_label: Getting Started
5+
---
6+
7+
![Architecture](https://img.shields.io/badge/architecture-new_&_old-green)
8+
9+
Similar to how the [Getting Started for Windows](getting-started.md) guide takes you through the process of creating a base React Native app (which supports iOS and Android), and then *adding* Windows support, this guide will take you through the steps of creating a base React Native library and then *adding* Windows support.
10+
11+
Before you get started, make sure you have installed all of the [development dependencies](rnw-dependencies.md).
12+
13+
> **Note:** There have always been multiple ways to create base React Native libraries, each creating a slightly different setup. This guide uses the `create-react-native-library` tool (with specific options) to start a brand new library, because that is the specific setup tested by the React Native for Windows team. Your experience may differ when attempting to add Windows support to (existing) libraries created by other tools.
14+
15+
## Create a new React Native library project
16+
17+
Call the following from the place where you want your project directory to live:
18+
19+
<!-- Note, make sure `--react-native-version "XYZ"` are pointing to the correct NPM tags in the command below. -->
20+
21+
<!-- 1. For the next version (i.e. in docs/getting-started.md) use "nightly" for the RN version -->
22+
<!-- 2. For stable versions in versioned_docs use the semantic version, i.e. "^0.73.0" for the RN version -->
23+
24+
<!-- See https://www.npmjs.com/package/react-native?activeTab=versions for the RN version tags. -->
25+
26+
```bat
27+
npx --yes [email protected] --local false --type turbo-module --react-native-version "nightly" --example vanilla <projectName>
28+
```
29+
30+
> **Note**: Replace `<projectName>` with the name of your library. The rest of this guide will assume you named your project `testlib`. You will also be prompted to supply several other options (slug, description, etc.) when creating your project. For more information on what these options mean, see [create-react-native-library's documentation](https://callstack.github.io/react-native-builder-bob).
31+
32+
### Navigate into this newly created directory
33+
34+
React Native will have created your project in a new sub-directory, which you must enter before continuing.
35+
36+
```bat
37+
cd testlib
38+
```
39+
40+
### Add React Native Windows to your project's dependencies
41+
42+
<!-- Note, make sure "version" is pointing to the correct react-native-windows NPM tag in the command below. -->
43+
44+
<!-- 1. For the next version (i.e. in docs/getting-started.md) use "canary" -->
45+
<!-- 2. For other versions in versioned_docs use the version in the format "^0.XY.0" -->
46+
47+
```bat
48+
yarn add react-native-windows@canary --dev
49+
yarn add react-native-windows@* --peer
50+
yarn install
51+
```
52+
53+
### Initialize the React Native Windows native code and projects
54+
55+
Lastly, initialize the React Native for Windows library with the [init-windows command](init-windows-cli.md) and the `cpp-lib` template:
56+
57+
```bat
58+
npx react-native init-windows --template cpp-lib --overwrite
59+
```
60+
61+
> **Note:** The command will not only initialize the Windows code for the library project itself, but it will also add and initialize React Native for Windows for the example app created by `create-react-native-library` in the `example` folder.
62+
63+
## Running the React Native Windows example app
64+
65+
If you followed this guide and added Windows support to the base project created by `create-react-native-library`, you should be able to launch the provided `example` app with the [run-windows command](run-windows-cli.md):
66+
67+
```bat
68+
yarn example react-native run-windows
69+
```
70+
71+
## Next Steps
72+
73+
After you've initialized a new project with Windows support, your next step is to implement the Windows support in native code.
74+
75+
If you're implementing a Native Module (i.e. exposing non-UI native code), continue with [Native Platform: Native Modules](native-platform-modules.md).
76+
77+
If you're implementing a Native Component (i.e. native Windows views), continue with [Native Platform: Native Components](native-platform-components.md).

0 commit comments

Comments
 (0)