Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "none",
"comment": "Removed MainReactNativeHost from samples and use ReactApplication properties instead.",
"packageName": "react-native-windows",
"email": "vmorozov@microsoft.com",
"commit": "4562d6f570094dd439e7d5be225ffc11141c14c0",
"date": "2019-10-23T16:21:59.944Z",
"file": "c:\\git\\vmoroz\\react-native-windows\\change\\react-native-windows-2019-10-23-09-22-00-ReactApplication.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@
#include "pch.h"

#include "App.h"
#include "ReactPackageProvider.h"
#include "winrt/SampleLibraryCPP.h"
#include "winrt/SampleLibraryCS.h"

using namespace winrt;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Foundation;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
using namespace SampleApp;
using namespace SampleApp::implementation;
namespace winrt::SampleApp::implementation {

/// <summary>
/// Initializes the singleton application object. This is the first line of
/// authored code executed, and as such is the logical equivalent of main() or
/// WinMain().
/// </summary>
App::App() {
App::App() noexcept {
MainComponentName(L"SampleApp");
JavaScriptMainModuleName(L"index.windows");

PackageProviders().Append(
make<ReactPackageProvider>()); // Includes all modules in this project
PackageProviders().Append(winrt::SampleLibraryCPP::ReactPackageProvider());
PackageProviders().Append(winrt::SampleLibraryCS::ReactPackageProvider());

InitializeComponent();

// This works around a cpp/winrt bug with composable/aggregable types tracked
// by 22116519
AddRef();
m_inner.as<::IUnknown>()->Release();
}

} // namespace winrt::SampleApp::implementation
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
#pragma once
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once

#include "App.xaml.g.h"

#include "MainReactNativeHost.h"

namespace winrt::SampleApp::implementation {
struct App : AppT<App> {
App();

winrt::Microsoft::ReactNative::ReactNativeHost HostCore() {
if (m_host == nullptr) {
m_host =
winrt::make<winrt::SampleApp::implementation::MainReactNativeHost>();
}

return m_host;
}

private:
winrt::SampleApp::MainReactNativeHost m_host{};
struct App : AppT<App> {
App() noexcept;
};

} // namespace winrt::SampleApp::implementation

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="DebugConsole.h" />
<ClInclude Include="MainReactNativeHost.h">
<DependentUpon>MainReactNativeHost.idl</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="ReactPackageProvider.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="App.h">
Expand Down Expand Up @@ -137,10 +133,6 @@
<Image Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="MainReactNativeHost.cpp">
<DependentUpon>MainReactNativeHost.idl</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="ReactPackageProvider.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
Expand All @@ -154,9 +146,6 @@
<Midl Include="App.idl">
<DependentUpon>App.xaml</DependentUpon>
</Midl>
<Midl Include="MainReactNativeHost.idl">
<SubType>Designer</SubType>
</Midl>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</ItemGroup>
<ItemGroup>
<Midl Include="App.idl" />
<Midl Include="MainReactNativeHost.idl" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@

namespace SampleApp
{
/// <summary>
/// Provides application-specific behavior to supplement the default
/// Application class.
/// </summary>
sealed partial class App : ReactApplication
{
private MainReactNativeHost _host = new MainReactNativeHost();

/// <summary>
/// Initializes the singleton application object. This is the first line
/// of authored code executed, and as such is the logical equivalent of
/// main() or WinMain().
/// Provides application-specific behavior to supplement the default
/// Application class.
/// </summary>
public App()
sealed partial class App : ReactApplication
{
this.InitializeComponent();
}
/// <summary>
/// Initializes the singleton application object. This is the first line
/// of authored code executed, and as such is the logical equivalent of
/// main() or WinMain().
/// </summary>
public App()
{
MainComponentName = "SampleApp";
JavaScriptMainModuleName = "index.windows";

protected override ReactNativeHost HostCore => _host;
}
PackageProviders.Add(new Microsoft.ReactNative.Managed.LocalPackageProvider()); // Includes any modules in this project
PackageProviders.Add(new SampleLibraryCS.ReactPackageProvider());
PackageProviders.Add(new SampleLibraryCPP.ReactPackageProvider());

InitializeComponent();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="DebugConsole.cs" />
<Compile Include="MainReactNativeHost.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
55 changes: 44 additions & 11 deletions vnext/Microsoft.ReactNative/ReactApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

#include "pch.h"
#include "ReactApplication.h"
#if __has_include("ReactApplication.g.cpp")
#include "ReactApplication.g.cpp"
#endif
#include "ReactNativeHost.h"

#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.UI.Core.h>

using namespace winrt;
using namespace Microsoft::ReactNative;
using namespace Windows::ApplicationModel;
Expand All @@ -19,8 +20,8 @@ using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;

namespace winrt::Microsoft::ReactNative::implementation {
ReactApplication::ReactApplication()
: m_delegate(CreateReactApplicationDelegate()) {

ReactApplication::ReactApplication() noexcept {
Suspending({this, &ReactApplication::OnSuspending});

#if defined _DEBUG && \
Expand All @@ -35,17 +36,39 @@ ReactApplication::ReactApplication()
#endif
}

Microsoft::ReactNative::ReactNativeHost ReactApplication::Host() {
if (m_host == nullptr) {
m_host = overridable().HostCore();
Microsoft::ReactNative::ReactInstanceSettings
ReactApplication::InstanceSettings() noexcept {
if (!m_instanceSettings) {
m_instanceSettings = make<ReactInstanceSettings>();
m_instanceSettings.UseWebDebugger(false);
m_instanceSettings.UseLiveReload(true);
m_instanceSettings.UseJsi(true);
m_instanceSettings.EnableDeveloperMenu(REACT_DEFAULT_ENABLE_DEVELOPER_MENU);
}

return m_host;
return m_instanceSettings;
}

IVector<IReactPackageProvider> ReactApplication::PackageProviders() noexcept {
if (!m_packageProviders) {
m_packageProviders = single_threaded_vector<IReactPackageProvider>();
}

return m_packageProviders;
}

Microsoft::ReactNative::ReactNativeHost ReactApplication::HostCore() {
throw hresult_not_implemented(
L"You must implement ReactApplication.HostCore.");
Microsoft::ReactNative::ReactNativeHost ReactApplication::Host() noexcept {
if (!m_host) {
m_host = make<ReactNativeHost>();
m_host.InstanceSettings(InstanceSettings());
m_host.PackageProviders(PackageProviders());
m_host.MainComponentName(MainComponentName());
m_host.UseDeveloperSupport(UseDeveloperSupport());
m_host.JavaScriptMainModuleName(JavaScriptMainModuleName());
m_host.JavaScriptBundleFile(JavaScriptBundleFile());
}

return m_host;
}

void ReactApplication::OnLaunched(LaunchActivatedEventArgs const &e) {
Expand All @@ -61,6 +84,10 @@ void ReactApplication::OnLaunched(LaunchActivatedEventArgs const &e) {
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
void ReactApplication::OnCreate(LaunchActivatedEventArgs const &e) {
if (!m_delegate) {
m_delegate = CreateReactApplicationDelegate();
}

#if defined _DEBUG
if (IsDebuggerPresent()) {
this->DebugSettings().EnableFrameRateCounter(TRUE);
Expand Down Expand Up @@ -145,4 +172,10 @@ void ReactApplication::OnNavigationFailed(
throw hresult_error(
E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name);
}

ReactApplicationDelegate __stdcall ReactApplication::
CreateReactApplicationDelegate() {
return winrt::Microsoft::ReactNative::ReactApplicationDelegate(*this);
}

} // namespace winrt::Microsoft::ReactNative::implementation
Loading