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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Fixes for bundle loading and back handler crash using xaml islands",
"packageName": "react-native-windows",
"email": "acoates@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-05-15T19:40:09.796Z"
}
2 changes: 1 addition & 1 deletion vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<AdditionalDependencies>winsqlite3.lib;ChakraRT.lib;dxguid.lib;dloadhelper.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>winsqlite3.lib;ChakraRT.lib;dxguid.lib;dloadhelper.lib;OneCoreUap.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>winsqlite3.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<SubSystem>Console</SubSystem>
<GenerateWindowsMetadata>true</GenerateWindowsMetadata>
Expand Down
5 changes: 5 additions & 0 deletions vnext/Microsoft.ReactNative/Pch/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
#define NOGDI
#endif

#undef WINAPI_FAMILY
#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure XBOX team isn't impacted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@namrog84 FYI


#include <combaseapi.h>
#include <guiddef.h>
#include <intrin.h>
#include <unknwn.h>
#include <windows.h>
// When WINAPI_FAMILY is DESKTOP_APP, windows.h creates a macro for GetCurrentTime, which conflicts with other headers
#undef GetCurrentTime

#include "CppWinRTIncludes.h"
#include "HResult.h"
Expand Down
9 changes: 9 additions & 0 deletions vnext/Microsoft.ReactNative/Views/ReactRootControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <object/unknownObject.h>

#include <ReactHost/MsoUtils.h>
#include <Utils/Helpers.h>

#include <UI.Xaml.Controls.Primitives.h>
#include <UI.Xaml.Controls.h>
Expand Down Expand Up @@ -617,6 +618,14 @@ 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 if 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,
Expand Down
5 changes: 5 additions & 0 deletions vnext/ReactUWP/Pch/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
#define NOGDI
#endif

#undef WINAPI_FAMILY
#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP

#include <combaseapi.h>
#include <guiddef.h>
#include <intrin.h>
#include <unknwn.h>
#include <windows.h>
// When WINAPI_FAMILY is DESKTOP_APP, windows.h creates a macro for GetCurrentTime, which conflicts with other headers
#undef GetCurrentTime

#include "CppWinRTIncludes.h"

Expand Down
12 changes: 12 additions & 0 deletions vnext/ReactUWP/Utils/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <Utils/Helpers.h>
#include <winrt/Windows.Foundation.Metadata.h>

#include <appmodel.h>
#include <processthreadsapi.h>

namespace winrt {
using namespace xaml::Controls::Primitives;
using namespace xaml::Media;
Expand Down Expand Up @@ -91,5 +94,14 @@ bool Is19H1OrHigher() {
return IsAPIContractV8Available();
}

bool IsXamlIsland() {
AppPolicyWindowingModel e;
if (FAILED(AppPolicyGetWindowingModel(GetCurrentThreadEffectiveToken(), &e)) ||
e == AppPolicyWindowingModel_ClassicDesktop) {
return true;
}
return false;
}

} // namespace uwp
}; // namespace react
11 changes: 9 additions & 2 deletions vnext/ReactUWP/Utils/LocalBundleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ namespace uwp {

std::future<std::string> 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.
Expand Down
2 changes: 2 additions & 0 deletions vnext/include/ReactUWP/Utils/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ bool IsRS3OrHigher();
bool IsRS4OrHigher();
bool IsRS5OrHigher();
bool Is19H1OrHigher();

bool IsXamlIsland();
} // namespace uwp
} // namespace react