|
@@ -32,6 +32,13 @@ namespace winrt::ReactNativeWebView::implementation {
|
32
|
32
|
RegisterEvents();
|
33
|
33
|
}
|
34
|
34
|
|
|
35
|
+ ReactWebView::~ReactWebView()
|
|
36
|
+ {
|
|
37
|
+ if (m_messagingEnabled) {
|
|
38
|
+ m_webBridge.MessagePostedEvent(m_message_token);
|
|
39
|
+ }
|
|
40
|
+ }
|
|
41
|
+
|
35
|
42
|
void ReactWebView::RegisterEvents() {
|
36
|
43
|
m_navigationStartingRevoker = m_webView.NavigationStarting(
|
37
|
44
|
winrt::auto_revoke, [ref = get_weak()](auto const& sender, auto const& args) {
|
|
@@ -88,11 +95,8 @@ namespace winrt::ReactNativeWebView::implementation {
|
88
|
95
|
if (m_messagingEnabled) {
|
89
|
96
|
auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
|
90
|
97
|
m_webBridge = WebViewBridge::WebBridge(tag);
|
91
|
|
- m_webBridge.MessagePostedEvent(winrt::auto_revoke, [ref = get_weak()](const int32_t& message) {
|
92
|
|
- OutputDebugStringW(L"> ReactWebView:MessagePostedEvent");
|
93
|
|
- if (auto self = ref.get()) {
|
94
|
|
- self->OnMessagePosted(message);
|
95
|
|
- }
|
|
98
|
+ m_message_token = m_webBridge.MessagePostedEvent([this](const int32_t& message) {
|
|
99
|
+ this->OnMessagePosted(message);
|
96
|
100
|
});
|
97
|
101
|
webView.AddWebAllowedObject(L"__RN_WEBVIEW_JS_BRIDGE", m_webBridge);
|
98
|
102
|
}
|
|
@@ -100,9 +104,10 @@ namespace winrt::ReactNativeWebView::implementation {
|
100
|
104
|
|
101
|
105
|
void ReactWebView::OnMessagePosted(const int32_t& message)
|
102
|
106
|
{
|
|
107
|
+ OutputDebugStringW(L"> ReactWebView:OnMessagePosted received \n");
|
|
108
|
+
|
103
|
109
|
// TODO: send to RN
|
104
|
110
|
// PostMessage(winrt::hstring(args.Value()));
|
105
|
|
- OutputDebugStringW(L"> ReactWebView:OnMessagePosted received");
|
106
|
111
|
}
|
107
|
112
|
|
108
|
113
|
void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
|