react-native-windows 0.76.0-preview.3 → 0.76.0-preview.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.windows.js +15 -15
  2. package/Libraries/Components/Button.windows.js +18 -18
  3. package/Libraries/Components/Flyout/FlyoutNativeComponent.js +5 -1
  4. package/Libraries/Components/Keyboard/KeyboardExt.js +1 -1
  5. package/Libraries/Components/Keyboard/KeyboardExt.js.map +1 -1
  6. package/Libraries/Components/TextInput/TextInput.windows.js +16 -11
  7. package/Libraries/Components/Touchable/Touchable.windows.js +2 -2
  8. package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +5 -3
  9. package/Libraries/Components/View/View.windows.js +1 -3
  10. package/Libraries/Core/ReactNativeVersion.js +1 -1
  11. package/Libraries/Text/Text.windows.js +32 -63
  12. package/Libraries/Utilities/Platform.windows.js +4 -4
  13. package/Microsoft.ReactNative/ReactNativeAppBuilder.cpp +25 -129
  14. package/Microsoft.ReactNative/ReactNativeAppBuilder.h +5 -13
  15. package/Microsoft.ReactNative/ReactNativeAppBuilder.idl +13 -34
  16. package/Microsoft.ReactNative/ReactNativeWin32App.cpp +129 -18
  17. package/Microsoft.ReactNative/ReactNativeWin32App.h +14 -5
  18. package/PropertySheets/External/Microsoft.ReactNative.CppLib.props +17 -0
  19. package/PropertySheets/External/Microsoft.ReactNative.CppLib.targets +17 -0
  20. package/PropertySheets/Generated/PackageVersion.g.props +2 -2
  21. package/PropertySheets/WebView2.props +7 -0
  22. package/PropertySheets/WinUI.props +1 -1
  23. package/Shared/Shared.vcxitems +0 -10
  24. package/just-task.js +1 -1
  25. package/package.json +13 -14
  26. package/templates/cpp-app/template.config.js +8 -3
  27. package/templates/cpp-app/windows/MyApp/MyApp.cpp +46 -131
  28. package/templates/cpp-lib/template.config.js +8 -3
  29. package/templates/cpp-lib/windows/MyLib/MyLib.vcxproj +4 -4
  30. package/templates/templateUtils.js +2 -3
  31. package/Microsoft.ReactNative/ReactInstanceSettingsBuilder.cpp +0 -59
  32. package/Microsoft.ReactNative/ReactInstanceSettingsBuilder.h +0 -23
@@ -8,6 +8,7 @@
8
8
 
9
9
  #include "NativeModules.h"
10
10
 
11
+ // A PackageProvider containing any turbo modules you define within this app project
11
12
  struct CompReactPackageProvider
12
13
  : winrt::implements<CompReactPackageProvider, winrt::Microsoft::ReactNative::IReactPackageProvider> {
13
14
  public: // IReactPackageProvider
@@ -16,152 +17,66 @@ struct CompReactPackageProvider
16
17
  }
17
18
  };
18
19
 
