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/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 7011653d84c..8ab51da8f92 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.sln b/packages/playground/windows/playground-win32.sln index 705febd73f7..969d4742d16 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,37 +17,39 @@ 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("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "..\..\..\vnext\Common\Common.vcxproj", "{FCA38F3C-7C73-4C47-BE4E-32F77FA8538D}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.ReactNative.Cxx", "..\..\..\vnext\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems", "{DA8B35B3-DA00-4B02-BDE6-6A397B3FD46B}" +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\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9 ..\..\..\vnext\ReactWindowsCore\ReactWindowsCore.vcxitems*{11c084a3-a57c-4296-a679-cac17b603144}*SharedItemsImports = 4 - ..\..\..\vnext\Chakra\Chakra.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4 - ..\..\..\vnext\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.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\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9 ..\..\..\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 @@ -93,18 +90,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 @@ -129,6 +114,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 @@ -157,6 +154,19 @@ 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} + {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..fa1dfc6f319 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,72 +12,55 @@ #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))); - - 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 { + OutputDebugStringA("----- Begin RedBox -----\n"); - return viewManagers; - } -}; + 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; + } -struct HwndReactInstanceCreator : ::react::uwp::IReactInstanceCreator { - HwndReactInstanceCreator(HWND hwnd) { - m_hwnd = hwnd; + OutputDebugString(info.Message().c_str()); + OutputDebugStringA("\n----- End RedBox -----\n"); } - 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 { @@ -95,9 +69,12 @@ 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; bool m_useWebDebugger{true}; bool m_liveReloadEnabled{true}; @@ -106,8 +83,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) {} @@ -115,54 +90,69 @@ struct WindowData { return reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); } - 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::make_shared(); - std::shared_ptr viewManagerProvider = - std::make_shared(); - - m_instance = react::uwp::CreateReactInstance(moduleLoader, viewManagerProvider); - - 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; + winrt::Microsoft::ReactNative::ReactNativeHost Host() noexcept { + if (!m_host) { + m_host = winrt::Microsoft::ReactNative::ReactNativeHost(); + m_host.InstanceSettings(InstanceSettings()); + m_host.PackageProviders(PackageProviders()); + } - settings.EnableDeveloperMenu = true; + return m_host; + } + winrt::Microsoft::ReactNative::ReactInstanceSettings InstanceSettings() noexcept { + if (!m_instanceSettings) { + m_instanceSettings = winrt::Microsoft::ReactNative::ReactInstanceSettings(); + } - settings.LoggingCallback = [](facebook::react::RCTLogLevel logLevel, const char *message) { - OutputDebugStringA("In LoggingCallback"); - OutputDebugStringA(message); - }; + return m_instanceSettings; + } - m_instance->Start(m_instance, settings); - m_instance->loadBundle(Microsoft::Common::Unicode::Utf16ToUtf8(m_bundleFile)); + winrt::Windows::Foundation::Collections::IVector + PackageProviders() noexcept { + if (!m_packageProviders) { + m_packageProviders = winrt::single_threaded_vector(); + } - folly::dynamic initialProps = folly::dynamic::object(); + return m_packageProviders; + } - // Retrieve ABI pointer from C++/CX pointer - auto rootElement = m_desktopWindowXamlSource.Content().as(); + 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()) { PCWSTR appName = (m_bundleFile == LR"(Samples\rntester)") ? L"RNTesterApp" : L"Bootstrap"; - // Create the root view - m_rootView = react::uwp::CreateReactRootView(rootElement, appName, m_instanceCreator); + 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); + host.InstanceSettings().RedBoxHandler(winrt::make()); + 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(); + + m_reactRootView = winrt::Microsoft::ReactNative::ReactRootView(); + m_reactRootView.ComponentName(host.InstanceSettings().MainComponentName()); + m_reactRootView.ReactNativeHost(host); - m_rootView->SetInitialProps(std::move(initialProps)); - m_rootView->SetInstanceCreator(m_instanceCreator); - m_rootView->AttachRoot(); + // Retrieve ABI pointer from C++/CX pointer + auto rootElement = m_desktopWindowXamlSource.Content().as(); + rootElement.Children().Clear(); + rootElement.Children().Append(m_reactRootView); } break; @@ -193,16 +183,10 @@ 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 +197,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 +226,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 +275,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 +297,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 +305,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,50 +325,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: { @@ -415,14 +355,12 @@ 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()); - WUXH::DesktopWindowXamlSource desktopXamlSource; WNDCLASSEXW wcex = {}; diff --git a/packages/playground/windows/playground-win32/Playground-win32.vcxproj b/packages/playground/windows/playground-win32/Playground-win32.vcxproj index 19af51184fe..60bb691b19c 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 @@ -10,9 +11,6 @@ false - - - Debug @@ -42,6 +40,7 @@ Application Unicode + v142 true @@ -51,7 +50,6 @@ true - @@ -68,34 +66,30 @@ - StdCall - true Use pch.h - true + $(IntDir)pch.pch Level3 + true + %(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 - @@ -116,20 +110,23 @@ - - {2d5d43d9-cffc-4c40-b4cd-02efb4e2742b} - + - + + {f7d32bd0-2749-483e-9a0d-1635ef7e3136} + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\AppxPackage\Microsoft.AppXPackage.Targets resources.pri + @@ -138,6 +135,8 @@ 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}. + + 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