-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Removed the ref count work around from classes derived from ReactApplication #4755
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
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": "prerelease", | ||
| "comment": "Removed the ref count work around from classes derived from ReactApplications", | ||
| "packageName": "react-native-windows", | ||
| "email": "vmorozov@microsoft.com", | ||
| "dependentChangeType": "patch", | ||
| "date": "2020-04-30T15:22:39.524Z" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,15 +4,55 @@ | |
| #pragma once | ||
|
|
||
| #include "ReactApplication.g.h" | ||
| #include <CppWinRTIncludes.h> | ||
| #include "ReactNativeHost.h" | ||
|
|
||
| namespace winrt::Microsoft::ReactNative::implementation { | ||
|
|
||
| struct ReactApplication : ReactApplicationT<ReactApplication> { | ||
| using Super = ReactApplicationT<ReactApplication>; | ||
| // NoDefaultCtorReactApplication_base is a copy of the generated ReactApplication_base | ||
| // without the default constructor where it calls a factory for the base type. | ||
| // This is done to fix the aggregation issue in types inheriting from the ReactApplication. | ||
| // We call the factory in the ReactApplication constructor where we can pass correct | ||
| // 'outer' interface. | ||
| // | ||
| // This class must match the generated ReactApplication_base. | ||
| // It must be updated if the shape of generated ReactApplication_base is changed in future. | ||
| // The only difference is that this class has no default constructor. | ||
| template <typename D, typename... I> | ||
| struct __declspec(empty_bases) NoDefaultCtorReactApplication_base | ||
| : implements< | ||
| D, | ||
| Microsoft::ReactNative::ReactApplication, | ||
| composable, | ||
| composing, | ||
| xaml::IApplicationOverrides, | ||
| xaml::IApplicationOverrides2, | ||
| I...>, | ||
| impl::require<D, xaml::IApplication, xaml::IApplication2, xaml::IApplication3>, | ||
| impl::base<D, xaml::Application>, | ||
| xaml::IApplicationOverridesT<D>, | ||
| xaml::IApplicationOverrides2T<D> { | ||
| using base_type = NoDefaultCtorReactApplication_base; | ||
| using class_type = Microsoft::ReactNative::ReactApplication; | ||
| using implements_type = typename NoDefaultCtorReactApplication_base::implements_type; | ||
| using implements_type::implements_type; | ||
| using composable_base = xaml::Application; | ||
|
|
||
| hstring GetRuntimeClassName() const { | ||
| return L"Microsoft.ReactNative.ReactApplication"; | ||
| } | ||
|
|
||
| protected: | ||
| using dispatch = impl::dispatch_to_overridable<D, xaml::IApplicationOverrides, xaml::IApplicationOverrides2>; | ||
| auto overridable() noexcept { | ||
| return dispatch::overridable(static_cast<D &>(*this)); | ||
| } | ||
| }; | ||
|
|
||
| struct ReactApplication : NoDefaultCtorReactApplication_base<ReactApplication> { | ||
|
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. Why did the base type for this need to change? Was there something provided in the generated code that was conflicting with this override?
Member
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. The default constructor of the ReactApplicationT calls the factory for the XAML Application class. If I do not replace the base class, then the XAML Application is going to be created twice: one in the base default constructor and the second in the our constructor with the outer reference. Ideally, the generated class must have two constructors or one with an optional outer parameter. In reply to: 418151912 [](ancestors = 418151912)
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. Oh I see. Yes that makes sense. |
||
| public: // ReactApplication ABI API | ||
| ReactApplication() noexcept; | ||
| ReactApplication(); | ||
| ReactApplication(IInspectable const &outer) noexcept; | ||
|
|
||
| ReactNative::ReactInstanceSettings InstanceSettings() noexcept; | ||
| void InstanceSettings(ReactNative::ReactInstanceSettings const &value) noexcept; | ||
|
|
@@ -57,6 +97,13 @@ struct ReactApplication : ReactApplicationT<ReactApplication> { | |
|
|
||
| namespace winrt::Microsoft::ReactNative::factory_implementation { | ||
|
|
||
| struct ReactApplication : ReactApplicationT<ReactApplication, implementation::ReactApplication> {}; | ||
| // Override the CreateInstance method to pass baseInterface to the ReactApplication constructor | ||
| // to support correct COM aggregation that is need to inherit from the ReactApplication. | ||
| struct ReactApplication : ReactApplicationT<ReactApplication, implementation::ReactApplication> { | ||
| auto CreateInstance(IInspectable const &baseInterface, IInspectable &innerInterface) { | ||
| return impl::composable_factory<implementation::ReactApplication>::template CreateInstance< | ||
| Microsoft::ReactNative::ReactApplication>(baseInterface, innerInterface, baseInterface); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace winrt::Microsoft::ReactNative::factory_implementation | ||
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.
(nit) what does this do?
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.
It brings constructors from the implements_type base class. I am not sure why it is need. I effectively copy&pasted the generated code and did minimal changes to it: deleted default constructor.
In reply to: 418146298 [](ancestors = 418146298)