19
- // Global Variables:
20
- constexpr PCWSTR windowTitle = L"{{ mainComponentName }}";
21
- constexpr PCWSTR mainComponentName = L"{{ mainComponentName }}";
22
-
23
- float ScaleFactor(HWND hwnd) noexcept {
24
- return GetDpiForWindow(hwnd) / static_cast<float>(USER_DEFAULT_SCREEN_DPI);
25
- }
20
+ // The entry point of the Win32 application
21
+ _Use_decl_annotations_ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE, PSTR /* commandLine */, int showCmd) {
22
+ // Initialize WinRT
23
+ winrt::init_apartment(winrt::apartment_type::single_threaded);
26
24
 
27
- void UpdateRootViewSizeToAppWindow(
28
- winrt::Microsoft::ReactNative::ReactNativeIsland const &rootView,
29
- winrt::Microsoft::UI::Windowing::AppWindow const &window) {
30
- auto hwnd = winrt::Microsoft::UI::GetWindowFromWindowId(window.Id());
31
- auto scaleFactor = ScaleFactor(hwnd);
32
- winrt::Windows::Foundation::Size size{
33
- window.ClientSize().Width / scaleFactor, window.ClientSize().Height / scaleFactor};
34
- // Do not relayout when minimized
35
- if (window.Presenter().as<winrt::Microsoft::UI::Windowing::OverlappedPresenter>().State() !=
36
- winrt::Microsoft::UI::Windowing::OverlappedPresenterState::Minimized) {
37
- winrt::Microsoft::ReactNative::LayoutConstraints constraints;
38
- constraints.LayoutDirection = winrt::Microsoft::ReactNative::LayoutDirection::Undefined;
39
- constraints.MaximumSize = constraints.MinimumSize = size;
40
- rootView.Arrange(constraints, {0,0});
41
- }
42
- }
25
+ // Enable per monitor DPI scaling
26
+ SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
43
27
 
44
- // Create and configure the ReactNativeHost
45
- winrt::Microsoft::ReactNative::ReactNativeHost CreateReactNativeHost(
46
- HWND hwnd,
47
- const winrt::Microsoft::UI::Composition::Compositor &compositor) {
28
+ // Find the path hosting the app exe file
48
29
  WCHAR appDirectory[MAX_PATH];
49
30
  GetModuleFileNameW(NULL, appDirectory, MAX_PATH);
50
31
  PathCchRemoveFileSpec(appDirectory, MAX_PATH);
51
32
 
52
- auto host = winrt::Microsoft::ReactNative::ReactNativeHost();
53
-
54
- // Include any autolinked modules
55
- RegisterAutolinkedNativeModulePackages(host.PackageProviders());
33
+ // Create a ReactNativeWin32App with the ReactNativeAppBuilder
34
+ auto reactNativeWin32App{winrt::Microsoft::ReactNative::ReactNativeAppBuilder().Build()};
56
35
 
57
- host.PackageProviders().Append(winrt::make<CompReactPackageProvider>());
36
+ // Configure the initial InstanceSettings for the app's ReactNativeHost
37
+ auto settings{reactNativeWin32App.ReactNativeHost().InstanceSettings()};
38
+ // Register any autolinked native modules
39
+ RegisterAutolinkedNativeModulePackages(settings.PackageProviders());
40
+ // Register any native modules defined within this app project
41
+ settings.PackageProviders().Append(winrt::make<CompReactPackageProvider>());
58
42
 
59
43
  #if BUNDLE
60
- host.InstanceSettings().JavaScriptBundleFile(L"index.windows");
61
- host.InstanceSettings().BundleRootPath(std::wstring(L"file://").append(appDirectory).append(L"\\Bundle\\").c_str());
62
- host.InstanceSettings().UseFastRefresh(false);
44
+ // Load the JS bundle from a file (not Metro):
45
+ // Set the path (on disk) where the .bundle file is located
46
+ settings.BundleRootPath(std::wstring(L"file://").append(appDirectory).append(L"\\Bundle\\").c_str());
47
+ // Set the name of the bundle file (without the .bundle extension)
48
+ settings.JavaScriptBundleFile(L"index.windows");
49
+ // Disable hot reload
50
+ settings.UseFastRefresh(false);
63
51
  #else
64
- host.InstanceSettings().JavaScriptBundleFile(L"index");
65
- host.InstanceSettings().UseFastRefresh(true);
52
+ // Load the JS bundle from Metro
53
+ settings.JavaScriptBundleFile(L"index");
54
+ // Enable hot reload
55
+ settings.UseFastRefresh(true);
66
56
  #endif
67
-
68
57
  #if _DEBUG
69
- host.InstanceSettings().UseDirectDebugger(true);
70
- host.InstanceSettings().UseDeveloperSupport(true);
58
+ // For Debug builds
59
+ // Enable Direct Debugging of JS
60
+ settings.UseDirectDebugger(true);
61
+ // Enable the Developer Menu
62
+ settings.UseDeveloperSupport(true);
71
63
  #else
72
- host.InstanceSettings().UseDirectDebugger(false);
73
- host.InstanceSettings().UseDeveloperSupport(false);
64
+ // For Release builds:
65
+ // Disable Direct Debugging of JS
66
+ settings.UseDirectDebugger(false);
67
+ // Disable the Developer Menu
68
+ settings.UseDeveloperSupport(false);
74
69
  #endif
75
70
 
76
- winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
77
- host.InstanceSettings().Properties(), reinterpret_cast<uint64_t>(hwnd));
78
-
79
- winrt::Microsoft::ReactNative::Composition::CompositionUIService::SetCompositor(
80
- host.InstanceSettings(), compositor);
81
-
82
- return host;
83
- }
84
-
85
- _Use_decl_annotations_ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE, PSTR /* commandLine */, int showCmd) {
86
- // Initialize WinRT.
87
- winrt::init_apartment(winrt::apartment_type::single_threaded);
88
-
89
- // Enable per monitor DPI scaling
90
- SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
91
-
92
- // Create a DispatcherQueue for this thread. This is needed for Composition, Content, and
93
- // Input APIs.
94
- auto dispatcherQueueController{winrt::Microsoft::UI::Dispatching::DispatcherQueueController::CreateOnCurrentThread()};
95
-
96
- // Create a Compositor for all Content on this thread.
97
- auto compositor{winrt::Microsoft::UI::Composition::Compositor()};
98
-
99
- // Create a top-level window.
100
- auto window = winrt::Microsoft::UI::Windowing::AppWindow::Create();
101
- window.Title(windowTitle);
102
- window.Resize({1000, 1000});
103
- window.Show();
104
- auto hwnd = winrt::Microsoft::UI::GetWindowFromWindowId(window.Id());
105
- auto scaleFactor = ScaleFactor(hwnd);
106
-
107
- auto host = CreateReactNativeHost(hwnd, compositor);
108
-
109
- // Start the react-native instance, which will create a JavaScript runtime and load the applications bundle
110
- host.ReloadInstance();
111
-
112
- // Create a RootView which will present a react-native component
113
- winrt::Microsoft::ReactNative::ReactViewOptions viewOptions;
114
- viewOptions.ComponentName(mainComponentName);
115
- auto rootView = winrt::Microsoft::ReactNative::ReactNativeIsland(compositor);
116
- rootView.ReactViewHost(winrt::Microsoft::ReactNative::ReactCoreInjection::MakeViewHost(host, viewOptions));
117
-
118
- // Update the size of the RootView when the AppWindow changes size
119
- window.Changed([wkRootView = winrt::make_weak(rootView)](
120
- winrt::Microsoft::UI::Windowing::AppWindow const &window,
121
- winrt::Microsoft::UI::Windowing::AppWindowChangedEventArgs const &args) {
122
- if (args.DidSizeChange() || args.DidVisibilityChange()) {
123
- if (auto rootView = wkRootView.get()) {
124
- UpdateRootViewSizeToAppWindow(rootView, window);
125
- }
126
- }
127
- });
128
-
129
- // Quit application when main window is closed
130
- window.Destroying(
131
- [host](winrt::Microsoft::UI::Windowing::AppWindow const &window, winrt::IInspectable const & /*args*/) {
132
- // Before we shutdown the application - unload the ReactNativeHost to give the javascript a chance to save any
133
- // state
134
- auto async = host.UnloadInstance();
135
- async.Completed([host](auto asyncInfo, winrt::Windows::Foundation::AsyncStatus asyncStatus) {
136
- asyncStatus;
137
- assert(asyncStatus == winrt::Windows::Foundation::AsyncStatus::Completed);
138
- host.InstanceSettings().UIDispatcher().Post([]() { PostQuitMessage(0); });
139
- });
140
- });
141
-
142
- // DesktopChildSiteBridge create a ContentSite that can host the RootView ContentIsland
143
- auto bridge = winrt::Microsoft::UI::Content::DesktopChildSiteBridge::Create(compositor, window.Id());
144
- bridge.Connect(rootView.Island());
145
- bridge.ResizePolicy(winrt::Microsoft::UI::Content::ContentSizePolicy::ResizeContentToParentWindow);
146
-
147
- rootView.ScaleFactor(scaleFactor);
148
-
149
- // Set the intialSize of the root view
150
- UpdateRootViewSizeToAppWindow(rootView, window);
151
-
152
- bridge.Show();
153
-
154
- // Run the main application event loop
155
- dispatcherQueueController.DispatcherQueue().RunEventLoop();
156
-
157
- // Rundown the DispatcherQueue. This drains the queue and raises events to let components
158
- // know the message loop has finished.
159
- dispatcherQueueController.ShutdownQueue();
71
+ // Get the AppWindow so we can configure its initial title and size
72
+ auto appWindow{reactNativeWin32App.AppWindow()};
73
+ appWindow.Title(L"{{ mainComponentName }}");
74
+ appWindow.Resize({1000, 1000});
160
75
 
161
- bridge.Close();
162
- bridge = nullptr;
76
+ // Get the ReactViewOptions so we can set the initial RN component to load
77
+ auto viewOptions{reactNativeWin32App.ReactViewOptions()};
78
+ viewOptions.ComponentName(L"{{ mainComponentName }}");
163
79
 
164
- // Destroy all Composition objects
165
- compositor.Close();
166
- compositor = nullptr;
80
+ // Start the app
81
+ reactNativeWin32App.Start();
167
82
  }
