Skip to content
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

Fix event setup codepath #202

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix event setup codepath",
"packageName": "react-native-xaml",
"email": "[email protected]",
"dependentChangeType": "patch"
}
13 changes: 6 additions & 7 deletions package/windows/ReactNativeXaml/XamlMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ using namespace winrt::Microsoft::ReactNative;
#define MAKE_GET_DP(type, prop) IsType<type>, []() { return type::prop(); }

void XamlMetadata::SetupEventDispatcher(const IReactContext& reactContext) {
m_reactContext = reactContext;
std::once_flag inited;
std::call_once(inited, [ctx = reactContext, this]() {
ExecuteJsi(ctx, [shared = shared_from_this()](facebook::jsi::Runtime& rt) {
if (!m_reactContext) {
m_reactContext = reactContext;
}

auto obj = rt.global().createFromHostObject(rt, std::make_shared<XamlObject>());
rt.global().setProperty(rt, jsi::PropNameID::forAscii(rt, "xaml"), obj);
if (!m_receiveEvent.has_value()) {
ExecuteJsi(m_reactContext, [shared = shared_from_this()](facebook::jsi::Runtime& rt) {
auto batchedBridge = rt.global().getProperty(rt, "__fbBatchedBridge");
if (!batchedBridge.isUndefined() && batchedBridge.isObject()) {
if (auto vm = shared.get()) {
Expand All @@ -46,7 +45,7 @@ void XamlMetadata::SetupEventDispatcher(const IReactContext& reactContext) {
}
}
});
jonthysell marked this conversation as resolved.
Show resolved Hide resolved
});
}
}

FrameworkElement Wrap(const winrt::Windows::Foundation::IInspectable& d) {
Expand Down