// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #include "pch.h" #include "RedBoxHandler.h" #if __has_include("RedBoxHelper.g.cpp") #include "RedBoxHelper.g.cpp" #endif #include #include #include #include namespace winrt::Microsoft::ReactNative::implementation { Mso::React::ErrorInfo CreateErrorInfo(const IRedBoxErrorInfo &info) { Mso::React::ErrorInfo ei; ei.Id = info.Id(); ei.Message = ::Microsoft::Common::Unicode::Utf16ToUtf8(info.Message()); for (const auto &frame : info.Callstack()) { Mso::React::ErrorFrameInfo efi; efi.Method = ::Microsoft::Common::Unicode::Utf16ToUtf8(frame.Method()); efi.File = ::Microsoft::Common::Unicode::Utf16ToUtf8(frame.File()); efi.Line = frame.Line(); efi.Column = frame.Column(); ei.Callstack.push_back(std::move(efi)); } return ei; } struct DefaultRedBoxHandler : winrt::implements { DefaultRedBoxHandler(winrt::Microsoft::ReactNative::ReactNativeHost const &host) noexcept { auto hostImpl = winrt::get_self(host); Mso::WeakPtr wkHost(hostImpl->ReactHost()); m_redBoxHandler = Mso::React::CreateDefaultRedBoxHandler( ReactPropertyBag(host.InstanceSettings().Properties()), std::move(wkHost), *ReactDispatcher::GetUIDispatchQueue2(host.InstanceSettings().Properties())); } void ShowNewError(IRedBoxErrorInfo const &info, RedBoxErrorType type) noexcept { m_redBoxHandler->showNewError( CreateErrorInfo(info), static_cast(static_cast(type))); } bool IsDevSupportEnabled() noexcept { return m_redBoxHandler->isDevSupportEnabled(); } void UpdateError(IRedBoxErrorInfo const &info) noexcept { m_redBoxHandler->updateError(std::move(CreateErrorInfo(info))); } void DismissRedBox() noexcept { m_redBoxHandler->dismissRedbox(); } private: std::shared_ptr m_redBoxHandler; }; IRedBoxHandler RedBoxHelper::CreateDefaultHandler(winrt::Microsoft::ReactNative::ReactNativeHost const &host) noexcept { return winrt::make(host); } } // namespace winrt::Microsoft::ReactNative::implementation