From 91fe2edabfb2f2dc618d5a23e7e03c1a49b6b933 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Mon, 27 Apr 2020 14:39:57 -0700 Subject: [PATCH 01/12] Start converting playground win32 to MS.RN. --- .../playground/windows/playground-win32.sln | 84 ++++++----- .../playground-win32/Playground-Win32.cpp | 131 ++++++++++++++---- .../playground-win32/Playground-win32.vcxproj | 59 +++++--- .../windows/playground-win32/packages.config | 1 + 4 files changed, 192 insertions(+), 83 deletions(-) diff --git a/packages/playground/windows/playground-win32.sln b/packages/playground/windows/playground-win32.sln index 8b30f151e52..9e1f6df9976 100644 --- a/packages/playground/windows/playground-win32.sln +++ b/packages/playground/windows/playground-win32.sln @@ -7,11 +7,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Playground-Win32", "playgro EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Folly", "..\..\..\vnext\Folly\Folly.vcxproj", "{A990658C-CE31-4BCC-976F-0FC6B1AF693D}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReactUWP", "..\..\..\vnext\ReactUWP\ReactUWP.vcxproj", "{2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}" - ProjectSection(ProjectDependencies) = postProject - {A990658C-CE31-4BCC-976F-0FC6B1AF693D} = {A990658C-CE31-4BCC-976F-0FC6B1AF693D} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReactCommon", "..\..\..\vnext\ReactCommon\ReactCommon.vcxproj", "{A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}" ProjectSection(ProjectDependencies) = postProject {A990658C-CE31-4BCC-976F-0FC6B1AF693D} = {A990658C-CE31-4BCC-976F-0FC6B1AF693D} @@ -22,28 +17,41 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReactWindowsCore", "..\..\. {A990658C-CE31-4BCC-976F-0FC6B1AF693D} = {A990658C-CE31-4BCC-976F-0FC6B1AF693D} EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PropertySheets", "PropertySheets", "{6F24927E-EE45-4DB2-91DA-DCC6E98B0C42}" - ProjectSection(SolutionItems) = preProject - ..\..\..\vnext\PropertySheets\ARM.props = ..\..\..\vnext\PropertySheets\ARM.props - ..\..\..\vnext\PropertySheets\Debug.props = ..\..\..\vnext\PropertySheets\Debug.props - ..\..\..\vnext\PropertySheets\React.Cpp.props = ..\..\..\vnext\PropertySheets\React.Cpp.props - ..\..\..\vnext\PropertySheets\Release.props = ..\..\..\vnext\PropertySheets\Release.props - ..\..\..\vnext\PropertySheets\Warnings.props = ..\..\..\vnext\PropertySheets\Warnings.props - ..\..\..\vnext\PropertySheets\Win32.props = ..\..\..\vnext\PropertySheets\Win32.props - ..\..\..\vnext\PropertySheets\x64.props = ..\..\..\vnext\PropertySheets\x64.props - ..\..\..\vnext\PropertySheets\x86.props = ..\..\..\vnext\PropertySheets\x86.props - EndProjectSection +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chakra", "..\..\..\vnext\Chakra\Chakra.vcxitems", "{C38970C0-5FBF-4D69-90D8-CBAC225AE895}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.ReactNative", "..\..\..\vnext\Microsoft.ReactNative\Microsoft.ReactNative.vcxproj", "{F7D32BD0-2749-483E-9A0D-1635EF7E3136}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JSI.Shared", "..\..\..\vnext\JSI\Shared\JSI.Shared.vcxitems", "{0CC28589-39E4-4288-B162-97B959F8B843}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JSI.Universal", "..\..\..\vnext\JSI\Universal\JSI.Universal.vcxproj", "{A62D504A-16B8-41D2-9F19-E2E86019E5E4}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.ReactNative.Cxx", "..\..\..\vnext\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems", "{DA8B35B3-DA00-4B02-BDE6-6A397B3FD46B}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.ReactNative.SharedManaged", "..\..\..\vnext\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.shproj", "{67A1076F-7790-4203-86EA-4402CCB5E782}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "..\..\..\vnext\Common\Common.vcxproj", "{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ReactNative", "ReactNative", "{5EA20F54-880A-49F3-99FA-4B3FE54E8AB1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Shared", "..\..\..\vnext\Shared\Shared.vcxitems", "{2049DBE9-8D13-42C9-AE4B-413AE38FFFD0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mso", "..\..\..\vnext\Mso\Mso.vcxitems", "{84E05BFA-CBAF-4F0D-BFB6-4CE85742A57E}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution - ..\..\..\vnext\Chakra\Chakra.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4 - ..\..\..\vnext\Mso\Mso.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4 - ..\..\..\vnext\Shared\Shared.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4 + ..\..\..\vnext\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9 + ..\..\..\vnext\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9 + ..\..\..\vnext\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13 + ..\..\..\vnext\Mso\Mso.vcxitems*{84e05bfa-cbaf-4f0d-bfb6-4ce85742a57e}*SharedItemsImports = 9 + ..\..\..\vnext\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{8b88ffae-4dbc-49a2-afa5-d2477d4ad189}*SharedItemsImports = 4 ..\..\..\vnext\JSI\Shared\JSI.Shared.vcxitems*{a62d504a-16b8-41d2-9f19-e2e86019e5e4}*SharedItemsImports = 4 + ..\..\..\vnext\Chakra\Chakra.vcxitems*{c38970c0-5fbf-4d69-90d8-cbac225ae895}*SharedItemsImports = 9 + ..\..\..\vnext\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{da8b35b3-da00-4b02-bde6-6a397b3fd46b}*SharedItemsImports = 9 + ..\..\..\vnext\Chakra\Chakra.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4 + ..\..\..\vnext\JSI\Shared\JSI.Shared.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4 + ..\..\..\vnext\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4 + ..\..\..\vnext\Mso\Mso.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4 + ..\..\..\vnext\Shared\Shared.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4 EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -84,18 +92,6 @@ Global {A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|x64.Build.0 = Release|x64 {A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|x86.ActiveCfg = Release|Win32 {A990658C-CE31-4BCC-976F-0FC6B1AF693D}.Release|x86.Build.0 = Release|Win32 - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Debug|ARM.ActiveCfg = Debug|ARM - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Debug|ARM.Build.0 = Debug|ARM - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Debug|x64.ActiveCfg = Debug|x64 - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Debug|x64.Build.0 = Debug|x64 - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Debug|x86.ActiveCfg = Debug|Win32 - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Debug|x86.Build.0 = Debug|Win32 - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Release|ARM.ActiveCfg = Release|ARM - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Release|ARM.Build.0 = Release|ARM - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Release|x64.ActiveCfg = Release|x64 - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Release|x64.Build.0 = Release|x64 - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Release|x86.ActiveCfg = Release|Win32 - {2D5D43D9-CFFC-4C40-B4CD-02EFB4E2742B}.Release|x86.Build.0 = Release|Win32 {A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|ARM.ActiveCfg = Debug|ARM {A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|ARM.Build.0 = Debug|ARM {A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD}.Debug|x64.ActiveCfg = Debug|x64 @@ -120,6 +116,18 @@ Global {11C084A3-A57C-4296-A679-CAC17B603144}.Release|x64.Build.0 = Release|x64 {11C084A3-A57C-4296-A679-CAC17B603144}.Release|x86.ActiveCfg = Release|Win32 {11C084A3-A57C-4296-A679-CAC17B603144}.Release|x86.Build.0 = Release|Win32 + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|ARM.ActiveCfg = Debug|ARM + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|ARM.Build.0 = Debug|ARM + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|x64.ActiveCfg = Debug|x64 + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|x64.Build.0 = Debug|x64 + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|x86.ActiveCfg = Debug|Win32 + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Debug|x86.Build.0 = Debug|Win32 + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|ARM.ActiveCfg = Release|ARM + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|ARM.Build.0 = Release|ARM + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x64.ActiveCfg = Release|x64 + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x64.Build.0 = Release|x64 + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x86.ActiveCfg = Release|Win32 + {F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x86.Build.0 = Release|Win32 {A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|ARM.ActiveCfg = Debug|ARM {A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|ARM.Build.0 = Debug|ARM {A62D504A-16B8-41D2-9F19-E2E86019E5E4}.Debug|x64.ActiveCfg = Debug|x64 @@ -148,6 +156,20 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {A990658C-CE31-4BCC-976F-0FC6B1AF693D} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {A9D95A91-4DB7-4F72-BEB6-FE8A5C89BFBD} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {11C084A3-A57C-4296-A679-CAC17B603144} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {C38970C0-5FBF-4D69-90D8-CBAC225AE895} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {F7D32BD0-2749-483E-9A0D-1635EF7E3136} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {0CC28589-39E4-4288-B162-97B959F8B843} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {A62D504A-16B8-41D2-9F19-E2E86019E5E4} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {DA8B35B3-DA00-4B02-BDE6-6A397B3FD46B} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {67A1076F-7790-4203-86EA-4402CCB5E782} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {FCA38F3C-7C73-4C47-BE4E-32F77FA8538D} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {2049DBE9-8D13-42C9-AE4B-413AE38FFFD0} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + {84E05BFA-CBAF-4F0D-BFB6-4CE85742A57E} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F5EAF3BA-6B6F-4E81-B5C6-49B30EC0A32E} EndGlobalSection diff --git a/packages/playground/windows/playground-win32/Playground-Win32.cpp b/packages/playground/windows/playground-win32/Playground-Win32.cpp index 04539cdf0dc..50195183202 100644 --- a/packages/playground/windows/playground-win32/Playground-Win32.cpp +++ b/packages/playground/windows/playground-win32/Playground-Win32.cpp @@ -5,15 +5,6 @@ #include #include -#include -#include -#include -#include - -#include - -#include -#include #include #include @@ -21,14 +12,18 @@ #pragma push_macro("GetCurrentTime") #undef GetCurrentTime +#include + #include + +#include #include #include #pragma pop_macro("GetCurrentTime") +/* namespace { - std::string GetAsyncLocalStorageDBPath() { winrt::com_array localAppData; winrt::check_hresult(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, put_abi(localAppData))); @@ -46,11 +41,13 @@ std::string GetAsyncLocalStorageDBPath() { } } // namespace +*/ namespace WUX = winrt::Windows::UI::Xaml; namespace WUXC = WUX::Controls; namespace WUXH = WUX::Hosting; +/* struct PlaygroundNativeModuleProvider final : facebook::react::NativeModuleProvider { virtual std::vector GetModules( const std::shared_ptr &defaultQueueThread) override { @@ -69,6 +66,7 @@ class PlaygroundViewManagerProvider final : public react::uwp::ViewManagerProvid } }; + struct HwndReactInstanceCreator : ::react::uwp::IReactInstanceCreator { HwndReactInstanceCreator(HWND hwnd) { m_hwnd = hwnd; @@ -88,6 +86,7 @@ struct HwndReactInstanceCreator : ::react::uwp::IReactInstanceCreator { private: HWND m_hwnd; }; +*/ struct WindowData { static HINSTANCE s_instance; @@ -95,9 +94,15 @@ struct WindowData { std::wstring m_bundleFile; WUXH::DesktopWindowXamlSource m_desktopWindowXamlSource; - std::shared_ptr m_instance; - std::shared_ptr m_rootView; - std::shared_ptr m_instanceCreator; + + winrt::Microsoft::ReactNative::ReactRootView m_reactRootView; + winrt::Microsoft::ReactNative::ReactNativeHost m_host; + winrt::Microsoft::ReactNative::ReactInstanceSettings m_instanceSettings; + winrt::Windows::Foundation::Collections::IVector m_packageProviders; + + //std::shared_ptr m_instance; + //std::shared_ptr m_rootView; + //std::shared_ptr m_instanceCreator; bool m_useWebDebugger{true}; bool m_liveReloadEnabled{true}; @@ -106,7 +111,7 @@ struct WindowData { bool m_breakOnNextLine{false}; uint16_t m_debuggerPort{defaultDebuggerPort}; - react::uwp::JSIEngine m_jsEngine{react::uwp::JSIEngine::Chakra}; + //react::uwp::JSIEngine m_jsEngine{react::uwp::JSIEngine::Chakra}; WindowData(const WUXH::DesktopWindowXamlSource &desktopWindowXamlSource) : m_desktopWindowXamlSource(desktopWindowXamlSource) {} @@ -115,22 +120,86 @@ struct WindowData { return reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); } - LRESULT OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT) { + winrt::Microsoft::ReactNative::ReactNativeHost Host() noexcept + { + if (!m_host) { + m_host = winrt::Microsoft::ReactNative::ReactNativeHost(); + m_host.InstanceSettings(InstanceSettings()); + m_host.PackageProviders(PackageProviders()); + } + + return m_host; + } + winrt::Microsoft::ReactNative::ReactInstanceSettings InstanceSettings() noexcept + { + if (!m_instanceSettings) { + m_instanceSettings = winrt::Microsoft::ReactNative::ReactInstanceSettings(); + } + + return m_instanceSettings; + + } + + + winrt::Windows::Foundation::Collections::IVector + PackageProviders() noexcept + { + if (!m_packageProviders) { + m_packageProviders = winrt::single_threaded_vector(); + } + + return m_packageProviders; + + } + + + LRESULT OnCommand(HWND hwnd, int id, HWND /* hwndCtl*/ , UINT) { switch (id) { case IDM_OPENJSFILE: { DialogBox(s_instance, MAKEINTRESOURCE(IDD_OPENJSBUNDLEBOX), hwnd, &Bundle); if (!m_bundleFile.empty()) { + /* facebook::react::InitializeLogging( [](facebook::react::RCTLogLevel logLevel, const char *message) { OutputDebugStringA(message); }); + */ // Create NativeModuleProvider - std::shared_ptr moduleLoader = + /* + std::shared_ptr moduleLoader = std::make_shared(); std::shared_ptr viewManagerProvider = std::make_shared(); + m_instance = react::uwp::CreateReactInstance(moduleLoader, viewManagerProvider); + */ + + PCWSTR appName = (m_bundleFile == LR"(Samples\rntester)") ? L"RNTesterApp" : L"Bootstrap"; + + auto host = Host(); + host.InstanceSettings().JavaScriptBundleFile(m_bundleFile); + host.InstanceSettings().MainComponentName(appName); + host.InstanceSettings().UseWebDebugger(m_useWebDebugger); + host.InstanceSettings().UseDirectDebugger(m_useDirectDebugger); + host.InstanceSettings().DebuggerBreakOnNextLine(m_breakOnNextLine); + host.InstanceSettings().UseFastRefresh(m_liveReloadEnabled); + host.InstanceSettings().DebuggerPort(m_debuggerPort); + + // Nudge the ReactNativeHost to create the instance and wrapping context + host.ReloadInstance(); + + m_reactRootView = winrt::Microsoft::ReactNative::ReactRootView(); + m_reactRootView.ComponentName(host.InstanceSettings().MainComponentName()); + m_reactRootView.ReactNativeHost(host); + + // Retrieve ABI pointer from C++/CX pointer + auto rootElement = m_desktopWindowXamlSource.Content().as(); + rootElement.Children().Clear(); + rootElement.Children().Append(m_reactRootView); + + /* + react::uwp::ReactInstanceSettings settings; settings.UseWebDebugger = m_useWebDebugger; @@ -152,10 +221,8 @@ struct WindowData { folly::dynamic initialProps = folly::dynamic::object(); - // Retrieve ABI pointer from C++/CX pointer - auto rootElement = m_desktopWindowXamlSource.Content().as(); - PCWSTR appName = (m_bundleFile == LR"(Samples\rntester)") ? L"RNTesterApp" : L"Bootstrap"; + // Create the root view m_rootView = react::uwp::CreateReactRootView(rootElement, appName, m_instanceCreator); @@ -163,6 +230,7 @@ struct WindowData { m_rootView->SetInitialProps(std::move(initialProps)); m_rootView->SetInstanceCreator(m_instanceCreator); m_rootView->AttachRoot(); + */ } break; @@ -193,16 +261,18 @@ struct WindowData { SetWindowPos(hWndXamlIsland, nullptr, 0, 0, createStruct->cx, createStruct->cy, SWP_SHOWWINDOW); + /* try { m_instanceCreator = std::make_shared(hwnd); } catch (...) { return -1; } + */ return 0; } - LRESULT OnWindowPosChanged(HWND hwnd, const WINDOWPOS *windowPosition) { + LRESULT OnWindowPosChanged(HWND /* hwnd */, const WINDOWPOS *windowPosition) { auto interop = m_desktopWindowXamlSource.as(); HWND interopHwnd; winrt::check_hresult(interop->get_WindowHandle(&interopHwnd)); @@ -213,7 +283,7 @@ struct WindowData { } /// Message handler for about box. - static INT_PTR CALLBACK About(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) noexcept { + static INT_PTR CALLBACK About(HWND hwnd, UINT message, WPARAM wparam, LPARAM /* lparam */) noexcept { switch (message) { case WM_INITDIALOG: return TRUE; @@ -242,7 +312,7 @@ struct WindowData { LR"(Samples\view)", }; - static INT_PTR CALLBACK Bundle(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) noexcept { + static INT_PTR CALLBACK Bundle(HWND hwnd, UINT message, WPARAM wparam, LPARAM /*lparam*/) noexcept { switch (message) { case WM_INITDIALOG: { HWND hwndListBox = GetDlgItem(hwnd, IDC_JSBUNDLELIST); @@ -291,7 +361,7 @@ struct WindowData { SendMessageW(cmbEngines, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)TEXT("Chakra")); SendMessageW(cmbEngines, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)TEXT("Hermes")); SendMessageW(cmbEngines, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)TEXT("V8")); - SendMessageW(cmbEngines, CB_SETCURSEL, (WPARAM) static_cast(self->m_jsEngine), (LPARAM)0); + // SendMessageW(cmbEngines, CB_SETCURSEL, (WPARAM) static_cast(self->m_jsEngine), (LPARAM)0); return TRUE; } @@ -313,7 +383,7 @@ struct WindowData { auto port = std::stoi(buffer); if (port > UINT16_MAX) port = defaultDebuggerPort; - self->m_debuggerPort = port; + self->m_debuggerPort = static_cast(port); } catch (const std::out_of_range &) { self->m_debuggerPort = defaultDebuggerPort; } catch (const std::invalid_argument &) { @@ -321,9 +391,9 @@ struct WindowData { // (E.g. includes letters or symbols). } - auto cmbEngines = GetDlgItem(hwnd, IDC_JSENGINE); - int itemIndex = (int)SendMessageW(cmbEngines, (UINT)CB_GETCURSEL, (WPARAM)0, (LPARAM)0); - self->m_jsEngine = static_cast(itemIndex); + // auto cmbEngines = GetDlgItem(hwnd, IDC_JSENGINE); + // int itemIndex = (int)SendMessageW(cmbEngines, (UINT)CB_GETCURSEL, (WPARAM)0, (LPARAM)0); + // self->m_jsEngine = static_cast(itemIndex); } [[fallthrough]]; case IDCANCEL: @@ -341,6 +411,7 @@ struct WindowData { extern "C" IMAGE_DOS_HEADER __ImageBase; HINSTANCE WindowData::s_instance = reinterpret_cast(&__ImageBase); +/* std::shared_ptr<::react::uwp::IReactInstance> HwndReactInstanceCreator::getInstance() { if (!m_hwnd) return nullptr; @@ -385,6 +456,8 @@ void HwndReactInstanceCreator::persistBreakOnNextLine(bool breakOnNextLine) { WindowData::GetFromWindow(m_hwnd)->m_breakOnNextLine = breakOnNextLine; } +*/ + LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) noexcept { switch (message) { case WM_CREATE: { @@ -415,13 +488,13 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) return DefWindowProc(hwnd, message, wparam, lparam); } -_Use_decl_annotations_ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE, PSTR commandLine, int showCmd) { +_Use_decl_annotations_ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE, PSTR /* commandLine */, int showCmd) { constexpr PCWSTR appName = L"React Native Playground (Win32)"; constexpr PCWSTR windowClassName = L"MS_REACTNATIVE_PLAYGROUND_WIN32"; winrt::init_apartment(winrt::apartment_type::single_threaded); - react::windows::SetAsyncStorageDBPath(GetAsyncLocalStorageDBPath()); + // react::windows::SetAsyncStorageDBPath(GetAsyncLocalStorageDBPath()); WUXH::DesktopWindowXamlSource desktopXamlSource; diff --git a/packages/playground/windows/playground-win32/Playground-win32.vcxproj b/packages/playground/windows/playground-win32/Playground-win32.vcxproj index 3d8ffa2eef5..af2889f9ba8 100644 --- a/packages/playground/windows/playground-win32/Playground-win32.vcxproj +++ b/packages/playground/windows/playground-win32/Playground-win32.vcxproj @@ -1,5 +1,6 @@ + {8B88FFAE-4DBC-49A2-AFA5-D2477D4AD189} Playground @@ -9,9 +10,6 @@ 10.0.18362.0 - - - Debug @@ -49,11 +47,16 @@ false true + + v142 + - + + + @@ -64,36 +67,29 @@ - StdCall - true Use pch.h - true - Level3 - USE_V8;%(PreprocessorDefinitions) - USE_HERMES;%(PreprocessorDefinitions) + $(IntDir)pch.pch + Level4 + %(AdditionalOptions) /bigobj + 4453;28204 - shell32.lib;user32.lib;windowsapp.lib;$(ReactNativeWindowsDir)target\$(PlatformTarget)\$(Configuration)\ReactUWP\React.uwp.lib;%(AdditionalDependenices) + shell32.lib;user32.lib;windowsapp.lib;%(AdditionalDependenices) Windows true - Disabled + _DEBUG;%(PreprocessorDefinitions) + stdcpp17 - Size - true - Full + NDEBUG;%(PreprocessorDefinitions) - - true - true - @@ -114,20 +110,29 @@ - - {2d5d43d9-cffc-4c40-b4cd-02efb4e2742b} - + - + + {f7d32bd0-2749-483e-9a0d-1635ef7e3136} + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\AppxPackage\Microsoft.AppXPackage.Targets resources.pri + @@ -136,8 +141,16 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + \ No newline at end of file diff --git a/packages/playground/windows/playground-win32/packages.config b/packages/playground/windows/playground-win32/packages.config index 3a066bd4eff..05122f9e4af 100644 --- a/packages/playground/windows/playground-win32/packages.config +++ b/packages/playground/windows/playground-win32/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file From 82b32687784c1edfa554cf79cf0cd01faaa473cc Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Wed, 13 May 2020 14:23:23 -0700 Subject: [PATCH 02/12] hook up dispatcher in playground --- .../playground-win32/Playground-Win32.cpp | 194 +++--------------- .../windows/playground/MainPage.cpp | 4 + .../Views/ReactRootControl.cpp | 11 + 3 files changed, 46 insertions(+), 163 deletions(-) diff --git a/packages/playground/windows/playground-win32/Playground-Win32.cpp b/packages/playground/windows/playground-win32/Playground-Win32.cpp index 959793b0851..a842de6afbb 100644 --- a/packages/playground/windows/playground-win32/Playground-Win32.cpp +++ b/packages/playground/windows/playground-win32/Playground-Win32.cpp @@ -22,71 +22,51 @@ #pragma pop_macro("GetCurrentTime") -/* -namespace { -std::string GetAsyncLocalStorageDBPath() { - winrt::com_array localAppData; - winrt::check_hresult(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, put_abi(localAppData))); - - std::filesystem::path asyncLocalStorageDBDir{localAppData.data()}; - asyncLocalStorageDBDir /= LR"(Microsoft\React Native Playground (Win32))"; - - if (!CreateDirectoryW(asyncLocalStorageDBDir.wstring().data(), nullptr)) { - if (::GetLastError() != ERROR_ALREADY_EXISTS) - winrt::throw_last_error(); - } - - auto asyncLocalStoragePath = asyncLocalStorageDBDir / L"AsyncStorage.sqlite3"; - return Microsoft::Common::Unicode::Utf16ToUtf8(asyncLocalStoragePath.wstring()); -} - -} // namespace -*/ - namespace WUX = winrt::Windows::UI::Xaml; namespace WUXC = WUX::Controls; namespace WUXH = WUX::Hosting; -/* -struct PlaygroundNativeModuleProvider final : facebook::react::NativeModuleProvider { - virtual std::vector GetModules( - const std::shared_ptr &defaultQueueThread) override { - std::vector modules; - return modules; + +struct SimpleRedBoxHandler : winrt::implements { + SimpleRedBoxHandler() noexcept { } -}; -class PlaygroundViewManagerProvider final : public react::uwp::ViewManagerProvider { - public: - virtual std::vector GetViewManagers( - const std::shared_ptr &instance) override { - std::vector viewManagers; + void ShowNewError( + winrt::Microsoft::ReactNative::IRedBoxErrorInfo const &info, + winrt::Microsoft::ReactNative::RedBoxErrorType type) noexcept { - return viewManagers; - } -}; + OutputDebugStringA("----- Begin RedBox -----\n"); + + switch (type) + { + case winrt::Microsoft::ReactNative::RedBoxErrorType::JavaScriptFatal: + OutputDebugStringA("Fatal Error: "); + break; + case winrt::Microsoft::ReactNative::RedBoxErrorType::JavaScriptSoft: + OutputDebugStringA("JavaScript Error: "); + break; + case winrt::Microsoft::ReactNative::RedBoxErrorType::Native: + OutputDebugStringA("Native Error: "); + break; + } + OutputDebugString(info.Message().c_str()); + OutputDebugStringA("\n----- End RedBox -----\n"); -struct HwndReactInstanceCreator : ::react::uwp::IReactInstanceCreator { - HwndReactInstanceCreator(HWND hwnd) { - m_hwnd = hwnd; } - void detach() { - m_hwnd = nullptr; + bool IsDevSupportEnabled() noexcept { + return true; } - std::shared_ptr<::react::uwp::IReactInstance> getInstance() override; - void markAsNeedsReload() override; - void persistUseWebDebugger(bool useWebDebugger) override; - void persistUseLiveReload(bool useLiveReload) override; - void persistUseDirectDebugger(bool useDirectDebugger) override; - void persistBreakOnNextLine(bool breakOnNextLine) override; + void UpdateError(winrt::Microsoft::ReactNative::IRedBoxErrorInfo const &info) noexcept { + // noop + } - private: - HWND m_hwnd; + void DismissRedBox() noexcept { + // noop + } }; -*/ struct WindowData { static HINSTANCE s_instance; @@ -100,10 +80,6 @@ struct WindowData { winrt::Microsoft::ReactNative::ReactInstanceSettings m_instanceSettings; winrt::Windows::Foundation::Collections::IVector m_packageProviders; - //std::shared_ptr m_instance; - //std::shared_ptr m_rootView; - //std::shared_ptr m_instanceCreator; - bool m_useWebDebugger{true}; bool m_liveReloadEnabled{true}; bool m_reuseInstance{true}; @@ -111,8 +87,6 @@ struct WindowData { bool m_breakOnNextLine{false}; uint16_t m_debuggerPort{defaultDebuggerPort}; - //react::uwp::JSIEngine m_jsEngine{react::uwp::JSIEngine::Chakra}; - WindowData(const WUXH::DesktopWindowXamlSource &desktopWindowXamlSource) : m_desktopWindowXamlSource(desktopWindowXamlSource) {} @@ -159,22 +133,6 @@ struct WindowData { DialogBox(s_instance, MAKEINTRESOURCE(IDD_OPENJSBUNDLEBOX), hwnd, &Bundle); if (!m_bundleFile.empty()) { - /* - facebook::react::InitializeLogging( - [](facebook::react::RCTLogLevel logLevel, const char *message) { OutputDebugStringA(message); }); - */ - - // Create NativeModuleProvider - /* - std::shared_ptr moduleLoader = - std::make_shared(); - std::shared_ptr viewManagerProvider = - std::make_shared(); - - - m_instance = react::uwp::CreateReactInstance(moduleLoader, viewManagerProvider); - */ - PCWSTR appName = (m_bundleFile == LR"(Samples\rntester)") ? L"RNTesterApp" : L"Bootstrap"; auto host = Host(); @@ -185,6 +143,7 @@ struct WindowData { host.InstanceSettings().DebuggerBreakOnNextLine(m_breakOnNextLine); host.InstanceSettings().UseFastRefresh(m_liveReloadEnabled); host.InstanceSettings().DebuggerPort(m_debuggerPort); + host.InstanceSettings().RedBoxHandler(winrt::make()); host.InstanceSettings().Properties().Set( winrt::Microsoft::ReactNative::ReactDispatcherHelper::UIDispatcherProperty(), winrt::Microsoft::ReactNative::ReactDispatcherHelper::UIThreadDispatcher()); @@ -200,40 +159,6 @@ struct WindowData { auto rootElement = m_desktopWindowXamlSource.Content().as(); rootElement.Children().Clear(); rootElement.Children().Append(m_reactRootView); - - /* - - - react::uwp::ReactInstanceSettings settings; - settings.UseWebDebugger = m_useWebDebugger; - settings.UseLiveReload = m_liveReloadEnabled; - settings.DebuggerBreakOnNextLine = m_breakOnNextLine; - settings.UseDirectDebugger = m_useDirectDebugger; - settings.DebuggerPort = m_debuggerPort; - settings.jsiEngine = m_jsEngine; - - settings.EnableDeveloperMenu = true; - - settings.LoggingCallback = [](facebook::react::RCTLogLevel logLevel, const char *message) { - OutputDebugStringA("In LoggingCallback"); - OutputDebugStringA(message); - }; - - m_instance->Start(m_instance, settings); - m_instance->loadBundle(Microsoft::Common::Unicode::Utf16ToUtf8(m_bundleFile)); - - folly::dynamic initialProps = folly::dynamic::object(); - - - - - // Create the root view - m_rootView = react::uwp::CreateReactRootView(rootElement, appName, m_instanceCreator); - - m_rootView->SetInitialProps(std::move(initialProps)); - m_rootView->SetInstanceCreator(m_instanceCreator); - m_rootView->AttachRoot(); - */ } break; @@ -264,14 +189,6 @@ struct WindowData { SetWindowPos(hWndXamlIsland, nullptr, 0, 0, createStruct->cx, createStruct->cy, SWP_SHOWWINDOW); - /* - try { - m_instanceCreator = std::make_shared(hwnd); - } catch (...) { - return -1; - } - */ - return 0; } @@ -414,53 +331,6 @@ struct WindowData { extern "C" IMAGE_DOS_HEADER __ImageBase; HINSTANCE WindowData::s_instance = reinterpret_cast(&__ImageBase); -/* -std::shared_ptr<::react::uwp::IReactInstance> HwndReactInstanceCreator::getInstance() { - if (!m_hwnd) - return nullptr; - - return WindowData::GetFromWindow(m_hwnd)->m_instance; -} - -void HwndReactInstanceCreator::markAsNeedsReload() { - if (!m_hwnd) - return; - - auto instance = WindowData::GetFromWindow(m_hwnd)->m_instance; - if (instance) - instance->SetAsNeedsReload(); -} - -void HwndReactInstanceCreator::persistUseWebDebugger(bool useWebDebugger) { - if (!m_hwnd) - return; - - WindowData::GetFromWindow(m_hwnd)->m_useWebDebugger = useWebDebugger; -} - -void HwndReactInstanceCreator::persistUseLiveReload(bool useLiveReload) { - if (!m_hwnd) - return; - - WindowData::GetFromWindow(m_hwnd)->m_liveReloadEnabled = useLiveReload; -} - -void HwndReactInstanceCreator::persistUseDirectDebugger(bool useDirectDebugger) { - if (!m_hwnd) - return; - - WindowData::GetFromWindow(m_hwnd)->m_useDirectDebugger = useDirectDebugger; -} - -void HwndReactInstanceCreator::persistBreakOnNextLine(bool breakOnNextLine) { - if (!m_hwnd) - return; - - WindowData::GetFromWindow(m_hwnd)->m_breakOnNextLine = breakOnNextLine; -} - -*/ - LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) noexcept { switch (message) { case WM_CREATE: { @@ -497,8 +367,6 @@ _Use_decl_annotations_ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE, PSTR winrt::init_apartment(winrt::apartment_type::single_threaded); - // react::windows::SetAsyncStorageDBPath(GetAsyncLocalStorageDBPath()); - WUXH::DesktopWindowXamlSource desktopXamlSource; WNDCLASSEXW wcex = {}; diff --git a/packages/playground/windows/playground/MainPage.cpp b/packages/playground/windows/playground/MainPage.cpp index 57ad5438409..e0ab6639903 100644 --- a/packages/playground/windows/playground/MainPage.cpp +++ b/packages/playground/windows/playground/MainPage.cpp @@ -42,6 +42,10 @@ void MainPage::OnLoadClick( host.InstanceSettings().DebuggerBreakOnNextLine(x_BreakOnFirstLineCheckBox().IsChecked().GetBoolean()); host.InstanceSettings().UseFastRefresh(x_UseFastRefreshCheckBox().IsChecked().GetBoolean()); host.InstanceSettings().DebuggerPort(static_cast(std::stoi(std::wstring(x_DebuggerPort().Text())))); + host.InstanceSettings().Properties().Set( + winrt::Microsoft::ReactNative::ReactDispatcherHelper::UIDispatcherProperty(), + winrt::Microsoft::ReactNative::ReactDispatcherHelper::UIThreadDispatcher()); + // Nudge the ReactNativeHost to create the instance and wrapping context host.ReloadInstance(); diff --git a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp index d61d17c6bf1..746c164fdb4 100644 --- a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp +++ b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp @@ -612,6 +612,17 @@ void ReactRootControl::ReloadViewHost() noexcept { } void ReactRootControl::AttachBackHandlers(XamlView const &rootView) noexcept { + /* + // If we are running in a Xaml Island or some other environment where the SystemNavigationManager is unavailable, + // we should just skip hooking up the BackButton handler. + // Unfortunately SystemNavigationManager->GetForCurrentView seems to crash with XamlIslands, not sure how to detect this right now + auto fact = winrt::get_activation_factory< + winrt::Windows::UI::Core::SystemNavigationManager, + winrt::Windows::UI::Core::ISystemNavigationManagerStatics>(); + auto abi = fact.as(); + ABI::Windows::UI::Core::ISystemNavigationManager* sysNavMgr; + auto hr = abi->GetForCurrentView(&sysNavMgr); + */ auto weakThis = weak_from_this(); m_backRequestedRevoker = winrt::Windows::UI::Core::SystemNavigationManager::GetForCurrentView().BackRequested( winrt::auto_revoke, From 97cab5ff2b5489e5b4a923570e203d6094d23b07 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Wed, 13 May 2020 14:25:06 -0700 Subject: [PATCH 03/12] Change files --- ...-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json diff --git a/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json b/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json new file mode 100644 index 00000000000..960cbdc82d9 --- /dev/null +++ b/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json @@ -0,0 +1,8 @@ +{ + "type": "none", + "comment": "Added comment about needing to detect XamlIslands for BackHandler", + "packageName": "react-native-windows", + "email": "acoates@microsoft.com", + "dependentChangeType": "none", + "date": "2020-05-13T21:25:06.608Z" +} From 53ac58baaca0664585a1a2b7d08bf4c019180928 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Wed, 13 May 2020 14:34:50 -0700 Subject: [PATCH 04/12] formatting --- .../playground-win32/Playground-Win32.cpp | 45 +++++++------------ .../windows/playground/MainPage.cpp | 1 - .../Views/ReactRootControl.cpp | 5 +-- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/packages/playground/windows/playground-win32/Playground-Win32.cpp b/packages/playground/windows/playground-win32/Playground-Win32.cpp index a842de6afbb..87e4ce16519 100644 --- a/packages/playground/windows/playground-win32/Playground-Win32.cpp +++ b/packages/playground/windows/playground-win32/Playground-Win32.cpp @@ -26,21 +26,17 @@ namespace WUX = winrt::Windows::UI::Xaml; namespace WUXC = WUX::Controls; namespace WUXH = WUX::Hosting; - struct SimpleRedBoxHandler : winrt::implements { - SimpleRedBoxHandler() noexcept { - } + SimpleRedBoxHandler() noexcept {} void ShowNewError( winrt::Microsoft::ReactNative::IRedBoxErrorInfo const &info, winrt::Microsoft::ReactNative::RedBoxErrorType type) noexcept { + OutputDebugStringA("----- Begin RedBox -----\n"); - OutputDebugStringA("----- Begin RedBox -----\n"); - - switch (type) - { + switch (type) { case winrt::Microsoft::ReactNative::RedBoxErrorType::JavaScriptFatal: - OutputDebugStringA("Fatal Error: "); + OutputDebugStringA("Fatal Error: "); break; case winrt::Microsoft::ReactNative::RedBoxErrorType::JavaScriptSoft: OutputDebugStringA("JavaScript Error: "); @@ -48,11 +44,10 @@ struct SimpleRedBoxHandler : winrt::implements m_packageProviders; + winrt::Windows::Foundation::Collections::IVector + m_packageProviders; bool m_useWebDebugger{true}; bool m_liveReloadEnabled{true}; @@ -94,8 +90,7 @@ struct WindowData { return reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); } - winrt::Microsoft::ReactNative::ReactNativeHost Host() noexcept - { + winrt::Microsoft::ReactNative::ReactNativeHost Host() noexcept { if (!m_host) { m_host = winrt::Microsoft::ReactNative::ReactNativeHost(); m_host.InstanceSettings(InstanceSettings()); @@ -104,30 +99,24 @@ struct WindowData { return m_host; } - winrt::Microsoft::ReactNative::ReactInstanceSettings InstanceSettings() noexcept - { + winrt::Microsoft::ReactNative::ReactInstanceSettings InstanceSettings() noexcept { if (!m_instanceSettings) { m_instanceSettings = winrt::Microsoft::ReactNative::ReactInstanceSettings(); } return m_instanceSettings; - } - winrt::Windows::Foundation::Collections::IVector - PackageProviders() noexcept - { - if (!m_packageProviders) { - m_packageProviders = winrt::single_threaded_vector(); - } - - return m_packageProviders; + PackageProviders() noexcept { + if (!m_packageProviders) { + m_packageProviders = winrt::single_threaded_vector(); + } + return m_packageProviders; } - - LRESULT OnCommand(HWND hwnd, int id, HWND /* hwndCtl*/ , UINT) { + LRESULT OnCommand(HWND hwnd, int id, HWND /* hwndCtl*/, UINT) { switch (id) { case IDM_OPENJSFILE: { DialogBox(s_instance, MAKEINTRESOURCE(IDD_OPENJSBUNDLEBOX), hwnd, &Bundle); diff --git a/packages/playground/windows/playground/MainPage.cpp b/packages/playground/windows/playground/MainPage.cpp index e0ab6639903..aaade330325 100644 --- a/packages/playground/windows/playground/MainPage.cpp +++ b/packages/playground/windows/playground/MainPage.cpp @@ -46,7 +46,6 @@ void MainPage::OnLoadClick( winrt::Microsoft::ReactNative::ReactDispatcherHelper::UIDispatcherProperty(), winrt::Microsoft::ReactNative::ReactDispatcherHelper::UIThreadDispatcher()); - // Nudge the ReactNativeHost to create the instance and wrapping context host.ReloadInstance(); diff --git a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp index 746c164fdb4..3a5421e2d66 100644 --- a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp +++ b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp @@ -615,9 +615,8 @@ void ReactRootControl::AttachBackHandlers(XamlView const &rootView) noexcept { /* // If we are running in a Xaml Island or some other environment where the SystemNavigationManager is unavailable, // we should just skip hooking up the BackButton handler. - // Unfortunately SystemNavigationManager->GetForCurrentView seems to crash with XamlIslands, not sure how to detect this right now - auto fact = winrt::get_activation_factory< - winrt::Windows::UI::Core::SystemNavigationManager, + // Unfortunately SystemNavigationManager->GetForCurrentView seems to crash with XamlIslands, not sure how to detect + // this right now auto fact = winrt::get_activation_factory< winrt::Windows::UI::Core::SystemNavigationManager, winrt::Windows::UI::Core::ISystemNavigationManagerStatics>(); auto abi = fact.as(); ABI::Windows::UI::Core::ISystemNavigationManager* sysNavMgr; From 0a807252f870c90cb0dad0aa5695d7485b779085 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Thu, 14 May 2020 09:57:10 -0700 Subject: [PATCH 05/12] minor changes --- packages/playground/windows/playground-win32.sln | 4 ---- .../playground-win32/Playground-win32.vcxproj | 16 +--------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/packages/playground/windows/playground-win32.sln b/packages/playground/windows/playground-win32.sln index 51cae8c858b..969d4742d16 100644 --- a/packages/playground/windows/playground-win32.sln +++ b/packages/playground/windows/playground-win32.sln @@ -27,8 +27,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JSI.Universal", "..\..\..\v EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.ReactNative.Cxx", "..\..\..\vnext\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems", "{DA8B35B3-DA00-4B02-BDE6-6A397B3FD46B}" EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.ReactNative.SharedManaged", "..\..\..\vnext\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.shproj", "{67A1076F-7790-4203-86EA-4402CCB5E782}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "..\..\..\vnext\Common\Common.vcxproj", "{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ReactNative", "ReactNative", "{5EA20F54-880A-49F3-99FA-4B3FE54E8AB1}" @@ -42,7 +40,6 @@ Global ..\..\..\vnext\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9 ..\..\..\vnext\ReactWindowsCore\ReactWindowsCore.vcxitems*{11c084a3-a57c-4296-a679-cac17b603144}*SharedItemsImports = 4 ..\..\..\vnext\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9 - ..\..\..\vnext\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13 ..\..\..\vnext\Mso\Mso.vcxitems*{84e05bfa-cbaf-4f0d-bfb6-4ce85742a57e}*SharedItemsImports = 9 ..\..\..\vnext\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{8b88ffae-4dbc-49a2-afa5-d2477d4ad189}*SharedItemsImports = 4 ..\..\..\vnext\JSI\Shared\JSI.Shared.vcxitems*{a62d504a-16b8-41d2-9f19-e2e86019e5e4}*SharedItemsImports = 4 @@ -166,7 +163,6 @@ Global {0CC28589-39E4-4288-B162-97B959F8B843} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} {A62D504A-16B8-41D2-9F19-E2E86019E5E4} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} {DA8B35B3-DA00-4B02-BDE6-6A397B3FD46B} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} - {67A1076F-7790-4203-86EA-4402CCB5E782} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} {FCA38F3C-7C73-4C47-BE4E-32F77FA8538D} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} {2049DBE9-8D13-42C9-AE4B-413AE38FFFD0} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} {84E05BFA-CBAF-4F0D-BFB6-4CE85742A57E} = {5EA20F54-880A-49F3-99FA-4B3FE54E8AB1} diff --git a/packages/playground/windows/playground-win32/Playground-win32.vcxproj b/packages/playground/windows/playground-win32/Playground-win32.vcxproj index 25eef5e7e06..bfd88e17759 100644 --- a/packages/playground/windows/playground-win32/Playground-win32.vcxproj +++ b/packages/playground/windows/playground-win32/Playground-win32.vcxproj @@ -40,6 +40,7 @@ Application Unicode + v142 true @@ -48,9 +49,6 @@ false true - - v142 - @@ -122,12 +120,6 @@ {f7d32bd0-2749-483e-9a0d-1635ef7e3136} - @@ -152,10 +144,4 @@ - - - - - - \ No newline at end of file From 868e8db19d2a6d84bee9d7d613e0603e321dedf9 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Thu, 14 May 2020 13:11:14 -0700 Subject: [PATCH 06/12] Fix playground-win32 offline bundle loading --- ...ive-windows-2020-05-13-14-25-06-msrnPlayWin32.json | 6 +++--- packages/playground/just-task.js | 8 ++++++++ packages/playground/package.json | 1 + packages/playground/windows/.gitignore | 1 + .../windows/playground-win32/Playground-Win32.cpp | 4 ++++ .../windows/playground-win32/Playground-win32.vcxproj | 3 --- vnext/ReactUWP/Utils/LocalBundleReader.cpp | 11 +++++++++-- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json b/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json index 960cbdc82d9..9a48c315646 100644 --- a/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json +++ b/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json @@ -1,8 +1,8 @@ { - "type": "none", - "comment": "Added comment about needing to detect XamlIslands for BackHandler", + "type": "prerelease", + "comment": "Fix bundle loading logic to handle non-ms-app paths", "packageName": "react-native-windows", "email": "acoates@microsoft.com", - "dependentChangeType": "none", + "dependentChangeType": "patch", "date": "2020-05-13T21:25:06.608Z" } diff --git a/packages/playground/just-task.js b/packages/playground/just-task.js index ad9f3c8a1b8..d82b4dd3b36 100644 --- a/packages/playground/just-task.js +++ b/packages/playground/just-task.js @@ -5,6 +5,7 @@ * @ts-check */ +const fs = require('fs'); const {task, series, eslintTask} = require('just-scripts'); task('eslint', () => { @@ -16,3 +17,10 @@ task('eslint:fix', () => { task('lint', series('eslint')); task('lint:fix', series('eslint:fix')); + +task('prepareBundleWin32', () => { + const file = 'windows/playground-win32/Bundle'; + if (!fs.existsSync(file)) { + fs.mkdirSync(file); + } +}); diff --git a/packages/playground/package.json b/packages/playground/package.json index 64b1cc263d6..17d4014d3a2 100644 --- a/packages/playground/package.json +++ b/packages/playground/package.json @@ -3,6 +3,7 @@ "version": "0.0.54", "private": true, "scripts": { + "bundle-win32":"just-scripts prepareBundleWin32 && npx react-native bundle --entry-file Samples\\rntester.tsx --bundle-output windows\\playground-win32\\Bundle\\Samples\\rntester.bundle --platform windows", "start": "react-native start", "lint:fix": "just-scripts lint:fix", "lint": "just-scripts lint", diff --git a/packages/playground/windows/.gitignore b/packages/playground/windows/.gitignore index 0925a804895..e8284b6d239 100644 --- a/packages/playground/windows/.gitignore +++ b/packages/playground/windows/.gitignore @@ -92,3 +92,4 @@ packages/ **/Generated Files/** playground/Bundle +playground-win32/Bundle diff --git a/packages/playground/windows/playground-win32/Playground-Win32.cpp b/packages/playground/windows/playground-win32/Playground-Win32.cpp index 87e4ce16519..ef2ef5a9595 100644 --- a/packages/playground/windows/playground-win32/Playground-Win32.cpp +++ b/packages/playground/windows/playground-win32/Playground-Win32.cpp @@ -124,11 +124,15 @@ struct WindowData { if (!m_bundleFile.empty()) { PCWSTR appName = (m_bundleFile == LR"(Samples\rntester)") ? L"RNTesterApp" : L"Bootstrap"; + WCHAR workingDir[MAX_PATH]; + GetCurrentDirectory(MAX_PATH, workingDir); + auto host = Host(); host.InstanceSettings().JavaScriptBundleFile(m_bundleFile); host.InstanceSettings().MainComponentName(appName); host.InstanceSettings().UseWebDebugger(m_useWebDebugger); host.InstanceSettings().UseDirectDebugger(m_useDirectDebugger); + host.InstanceSettings().BundleRootPath(std::wstring(L"file:").append(workingDir).append(L"\\Bundle\\").c_str()); host.InstanceSettings().DebuggerBreakOnNextLine(m_breakOnNextLine); host.InstanceSettings().UseFastRefresh(m_liveReloadEnabled); host.InstanceSettings().DebuggerPort(m_debuggerPort); diff --git a/packages/playground/windows/playground-win32/Playground-win32.vcxproj b/packages/playground/windows/playground-win32/Playground-win32.vcxproj index bfd88e17759..60bb691b19c 100644 --- a/packages/playground/windows/playground-win32/Playground-win32.vcxproj +++ b/packages/playground/windows/playground-win32/Playground-win32.vcxproj @@ -53,9 +53,6 @@ - - - diff --git a/vnext/ReactUWP/Utils/LocalBundleReader.cpp b/vnext/ReactUWP/Utils/LocalBundleReader.cpp index 305d80bad9c..90421dd4632 100644 --- a/vnext/ReactUWP/Utils/LocalBundleReader.cpp +++ b/vnext/ReactUWP/Utils/LocalBundleReader.cpp @@ -18,11 +18,18 @@ namespace uwp { std::future LocalBundleReader::LoadBundleAsync(const std::string &bundleUri) { winrt::hstring str(Microsoft::Common::Unicode::Utf8ToUtf16(bundleUri)); - winrt::Windows::Foundation::Uri uri(str); co_await winrt::resume_background(); - auto file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri); + winrt::Windows::Storage::StorageFile file{nullptr}; + + // Supports "ms-appx://" or "ms-appdata://" + if (bundleUri._Starts_with("ms-app")) { + winrt::Windows::Foundation::Uri uri(str); + file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri); + } else { + file = co_await winrt::Windows::Storage::StorageFile::GetFileFromPathAsync(str); + } // Read the buffer manually to avoid a Utf8 -> Utf16 -> Utf8 encoding // roundtrip. From 7c0648dd1afc8c3bb993305a00506aabd3fe9afd Mon Sep 17 00:00:00 2001 From: "REDMOND\\acoates" Date: Thu, 14 May 2020 16:19:23 -0700 Subject: [PATCH 07/12] fix AttachBackHandlers --- .../Microsoft.ReactNative.vcxproj | 2 +- .../Views/ReactRootControl.cpp | 36 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj index 3a981cd2ef6..aee0ff6b374 100644 --- a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +++ b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj @@ -164,7 +164,7 @@ true - winsqlite3.lib;ChakraRT.lib;dxguid.lib;dloadhelper.lib;%(AdditionalDependencies) + winsqlite3.lib;ChakraRT.lib;dxguid.lib;dloadhelper.lib;OneCoreUap.lib;%(AdditionalDependencies) winsqlite3.dll;%(DelayLoadDLLs) Console true diff --git a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp index 3a5421e2d66..6659fbfc776 100644 --- a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp +++ b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp @@ -28,6 +28,21 @@ #include #include +//#include + +extern "C" { + +typedef enum AppPolicyWindowingModel { + AppPolicyWindowingModel_None = 0, + AppPolicyWindowingModel_Universal = 1, + AppPolicyWindowingModel_ClassicDesktop = 2, + AppPolicyWindowingModel_ClassicPhone = 3 +} AppPolicyWindowingModel; + +WINBASEAPI +_Check_return_ _Success_(return == ERROR_SUCCESS) LONG WINAPI + AppPolicyGetWindowingModel(_In_ HANDLE processToken, _Out_ AppPolicyWindowingModel *policy); +} namespace react::uwp { @@ -612,16 +627,19 @@ void ReactRootControl::ReloadViewHost() noexcept { } void ReactRootControl::AttachBackHandlers(XamlView const &rootView) noexcept { + /* - // If we are running in a Xaml Island or some other environment where the SystemNavigationManager is unavailable, - // we should just skip hooking up the BackButton handler. - // Unfortunately SystemNavigationManager->GetForCurrentView seems to crash with XamlIslands, not sure how to detect - // this right now auto fact = winrt::get_activation_factory< winrt::Windows::UI::Core::SystemNavigationManager, - winrt::Windows::UI::Core::ISystemNavigationManagerStatics>(); - auto abi = fact.as(); - ABI::Windows::UI::Core::ISystemNavigationManager* sysNavMgr; - auto hr = abi->GetForCurrentView(&sysNavMgr); - */ + * If we are running in a Xaml Island or some other environment where the SystemNavigationManager is unavailable, + * we should just skip hooking up the BackButton handler. + * SystemNavigationManager->GetForCurrentView seems to crash with XamlIslands, so we detect if we are + * running in the desktop windowing model before calling it. + */ + AppPolicyWindowingModel e; + if (FAILED(AppPolicyGetWindowingModel((HANDLE)-6 /*GetCurrentThreadEffectiveToken()*/, &e)) || + e == AppPolicyWindowingModel_ClassicDesktop) { + return; + } + auto weakThis = weak_from_this(); m_backRequestedRevoker = winrt::Windows::UI::Core::SystemNavigationManager::GetForCurrentView().BackRequested( winrt::auto_revoke, From 2bc3f88124ec420be158cb5b73f41f5ce732e518 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Thu, 14 May 2020 21:02:30 -0700 Subject: [PATCH 08/12] move isXamlIsland to helpers --- packages/playground/index.js | 1 + .../playground-win32/Playground-Win32.cpp | 3 ++- .../Views/ReactRootControl.cpp | 27 +++---------------- vnext/ReactUWP/Utils/Helpers.cpp | 26 ++++++++++++++++++ vnext/include/ReactUWP/Utils/Helpers.h | 2 ++ 5 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 packages/playground/index.js diff --git a/packages/playground/index.js b/packages/playground/index.js new file mode 100644 index 00000000000..45a1db0b6b4 --- /dev/null +++ b/packages/playground/index.js @@ -0,0 +1 @@ +require('react-native-windows/RNTester'); diff --git a/packages/playground/windows/playground-win32/Playground-Win32.cpp b/packages/playground/windows/playground-win32/Playground-Win32.cpp index ef2ef5a9595..fa1dfc6f319 100644 --- a/packages/playground/windows/playground-win32/Playground-Win32.cpp +++ b/packages/playground/windows/playground-win32/Playground-Win32.cpp @@ -132,7 +132,8 @@ struct WindowData { host.InstanceSettings().MainComponentName(appName); host.InstanceSettings().UseWebDebugger(m_useWebDebugger); host.InstanceSettings().UseDirectDebugger(m_useDirectDebugger); - host.InstanceSettings().BundleRootPath(std::wstring(L"file:").append(workingDir).append(L"\\Bundle\\").c_str()); + host.InstanceSettings().BundleRootPath( + std::wstring(L"file:").append(workingDir).append(L"\\Bundle\\").c_str()); host.InstanceSettings().DebuggerBreakOnNextLine(m_breakOnNextLine); host.InstanceSettings().UseFastRefresh(m_liveReloadEnabled); host.InstanceSettings().DebuggerPort(m_debuggerPort); diff --git a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp index 6659fbfc776..a910d98a416 100644 --- a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp +++ b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp @@ -28,21 +28,7 @@ #include #include -//#include - -extern "C" { - -typedef enum AppPolicyWindowingModel { - AppPolicyWindowingModel_None = 0, - AppPolicyWindowingModel_Universal = 1, - AppPolicyWindowingModel_ClassicDesktop = 2, - AppPolicyWindowingModel_ClassicPhone = 3 -} AppPolicyWindowingModel; - -WINBASEAPI -_Check_return_ _Success_(return == ERROR_SUCCESS) LONG WINAPI - AppPolicyGetWindowingModel(_In_ HANDLE processToken, _Out_ AppPolicyWindowingModel *policy); -} +#include namespace react::uwp { @@ -627,18 +613,13 @@ void ReactRootControl::ReloadViewHost() noexcept { } void ReactRootControl::AttachBackHandlers(XamlView const &rootView) noexcept { - /* * If we are running in a Xaml Island or some other environment where the SystemNavigationManager is unavailable, - * we should just skip hooking up the BackButton handler. - * SystemNavigationManager->GetForCurrentView seems to crash with XamlIslands, so we detect if we are - * running in the desktop windowing model before calling it. + * we should just skip hooking up the BackButton handler. SystemNavigationManager->GetForCurrentView seems to + * crash with XamlIslands so we can't just bail is that call fails. */ - AppPolicyWindowingModel e; - if (FAILED(AppPolicyGetWindowingModel((HANDLE)-6 /*GetCurrentThreadEffectiveToken()*/, &e)) || - e == AppPolicyWindowingModel_ClassicDesktop) { + if (react::uwp::IsXamlIsland()) return; - } auto weakThis = weak_from_this(); m_backRequestedRevoker = winrt::Windows::UI::Core::SystemNavigationManager::GetForCurrentView().BackRequested( diff --git a/vnext/ReactUWP/Utils/Helpers.cpp b/vnext/ReactUWP/Utils/Helpers.cpp index b2fcad03c61..2e2b90bd336 100644 --- a/vnext/ReactUWP/Utils/Helpers.cpp +++ b/vnext/ReactUWP/Utils/Helpers.cpp @@ -7,12 +7,29 @@ #include #include +#include + namespace winrt { using namespace xaml::Controls::Primitives; using namespace xaml::Media; using namespace Windows::Foundation::Metadata; } // namespace winrt +// These are declared in appmodel.h, but only for WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) They work in UWP +// too though. +extern "C" { +typedef enum AppPolicyWindowingModel { + AppPolicyWindowingModel_None = 0, + AppPolicyWindowingModel_Universal = 1, + AppPolicyWindowingModel_ClassicDesktop = 2, + AppPolicyWindowingModel_ClassicPhone = 3 +} AppPolicyWindowingModel; + +WINBASEAPI +_Check_return_ _Success_(return == ERROR_SUCCESS) LONG WINAPI + AppPolicyGetWindowingModel(_In_ HANDLE processToken, _Out_ AppPolicyWindowingModel *policy); +} + namespace react { namespace uwp { @@ -90,5 +107,14 @@ bool Is19H1OrHigher() { return IsAPIContractV8Available(); } +bool IsXamlIsland() { + AppPolicyWindowingModel e; + if (FAILED(AppPolicyGetWindowingModel((HANDLE)-6 /*GetCurrentThreadEffectiveToken()*/, &e)) || + e == AppPolicyWindowingModel_ClassicDesktop) { + return true; + } + return false; +} + } // namespace uwp }; // namespace react diff --git a/vnext/include/ReactUWP/Utils/Helpers.h b/vnext/include/ReactUWP/Utils/Helpers.h index c7750034230..3c984a6410c 100644 --- a/vnext/include/ReactUWP/Utils/Helpers.h +++ b/vnext/include/ReactUWP/Utils/Helpers.h @@ -29,5 +29,7 @@ bool IsRS3OrHigher(); bool IsRS4OrHigher(); bool IsRS5OrHigher(); bool Is19H1OrHigher(); + +bool IsXamlIsland(); } // namespace uwp } // namespace react From 19d5431d8ab1f36d9881a8ea3ca4b921333c93d5 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 15 May 2020 09:40:51 -0700 Subject: [PATCH 09/12] Use proper headers for appmodel --- vnext/Microsoft.ReactNative/pch.h | 5 +++++ vnext/ReactUWP/Utils/Helpers.cpp | 18 ++---------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/vnext/Microsoft.ReactNative/pch.h b/vnext/Microsoft.ReactNative/pch.h index c339ff1e823..a2a7b6ee2a8 100644 --- a/vnext/Microsoft.ReactNative/pch.h +++ b/vnext/Microsoft.ReactNative/pch.h @@ -15,11 +15,16 @@ #define NOGDI #endif +#undef WINAPI_FAMILY +#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP + #include #include #include #include #include +// When WINAPI_FAMILY is DESKTOP_APP, windows.h create a macro for GetCurrentTime, which conflicts with other headers +#undef GetCurrentTime #include "CppWinRTIncludes.h" #include "HResult.h" diff --git a/vnext/ReactUWP/Utils/Helpers.cpp b/vnext/ReactUWP/Utils/Helpers.cpp index 2e2b90bd336..c0b194f35dc 100644 --- a/vnext/ReactUWP/Utils/Helpers.cpp +++ b/vnext/ReactUWP/Utils/Helpers.cpp @@ -8,6 +8,7 @@ #include #include +#include namespace winrt { using namespace xaml::Controls::Primitives; @@ -15,21 +16,6 @@ using namespace xaml::Media; using namespace Windows::Foundation::Metadata; } // namespace winrt -// These are declared in appmodel.h, but only for WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) They work in UWP -// too though. -extern "C" { -typedef enum AppPolicyWindowingModel { - AppPolicyWindowingModel_None = 0, - AppPolicyWindowingModel_Universal = 1, - AppPolicyWindowingModel_ClassicDesktop = 2, - AppPolicyWindowingModel_ClassicPhone = 3 -} AppPolicyWindowingModel; - -WINBASEAPI -_Check_return_ _Success_(return == ERROR_SUCCESS) LONG WINAPI - AppPolicyGetWindowingModel(_In_ HANDLE processToken, _Out_ AppPolicyWindowingModel *policy); -} - namespace react { namespace uwp { @@ -109,7 +95,7 @@ bool Is19H1OrHigher() { bool IsXamlIsland() { AppPolicyWindowingModel e; - if (FAILED(AppPolicyGetWindowingModel((HANDLE)-6 /*GetCurrentThreadEffectiveToken()*/, &e)) || + if (FAILED(AppPolicyGetWindowingModel(GetCurrentThreadEffectiveToken(), &e)) || e == AppPolicyWindowingModel_ClassicDesktop) { return true; } From 3b16611335f25a10e10dfbc364f8c0767e9eb064 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 15 May 2020 10:02:42 -0700 Subject: [PATCH 10/12] formatting --- vnext/Microsoft.ReactNative/Pch/pch.h | 2 +- vnext/ReactUWP/Utils/Helpers.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Pch/pch.h b/vnext/Microsoft.ReactNative/Pch/pch.h index a2a7b6ee2a8..f2af80ec3d9 100644 --- a/vnext/Microsoft.ReactNative/Pch/pch.h +++ b/vnext/Microsoft.ReactNative/Pch/pch.h @@ -16,7 +16,7 @@ #endif #undef WINAPI_FAMILY -#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP +#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP #include #include diff --git a/vnext/ReactUWP/Utils/Helpers.cpp b/vnext/ReactUWP/Utils/Helpers.cpp index ad51ac3e9ef..e5955a16493 100644 --- a/vnext/ReactUWP/Utils/Helpers.cpp +++ b/vnext/ReactUWP/Utils/Helpers.cpp @@ -8,8 +8,8 @@ #include #include -#include #include +#include namespace winrt { using namespace xaml::Controls::Primitives; From faca2b64d930ccfc5a08d15fdad4ff3bf52a008d Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 15 May 2020 12:46:56 -0700 Subject: [PATCH 11/12] Remove MSRN changes that will be submitted seperately --- ...ve-windows-2020-05-13-14-25-06-msrnPlayWin32.json | 8 -------- vnext/Microsoft.ReactNative/Pch/pch.h | 5 ----- .../Microsoft.ReactNative/Views/ReactRootControl.cpp | 9 --------- vnext/ReactUWP/Utils/Helpers.cpp | 12 ------------ vnext/ReactUWP/Utils/LocalBundleReader.cpp | 11 ++--------- vnext/include/ReactUWP/Utils/Helpers.h | 2 -- 6 files changed, 2 insertions(+), 45 deletions(-) delete mode 100644 change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json diff --git a/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json b/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json deleted file mode 100644 index 9a48c315646..00000000000 --- a/change/react-native-windows-2020-05-13-14-25-06-msrnPlayWin32.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "type": "prerelease", - "comment": "Fix bundle loading logic to handle non-ms-app paths", - "packageName": "react-native-windows", - "email": "acoates@microsoft.com", - "dependentChangeType": "patch", - "date": "2020-05-13T21:25:06.608Z" -} diff --git a/vnext/Microsoft.ReactNative/Pch/pch.h b/vnext/Microsoft.ReactNative/Pch/pch.h index f2af80ec3d9..c339ff1e823 100644 --- a/vnext/Microsoft.ReactNative/Pch/pch.h +++ b/vnext/Microsoft.ReactNative/Pch/pch.h @@ -15,16 +15,11 @@ #define NOGDI #endif -#undef WINAPI_FAMILY -#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP - #include #include #include #include #include -// When WINAPI_FAMILY is DESKTOP_APP, windows.h create a macro for GetCurrentTime, which conflicts with other headers -#undef GetCurrentTime #include "CppWinRTIncludes.h" #include "HResult.h" diff --git a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp index 6dbcb69d161..ef076ed36f5 100644 --- a/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp +++ b/vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp @@ -27,7 +27,6 @@ #include #include -#include #include #include @@ -618,14 +617,6 @@ void ReactRootControl::ReloadViewHost() noexcept { } void ReactRootControl::AttachBackHandlers(XamlView const &rootView) noexcept { - /* - * If we are running in a Xaml Island or some other environment where the SystemNavigationManager is unavailable, - * we should just skip hooking up the BackButton handler. SystemNavigationManager->GetForCurrentView seems to - * crash with XamlIslands so we can't just bail is that call fails. - */ - if (react::uwp::IsXamlIsland()) - return; - auto weakThis = weak_from_this(); m_backRequestedRevoker = winrt::Windows::UI::Core::SystemNavigationManager::GetForCurrentView().BackRequested( winrt::auto_revoke, diff --git a/vnext/ReactUWP/Utils/Helpers.cpp b/vnext/ReactUWP/Utils/Helpers.cpp index e5955a16493..c169f301d8a 100644 --- a/vnext/ReactUWP/Utils/Helpers.cpp +++ b/vnext/ReactUWP/Utils/Helpers.cpp @@ -8,9 +8,6 @@ #include #include -#include -#include - namespace winrt { using namespace xaml::Controls::Primitives; using namespace xaml::Media; @@ -94,14 +91,5 @@ bool Is19H1OrHigher() { return IsAPIContractV8Available(); } -bool IsXamlIsland() { - AppPolicyWindowingModel e; - if (FAILED(AppPolicyGetWindowingModel(GetCurrentThreadEffectiveToken(), &e)) || - e == AppPolicyWindowingModel_ClassicDesktop) { - return true; - } - return false; -} - } // namespace uwp }; // namespace react diff --git a/vnext/ReactUWP/Utils/LocalBundleReader.cpp b/vnext/ReactUWP/Utils/LocalBundleReader.cpp index 90421dd4632..305d80bad9c 100644 --- a/vnext/ReactUWP/Utils/LocalBundleReader.cpp +++ b/vnext/ReactUWP/Utils/LocalBundleReader.cpp @@ -18,18 +18,11 @@ namespace uwp { std::future LocalBundleReader::LoadBundleAsync(const std::string &bundleUri) { winrt::hstring str(Microsoft::Common::Unicode::Utf8ToUtf16(bundleUri)); + winrt::Windows::Foundation::Uri uri(str); co_await winrt::resume_background(); - winrt::Windows::Storage::StorageFile file{nullptr}; - - // Supports "ms-appx://" or "ms-appdata://" - if (bundleUri._Starts_with("ms-app")) { - winrt::Windows::Foundation::Uri uri(str); - file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri); - } else { - file = co_await winrt::Windows::Storage::StorageFile::GetFileFromPathAsync(str); - } + auto file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri); // Read the buffer manually to avoid a Utf8 -> Utf16 -> Utf8 encoding // roundtrip. diff --git a/vnext/include/ReactUWP/Utils/Helpers.h b/vnext/include/ReactUWP/Utils/Helpers.h index 3c984a6410c..c7750034230 100644 --- a/vnext/include/ReactUWP/Utils/Helpers.h +++ b/vnext/include/ReactUWP/Utils/Helpers.h @@ -29,7 +29,5 @@ bool IsRS3OrHigher(); bool IsRS4OrHigher(); bool IsRS5OrHigher(); bool Is19H1OrHigher(); - -bool IsXamlIsland(); } // namespace uwp } // namespace react From 06ce53299299970c06ad8d556375d65d2de5cb3b Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Fri, 15 May 2020 12:50:10 -0700 Subject: [PATCH 12/12] remove last MSRN change --- vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj index 1981e4c56ce..8586d47ef81 100644 --- a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +++ b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj @@ -165,7 +165,7 @@ true - winsqlite3.lib;ChakraRT.lib;dxguid.lib;dloadhelper.lib;OneCoreUap.lib;%(AdditionalDependencies) + winsqlite3.lib;ChakraRT.lib;dxguid.lib;dloadhelper.lib;%(AdditionalDependencies) winsqlite3.dll;%(DelayLoadDLLs) Console true