-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implemented support for native module std::weak_ptr #4980
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
Conversation
NikoAri
left a comment
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.
![]()
|
Hello @vmoroz! Because this pull request has the Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 10 hours, a condition that will be fulfilled in about 7 hours 48 minutes. No worries though, I will be back when the time is right! 😉 p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
|
Removing "Backport to 0.62" since we're about to rename it to "Backported to 0.62" as part of backporting label migration. This has been approved to go into 0.62 though, and such has the "Backport approved" label. |
* Implemented support for native module std::weak_ptr (#4980) (cherry picked from commit c23d3de) # Conflicts: # packages/microsoft-reactnative-sampleapps/windows/SampleLibraryCPP/SampleModuleCPP.h * Fix ReactInstance error state to avoid crashes (#4986) * Fix ReactInstance error state to avoid crashes * Change files * Clean m_redboxContent after RedBox closing (cherry picked from commit 05779f2) * ReactNotificationService to allow communication between native modules (#4953) Only picking up changes required for ReactDispatcher. (cherry picked from commit baba475) * Add UIDispatcher property to ReactInstanceSettings and IReactContext (#5007) * Add UIDispatcher property to ReactInstanceSettings and IReactContext * Change files * Fix ReactWindows-Desktop.sln compilation * Address PR feedback for the GetCurrentUIThreadQueue * Remove UIDispatcher setting from Playground project (cherry picked from commit 7236d61) # Conflicts: # packages/playground/windows/playground-win32/Playground-Win32.cpp # vnext/Desktop/React.Windows.Desktop.vcxproj.filters # vnext/Microsoft.ReactNative.Cxx.UnitTests/ReactContextTest.cpp # vnext/Microsoft.ReactNative.Cxx.UnitTests/ReactModuleBuilderMock.h # vnext/Microsoft.ReactNative.Cxx/ReactContext.h # vnext/Microsoft.ReactNative.Managed.UnitTests/ReactModuleBuilderMock.cs # vnext/Microsoft.ReactNative/IReactContext.cpp # vnext/Microsoft.ReactNative/IReactContext.h # vnext/Microsoft.ReactNative/IReactContext.idl # vnext/Microsoft.ReactNative/ReactInstanceSettings.h # vnext/Microsoft.ReactNative/ReactInstanceSettings.idl * Fix PlaygroundWin32 compilation
This change is to address a customer need to be able to get a
std::weak_ptrto a native module in case if the module must subscribe to some events. Since, a native module lifetime is bound to the React instance lifetime, we cannot usethispointer and we better use thestd::weak_ptr<T>.In this PR we enable the native modules to be inherited from the
std::enable_shared_from_this<T>that allows use of theweak_from_this()function to getstd::weak_ptr<T>to the module.To support the new functionality we are doing the following changes:
MakeDefaultReactModuleWrapper- the default factory that wraps up native module intoReactNonAbiValue<TModule>to pass the module across the ABI boundary.MakeDefaultSharedPtrReactModuleWrapper- the default factory that wraps up native module intoReactNonAbiValue<shared_ptr<TModule>>in case if module is inherited fromstd::enable_shared_from_this<T>.The custom factory can be associated with a module type by providing
GetReactModuleFactoryfunction overload that has two argumentsModule *pointer type andint. Theintparameter is used to give the overload higher priority than the defaultGetReactModuleFactoryfunction where we useint *when we pass 0 as a second argument.To show the use of the
std::weak_ptrwe have added a newSampleSharedCppModulemodule to the sample project. It shows how thestd::weak_ptrcan be used with help of thestd::enable_shared_from_thisbase andweak_from_this()method call.Microsoft Reviewers: Open in CodeFlow