@@ -76,7 +76,10 @@ async function getFileMappings(config = {}, options = {}) {
76
76
  );
77
77
 
78
78
  const projectRoot = libConfig.root ?? process.cwd();
79
- const {rnwPath, rnwVersion, devMode, isCanary} = templateUtils.getRnwInfo(libConfig, libOptions);
79
+ const {rnwPath, rnwVersion, devMode, isCanary} = templateUtils.getRnwInfo(
80
+ libConfig,
81
+ libOptions,
82
+ );
80
83
 
81
84
  const projectName =
82
85
  libConfig?.project?.windows?.projects[0]?.projectName ??
@@ -102,7 +105,9 @@ async function getFileMappings(config = {}, options = {}) {
102
105
  namespaceCpp: namespaceCpp,
103
106
 
104
107
  rnwVersion: rnwVersion,
105
- rnwPathFromProjectRoot: path.relative(projectRoot, rnwPath).replace(/\//g, '\\'),
108
+ rnwPathFromProjectRoot: path
109
+ .relative(projectRoot, rnwPath)
110
+ .replace(/\//g, '\\'),
106
111
 
107
112
  // Visual Studio is very picky about the casing of the guids for projects, project references and the solution
108
113
  // https://www.bing.com/search?q=visual+studio+project+guid+casing&cvid=311a5ad7f9fc41089507b24600d23ee7&FORM=ANAB01&PC=U531
@@ -115,7 +120,7 @@ async function getFileMappings(config = {}, options = {}) {
115
120
  devMode,
116
121
 
117
122
  useNuGets: !devMode, // default is to use published NuGets except in devMode, change to true here if you want to test devMode and nugets simultaneously
118
- addReactNativePublicAdoFeed: isCanary,
123
+ addReactNativePublicAdoFeed: true || isCanary, // Temporary true for all new projects until code-signing is restored, see issue #14030
119
124
 
120
125
  cppNugetPackages,
121
126
  };
@@ -66,7 +66,7 @@
66
66
  <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67
67
  </ImportGroup>
68
68
  <ImportGroup Label="ReactNativeWindowsPropertySheets">
69
- <Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.props" />
69
+ <Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" />
70
70
  </ImportGroup>
71
71
  <ItemDefinitionGroup>
72
72
  <ClCompile>
@@ -131,7 +131,7 @@
131
131
  </ItemGroup>
132
132
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
133
133
  <ImportGroup Label="ReactNativeWindowsTargets">
134
- <Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets')" />
134
+ <Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" />
135
135
  </ImportGroup>
136
136
  <ItemGroup>
137
137
  {{#cppNugetPackages}}
@@ -142,7 +142,7 @@
142
142
  <PropertyGroup>
143
143
  <ErrorText>This project references targets in your node_modules\react-native-windows folder. The missing file is {0}.</ErrorText>
144
144
  </PropertyGroup>
145
- <Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.props'))" />
146
- <Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets'))" />
145
+ <Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props'))" />
146
+ <Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets'))" />
147
147
  </Target>
148
148
  </Project>
@@ -112,9 +112,8 @@ async function runNpmInstall(config = {}, options = {}) {
112
112
 
113
113
  async function updateProjectPackageJson(config = {}, options = {}, props = {}) {
114
114
  const projectRoot = config?.root ?? process.cwd();
115
- const projectPackage = await pkgUtils.WritableNpmPackage.fromPath(
116
- projectRoot,
117
- );
115
+ const projectPackage =
116
+ await pkgUtils.WritableNpmPackage.fromPath(projectRoot);
118
117
 
119
118
  if (!projectPackage) {
120
119
  throw new Error(
@@ -1,59 +0,0 @@
1
- #include "pch.h"
2
- #include "ReactInstanceSettingsBuilder.h"
3
- #include "ReactInstanceSettingsBuilder.g.cpp"
4
- #include "ReactInstanceSettings.h"
5
-
6
- namespace winrt::ReactNative {
7
- using namespace winrt::Microsoft::ReactNative;
8
- }
9
-
10
- namespace winrt::UI {
11
- using namespace winrt::Microsoft::UI;
12
- }
13
-
14
- namespace winrt::Microsoft::ReactNative::implementation {
15
- ReactInstanceSettingsBuilder::ReactInstanceSettingsBuilder() {
16
- m_reactInstanceSettings = winrt::make<winrt::ReactNative::implementation::ReactInstanceSettings>();
17
- }
18
-
19
- winrt::ReactNative::ReactInstanceSettings ReactInstanceSettingsBuilder::ReactInstanceSettings() {
20
- return m_reactInstanceSettings;
21
- }
22
-
23
- winrt::ReactNative::ReactInstanceSettingsBuilder ReactInstanceSettingsBuilder::UseDirectDebugger(bool const &state) {
24
- m_reactInstanceSettings.UseDirectDebugger(state);
25
-
26
- return *this;
27
- }
28
-
29
- winrt::ReactNative::ReactInstanceSettingsBuilder ReactInstanceSettingsBuilder::UseDeveloperSupport(bool const &state) {
30
- m_reactInstanceSettings.UseDeveloperSupport(state);
31
-
32
- return *this;
33
- }
34
-
35
- winrt::ReactNative::ReactInstanceSettingsBuilder ReactInstanceSettingsBuilder::BundleRootPath(hstring const &path) {
36
- m_reactInstanceSettings.BundleRootPath(std::wstring(L"file://").append(path.c_str()).append(L"\\Bundle\\").c_str());
37
-
38
- return *this;
39
- }
40
-
41
- winrt::ReactNative::ReactInstanceSettingsBuilder ReactInstanceSettingsBuilder::DebugBundlePath(hstring const &path) {
42
- m_reactInstanceSettings.DebugBundlePath(path.c_str());
43
-
44
- return *this;
45
- }
46
-
47
- winrt::ReactNative::ReactInstanceSettingsBuilder ReactInstanceSettingsBuilder::JavaScriptBundleFile(
48
- hstring const &file) {
49
- m_reactInstanceSettings.JavaScriptBundleFile(file.c_str());
50
-
51
- return *this;
52
- }
53
-
54
- winrt::ReactNative::ReactInstanceSettingsBuilder ReactInstanceSettingsBuilder::UseFastRefresh(bool const &state) {
55
- m_reactInstanceSettings.UseFastRefresh(state);
56
-
57
- return *this;
58
- }
59
- } // namespace winrt::Microsoft::ReactNative::implementation
@@ -1,23 +0,0 @@
1
- #pragma once
2
- #include "ReactInstanceSettingsBuilder.g.h"
3
-
4
- namespace winrt::Microsoft::ReactNative::implementation {
5
- struct ReactInstanceSettingsBuilder : ReactInstanceSettingsBuilderT<ReactInstanceSettingsBuilder> {
6
- ReactInstanceSettingsBuilder();
7
-
8
- winrt::Microsoft::ReactNative::ReactInstanceSettings ReactInstanceSettings();
9
- winrt::Microsoft::ReactNative::ReactInstanceSettingsBuilder UseDirectDebugger(bool const &state);
10
- winrt::Microsoft::ReactNative::ReactInstanceSettingsBuilder UseDeveloperSupport(bool const &state);
11
- winrt::Microsoft::ReactNative::ReactInstanceSettingsBuilder BundleRootPath(hstring const &path);
12
- winrt::Microsoft::ReactNative::ReactInstanceSettingsBuilder DebugBundlePath(hstring const &path);
13
- winrt::Microsoft::ReactNative::ReactInstanceSettingsBuilder JavaScriptBundleFile(hstring const &file);
14
- winrt::Microsoft::ReactNative::ReactInstanceSettingsBuilder UseFastRefresh(bool const &state);
15
-
16
- private:
17
- winrt::Microsoft::ReactNative::ReactInstanceSettings m_reactInstanceSettings{nullptr};
18
- };
19
- } // namespace winrt::Microsoft::ReactNative::implementation
20
- namespace winrt::Microsoft::ReactNative::factory_implementation {
21
- struct ReactInstanceSettingsBuilder
22
- : ReactInstanceSettingsBuilderT<ReactInstanceSettingsBuilder, implementation::ReactInstanceSettingsBuilder> {};
23
- } // namespace winrt::Microsoft::ReactNative::factory_implementation