-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add ReactNativeHost to Win32 C++/WinRT ABI #4848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
daeed94
84f2f44
bdc22d9
0af6427
19951b9
027a6e9
1fb0f21
974f81e
79ac4f3
97ee9d0
3174af5
2ab6d47
e258c65
0c9a0ed
e90e444
a980a4b
ae5da6d
f31a713
0455d1e
e0911bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "test bundle build logic, JS function call test", | ||
| "packageName": "react-native-windows", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "none", | ||
| "date": "2020-05-01T01:28:03.315Z" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "add ReactNativeHost to Win32 C++/WinRT ABI", | ||
| "packageName": "react-native-windows", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch", | ||
| "date": "2020-05-10T00:42:52.866Z" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "pch.h" | ||
| #include <Windows.h> | ||
| #include <winrt/base.h> | ||
|
|
||
| extern int32_t __stdcall WINRT_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include "pch.h" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
nit: please add the copyright header. #Resolved
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| #include <CppUnitTest.h> | ||
| #include <winrt/Microsoft.ReactNative.h> | ||
| #include "ActivationFactory.h" | ||
|
|
||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||
|
|
||
| namespace ABITests { | ||
|
|
||
| TEST_CLASS (ReactNativeHostTests) { | ||
| public: | ||
| ReactNativeHostTests() noexcept { | ||
| winrt_activation_handler = WINRT_RoGetActivationFactory; | ||
| } | ||
|
|
||
| TEST_METHOD(Activation_Succeeds) { | ||
| try { | ||
| winrt::Microsoft::ReactNative::ReactNativeHost host{}; | ||
| Assert::IsTrue(true); | ||
| } catch (...) { | ||
| Assert::Fail(); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| } // namespace ABITests | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include <pch.h> | ||
| #include "ReactNativeHost.h" | ||
|
|
||
| #include "Microsoft.ReactNative.ReactNativeHost.g.cpp" | ||
|
|
||
| using namespace winrt::Windows::Foundation::Collections; | ||
|
|
||
| namespace winrt::Microsoft::ReactNative::implementation { | ||
|
|
||
| ReactNativeHost::ReactNativeHost() noexcept { | ||
| // TODO: implement | ||
| } | ||
|
|
||
| IVector<IReactPackageProvider> ReactNativeHost::PackageProviders() noexcept { | ||
| if (!m_packageProviders) { | ||
| m_packageProviders = single_threaded_vector<IReactPackageProvider>(); | ||
| } | ||
|
|
||
| return m_packageProviders; | ||
| } | ||
|
|
||
| void ReactNativeHost::PackageProviders(IVector<IReactPackageProvider> const &value) noexcept { | ||
| m_packageProviders = value; | ||
| } | ||
|
|
||
| ReactNative::ReactInstanceSettings ReactNativeHost::InstanceSettings() noexcept { | ||
| if (!m_instanceSettings) { | ||
| // TODO: implement | ||
| // m_instanceSettings = make<ReactInstanceSettings>(); | ||
| } | ||
|
|
||
| return m_instanceSettings; | ||
| } | ||
|
|
||
| void ReactNativeHost::InstanceSettings(ReactNative::ReactInstanceSettings const &value) noexcept { | ||
| m_instanceSettings = value; | ||
| } | ||
|
|
||
| void ReactNativeHost::ReloadInstance() noexcept { | ||
| // TODO: implement | ||
| } | ||
|
|
||
| void ReactNativeHost::OnSuspend() noexcept { | ||
| // TODO: implement | ||
| } | ||
|
|
||
| void ReactNativeHost::OnEnteredBackground() noexcept { | ||
| // TODO: implement | ||
| } | ||
|
|
||
| void ReactNativeHost::OnLeavingBackground() noexcept { | ||
| // TODO: implement | ||
| } | ||
|
|
||
| void ReactNativeHost::OnResume(OnResumeAction const & /*action*/) noexcept { | ||
| // TODO: implement | ||
| } | ||
|
|
||
| void ReactNativeHost::OnBackPressed() noexcept { | ||
| // TODO: implement | ||
| } | ||
|
|
||
| } // namespace winrt::Microsoft::ReactNative::implementation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <winrt/Windows.Foundation.Collections.h> | ||
|
|
||
| #include "Microsoft.ReactNative.ReactNativeHost.g.h" | ||
|
|
||
| namespace winrt::Microsoft::ReactNative::implementation { | ||
|
|
||
| struct ReactNativeHost : ReactNativeHostT<ReactNativeHost> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It would be nice to reuse files from the Microsoft.ReactNative project in future. #WontFix
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ReactNativeHost() noexcept; | ||
|
|
||
| // property PackageProviders | ||
| Windows::Foundation::Collections::IVector<IReactPackageProvider> PackageProviders() noexcept; | ||
| void PackageProviders(Windows::Foundation::Collections::IVector<IReactPackageProvider> const &value) noexcept; | ||
|
|
||
| // property InstanceSettings | ||
| ReactNative::ReactInstanceSettings InstanceSettings() noexcept; | ||
| void InstanceSettings(ReactNative::ReactInstanceSettings const &value) noexcept; | ||
|
|
||
| void ReloadInstance() noexcept; | ||
|
|
||
| void OnSuspend() noexcept; | ||
| void OnEnteredBackground() noexcept; | ||
| void OnLeavingBackground() noexcept; | ||
| void OnResume(OnResumeAction const &action) noexcept; | ||
| void OnBackPressed() noexcept; | ||
|
|
||
| private: | ||
| ReactNative::ReactInstanceSettings m_instanceSettings{nullptr}; | ||
| Windows::Foundation::Collections::IVector<IReactPackageProvider> m_packageProviders; | ||
| }; | ||
|
|
||
| } // namespace winrt::Microsoft::ReactNative::implementation | ||
|
|
||
| namespace winrt::Microsoft::ReactNative::factory_implementation { | ||
|
|
||
| struct ReactNativeHost : ReactNativeHostT<ReactNativeHost, implementation::ReactNativeHost> {}; | ||
|
|
||
| } // namespace winrt::Microsoft::ReactNative::factory_implementation | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,13 +90,27 @@ | |
| <AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
| <AdditionalOptions>-minpdbpathlen:256</AdditionalOptions> | ||
| </Link> | ||
| <Midl> | ||
| <AdditionalIncludeDirectories>$(ReactNativeWindowsDir)\Microsoft.ReactNative;$(ReactNativeWindowsDir)\Microsoft.ReactNative.Cxx;</AdditionalIncludeDirectories> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wonder why is it need for the MIDL directories.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's for I think it's a backwards build dependency we should change. In reply to: 423288009 [](ancestors = 423288009) |
||
| </Midl> | ||
| </ItemDefinitionGroup> | ||
| <Import Project="$(ReactNativeWindowsDir)\PropertySheets\ReactCommunity.cpp.props" /> | ||
| <ItemGroup> | ||
| <Midl Include="ABI\MemoryTracker.idl" /> | ||
| <Midl Include="ABI\MessageQueue.idl" /> | ||
| <Midl Include="ABI\NativeLogging.idl" /> | ||
| <Midl Include="ABI\NativeTracing.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\ReactNativeHost.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\IReactPackageProvider.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\ReactInstanceSettings.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\IReactPackageBuilder.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\IReactModuleBuilder.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\IJSValueWriter.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\IReactContext.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\IJSValueReader.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\IViewManager.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\IReactPropertyBag.idl" /> | ||
| <Midl Include="..\Microsoft.ReactNative\RedBoxHandler.idl" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClCompile Include="ABI\MemoryTracker.cpp"> | ||
|
|
@@ -115,6 +129,10 @@ | |
| <DependentUpon>ABI\NativeTracing.idl</DependentUpon> | ||
| <ObjectFileName>$(IntDir)\ABI\</ObjectFileName> | ||
| </ClCompile> | ||
| <ClCompile Include="ABI\ReactNativeHost.cpp"> | ||
| <DependentUpon>..\Microsoft.ReactNative\ReactNativeHost.idl</DependentUpon> | ||
| <ObjectFileName>$(IntDir)\ABI\</ObjectFileName> | ||
| </ClCompile> | ||
| <ClCompile Include="CxxReactWin32\JSBigString.cpp" /> | ||
| <ClCompile Include="DevSupportManager.cpp" /> | ||
| <ClCompile Include="Executors\WebSocketJSExecutor.cpp" /> | ||
|
|
@@ -145,6 +163,10 @@ | |
| <ClInclude Include="ABI\NativeTraceEventSource.h"> | ||
| <DependentUpon>ABI\NativeTracing.idl</DependentUpon> | ||
| </ClInclude> | ||
| <ClInclude Include="ABI\ReactNativeHost.h"> | ||
| <DependentUpon>..\Microsoft.ReactNative\ReactNativeHost.idl</DependentUpon> | ||
| <SubType>Code</SubType> | ||
| </ClInclude> | ||
| <ClInclude Include="DevSupportManager.h" /> | ||
| <ClInclude Include="Executors\WebSocketJSExecutor.h" /> | ||
| <ClInclude Include="LazyDevSupportManager.h" /> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to have a build dependency somewhere. The Microsoft.ReactNative.winmd must be created before the test project. #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should get this indirectly through the dependency on the DLL in line 88.
In reply to: 423290781 [](ancestors = 423290781)