|
9 | 9 | [ ](https://github.com/crazycodeboy/RNStudyNotes/blob/master/React%20Native%20%E9%97%AE%E9%A2%98%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%E5%90%88%E9%9B%86/React%20Native%20%E5%90%AF%E5%8A%A8%E7%99%BD%E5%B1%8F%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3%E6%95%99%E7%A8%8B/React%20Native%20%E5%90%AF%E5%8A%A8%E7%99%BD%E5%B1%8F%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3%E6%95%99%E7%A8%8B.md) |
10 | 10 | [ ](https://github.com/crazycodeboy/flutter_splash_screen) |
11 | 11 |
|
12 | | -A splash screen API for react-native which can programatically hide and show the splash screen. Works on iOS and Android. |
| 12 | +A splash screen API for react-native which can programatically hide and show the splash screen. Works on iOS, Android and Windows. |
13 | 13 |
|
14 | 14 | ## Content |
15 | 15 |
|
@@ -112,6 +112,20 @@ public class MainApplication extends Application implements ReactApplication { |
112 | 112 | `$(SRCROOT)/../node_modules/react-native-splash-screen/ios` |
113 | 113 |
|
114 | 114 |
|
| 115 | +**Windows:** |
| 116 | + |
| 117 | +##### Automatic install with autolinking on RNW |
| 118 | +RNSplashScreen supports autolinking. Just call: `yarn add react-native-splash-screen` |
| 119 | + |
| 120 | +##### Manual installation on RNW |
| 121 | +1. `yarn add react-native-splash-screen` |
| 122 | +2. Open your solution in Visual Studio 2019 (eg. `windows\yourapp.sln`) |
| 123 | +3. Right-click Solution icon in Solution Explorer > Add > Existing Project... |
| 124 | +4. Add `node_modules\[module name here]\windows\RNSplashScreen\RNSplashScreen.vcxproj` |
| 125 | +5. Right-click main application project > Add > Reference... |
| 126 | +6. Select `RNSplashScreen` in Solution Projects |
| 127 | +7. In app `pch.h` add `#include "winrt/RNSplashScreen.h"` |
| 128 | +8. In `App.cpp` add `PackageProviders().Append(winrt::RNSplashScreen::ReactPackageProvider());` before `InitializeComponent();` |
115 | 129 |
|
116 | 130 | ### Third step(Plugin Configuration): |
117 | 131 |
|
@@ -165,6 +179,43 @@ Update `AppDelegate.m` with the following additions: |
165 | 179 |
|
166 | 180 | ``` |
167 | 181 |
|
| 182 | +**Windows:** |
| 183 | +
|
| 184 | +On Windows, `react-native-splash-screen` will use an element in the visual tree to show the splash screen, a XAML `RNSplashScreen::RNSplashScreenControl`. |
| 185 | +
|
| 186 | +To add this element, follow the following steps: |
| 187 | +
|
| 188 | +1. In the application's `pch.h` file, add `#include "winrt/RNSplashScreen.h"` if you haven't already. |
| 189 | +
|
| 190 | +2. In the application's main XAML file, add a `RNSplashScreen::RNSplashScreenControl` element right beneath the `react:ReactRootView` element. |
| 191 | +
|
| 192 | +As an example, in `windows/myapp/MainPage.xaml` from the `react-native-windows` app template this can be done by adding a XAML `Grid` with a `RNSplashScreen::RNSplashScreenControl` alongside the `ReactRootView`. Change `windows/myapp/MainPage.xaml` from: |
| 193 | +```xaml |
| 194 | +<Page |
| 195 | + ... |
| 196 | + > |
| 197 | + <react:ReactRootView |
| 198 | + x:Name="ReactRootView" |
| 199 | + ... |
| 200 | + /> |
| 201 | +</Page> |
| 202 | +``` |
| 203 | +to |
| 204 | +```xaml |
| 205 | +<Page |
| 206 | + ... |
| 207 | + xmlns:rnsplashscreen="using:RNSplashScreen" |
| 208 | + > |
| 209 | + <Grid> |
| 210 | + <react:ReactRootView |
| 211 | + x:Name="ReactRootView" |
| 212 | + ... |
| 213 | + /> |
| 214 | + <rnsplashscreen:RNSplashScreenControl/> |
| 215 | + </Grid> |
| 216 | +</Page> |
| 217 | +``` |
| 218 | + |
168 | 219 | ## Getting started |
169 | 220 |
|
170 | 221 | Import `react-native-splash-screen` in your JS file. |
@@ -257,6 +308,14 @@ Customize your splash screen via `LaunchScreen.storyboard` or `LaunchScreen.xib` |
257 | 308 | - [via LaunchScreen.storyboard Tutorial](https://github.com/crazycodeboy/react-native-splash-screen/blob/master/add-LaunchScreen-tutorial-for-ios.md) |
258 | 309 |
|
259 | 310 |
|
| 311 | +### Windows |
| 312 | + |
| 313 | +`react-native-splash-screen` will use the splash screen image and background color defined in the application's `Package.appxmanifest` file. |
| 314 | + |
| 315 | +Since UWP applications already have a splash screen, this makes it so that the splash screen is extended into the `react-native-windows` load process. |
| 316 | + |
| 317 | +To configure the UWP splash screen, open `windows/myapp/Package.appxmanifest` in Visual Studio, open the `Visual Assets` tab and the `Splash Screen` horizontal tab. Add a Splash Screen image and define a background color. |
| 318 | + |
260 | 319 | ## Usage |
261 | 320 |
|
262 | 321 | Use like so: |
|
0 commit comments