Ver código fonte

Revert "Manage to build webview using Visual Studio"

This reverts commit 6f60262d21.
Tero Paananen 4 anos atrás
pai
commit
8fabfe73d6

+ 0
- 1
example/windows/WebViewWindows.sln Ver arquivo

45
 Global
45
 Global
46
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution
46
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution
47
 		..\..\node_modules\react-native-windows\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9
47
 		..\..\node_modules\react-native-windows\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9
48
-		..\..\node_modules\react-native-windows\ReactWindowsCore\ReactWindowsCore.vcxitems*{11c084a3-a57c-4296-a679-cac17b603144}*SharedItemsImports = 4
49
 		..\..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9
48
 		..\..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9
50
 		..\..\node_modules\react-native-windows\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13
49
 		..\..\node_modules\react-native-windows\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13
51
 		..\..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{729d9af8-cd9e-4427-9f6c-fb757e287729}*SharedItemsImports = 4
50
 		..\..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{729d9af8-cd9e-4427-9f6c-fb757e287729}*SharedItemsImports = 4

+ 1
- 1
package.json Ver arquivo

65
     "react": "16.11.0",
65
     "react": "16.11.0",
66
     "react-native": "0.62.2",
66
     "react-native": "0.62.2",
67
     "react-native-macos": "0.60.0-microsoft.73",
67
     "react-native-macos": "0.60.0-microsoft.73",
68
-    "react-native-windows": "^0.62.5",
68
+    "react-native-windows": "^0.62.0-0",
69
     "semantic-release": "15.13.24",
69
     "semantic-release": "15.13.24",
70
     "typescript": "3.8.3",
70
     "typescript": "3.8.3",
71
     "appium": "1.17.0",
71
     "appium": "1.17.0",

+ 0
- 3
windows/ReactNativeWebView.sln Ver arquivo

32
 Global
32
 Global
33
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution
33
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution
34
 		..\node_modules\react-native-windows\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9
34
 		..\node_modules\react-native-windows\JSI\Shared\JSI.Shared.vcxitems*{0cc28589-39e4-4288-b162-97b959f8b843}*SharedItemsImports = 9
35
-		..\node_modules\react-native-windows\ReactWindowsCore\ReactWindowsCore.vcxitems*{11c084a3-a57c-4296-a679-cac17b603144}*SharedItemsImports = 4
36
 		..\node_modules\react-native-windows\Chakra\Chakra.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
35
 		..\node_modules\react-native-windows\Chakra\Chakra.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
37
-		..\node_modules\react-native-windows\Mso\Mso.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
38
 		..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
36
 		..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
39
 		..\node_modules\react-native-windows\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13
37
 		..\node_modules\react-native-windows\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13
40
 		..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{729d9af8-cd9e-4427-9f6c-fb757e287729}*SharedItemsImports = 4
38
 		..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{729d9af8-cd9e-4427-9f6c-fb757e287729}*SharedItemsImports = 4
43
 		..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{da8b35b3-da00-4b02-bde6-6a397b3fd46b}*SharedItemsImports = 9
41
 		..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{da8b35b3-da00-4b02-bde6-6a397b3fd46b}*SharedItemsImports = 9
44
 		..\node_modules\react-native-windows\Chakra\Chakra.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
42
 		..\node_modules\react-native-windows\Chakra\Chakra.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
45
 		..\node_modules\react-native-windows\JSI\Shared\JSI.Shared.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
43
 		..\node_modules\react-native-windows\JSI\Shared\JSI.Shared.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
46
-		..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
47
 		..\node_modules\react-native-windows\Mso\Mso.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
44
 		..\node_modules\react-native-windows\Mso\Mso.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
48
 		..\node_modules\react-native-windows\Shared\Shared.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
45
 		..\node_modules\react-native-windows\Shared\Shared.vcxitems*{f7d32bd0-2749-483e-9a0d-1635ef7e3136}*SharedItemsImports = 4
49
 	EndGlobalSection
46
 	EndGlobalSection

+ 20
- 17
windows/ReactNativeWebView/ReactWebView.cpp Ver arquivo

26
 #else
26
 #else
27
         m_webView = winrt::WebView();
27
         m_webView = winrt::WebView();
28
 #endif
28
 #endif
29
-        this->Content(m_webView);
30
         RegisterEvents();
29
         RegisterEvents();
31
     }
30
     }
32
 
31
 
32
+    winrt::WebView ReactWebView::GetView() {
33
+        return m_webView;
34
+    }
35
+
33
     void ReactWebView::RegisterEvents() {
36
     void ReactWebView::RegisterEvents() {
34
         m_navigationStartingRevoker = m_webView.NavigationStarting(
37
         m_navigationStartingRevoker = m_webView.NavigationStarting(
35
             winrt::auto_revoke, [ref = get_weak()](auto const& sender, auto const& args) {
38
             winrt::auto_revoke, [ref = get_weak()](auto const& sender, auto const& args) {
61
             });
64
             });
62
     }
65
     }
63
 
66
 
64
-    void ReactWebView::WriteWebViewNavigationEventArg(winrt::WebView const& sender, winrt::IJSValueWriter const& eventDataWriter) {
65
-        auto tag = this->GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
66
-        WriteProperty(eventDataWriter, L"canGoBack", sender.CanGoBack());
67
-        WriteProperty(eventDataWriter, L"canGoForward", sender.CanGoForward());
68
-        WriteProperty(eventDataWriter, L"loading", !sender.IsLoaded());
67
+    void ReactWebView::WriteWebViewNavigationEventArg(winrt::IJSValueWriter const& eventDataWriter) {
68
+        auto tag = m_webView.GetValue(winrt::FrameworkElement::TagProperty()).as<winrt::IPropertyValue>().GetInt64();
69
+        WriteProperty(eventDataWriter, L"canGoBack", m_webView.CanGoBack());
70
+        WriteProperty(eventDataWriter, L"canGoForward", m_webView.CanGoForward());
71
+        WriteProperty(eventDataWriter, L"loading", !m_webView.IsLoaded());
69
         WriteProperty(eventDataWriter, L"target", tag);
72
         WriteProperty(eventDataWriter, L"target", tag);
70
-        WriteProperty(eventDataWriter, L"title", sender.DocumentTitle());
71
-        if (auto uri = sender.Source()) {
72
-          WriteProperty(eventDataWriter, L"url", uri.AbsoluteCanonicalUri());
73
+        WriteProperty(eventDataWriter, L"title", m_webView.DocumentTitle());
74
+        if (auto uri = m_webView.Source()) {
75
+            WriteProperty(eventDataWriter, L"url", uri.AbsoluteCanonicalUri());
73
         }
76
         }
74
     }
77
     }
75
 
78
 
76
     void ReactWebView::OnNavigationStarting(winrt::WebView const& webView, winrt::WebViewNavigationStartingEventArgs const& /*args*/) {
79
     void ReactWebView::OnNavigationStarting(winrt::WebView const& webView, winrt::WebViewNavigationStartingEventArgs const& /*args*/) {
77
         m_reactContext.DispatchEvent(
80
         m_reactContext.DispatchEvent(
78
-            *this,
81
+            webView,
79
             L"topLoadingStart",
82
             L"topLoadingStart",
80
             [&](winrt::IJSValueWriter const& eventDataWriter) noexcept {
83
             [&](winrt::IJSValueWriter const& eventDataWriter) noexcept {
81
                 eventDataWriter.WriteObjectBegin();
84
                 eventDataWriter.WriteObjectBegin();
82
-                WriteWebViewNavigationEventArg(webView, eventDataWriter);
85
+                WriteWebViewNavigationEventArg(eventDataWriter);
83
                 eventDataWriter.WriteObjectEnd();
86
                 eventDataWriter.WriteObjectEnd();
84
             });
87
             });
85
     }
88
     }
86
 
89
 
87
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
90
     void ReactWebView::OnNavigationCompleted(winrt::WebView const& webView, winrt::WebViewNavigationCompletedEventArgs const& /*args*/) {
88
         m_reactContext.DispatchEvent(
91
         m_reactContext.DispatchEvent(
89
-            *this,
92
+            webView,
90
             L"topLoadingFinish",
93
             L"topLoadingFinish",
91
             [&](winrt::IJSValueWriter const& eventDataWriter) noexcept {
94
             [&](winrt::IJSValueWriter const& eventDataWriter) noexcept {
92
                 eventDataWriter.WriteObjectBegin();
95
                 eventDataWriter.WriteObjectBegin();
93
-                WriteWebViewNavigationEventArg(webView, eventDataWriter);
96
+                WriteWebViewNavigationEventArg(eventDataWriter);
94
                 eventDataWriter.WriteObjectEnd();
97
                 eventDataWriter.WriteObjectEnd();
95
             });
98
             });
96
 
99
 
97
         winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
100
         winrt::hstring windowAlert = L"window.alert = function (msg) {window.external.notify(`{\"type\":\"__alert\",\"message\":\"${msg}\"}`)};";
98
         winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {window.external.notify(String(data))}};";
101
         winrt::hstring postMessage = L"window.ReactNativeWebView = {postMessage: function (data) {window.external.notify(String(data))}};";
99
-        webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
102
+        m_webView.InvokeScriptAsync(L"eval", { windowAlert + postMessage });
100
     }
103
     }
101
 
104
 
102
     void ReactWebView::OnNavigationFailed(winrt::IInspectable const& /*sender*/, winrt::WebViewNavigationFailedEventArgs const& args) {
105
     void ReactWebView::OnNavigationFailed(winrt::IInspectable const& /*sender*/, winrt::WebViewNavigationFailedEventArgs const& args) {
103
         m_reactContext.DispatchEvent(
106
         m_reactContext.DispatchEvent(
104
-            *this,
107
+            m_webView,
105
             L"topLoadingError",
108
             L"topLoadingError",
106
             [&](winrt::IJSValueWriter const& eventDataWriter) noexcept {
109
             [&](winrt::IJSValueWriter const& eventDataWriter) noexcept {
107
                 auto httpCode = static_cast<int32_t>(args.WebErrorStatus());
110
                 auto httpCode = static_cast<int32_t>(args.WebErrorStatus());
108
                 eventDataWriter.WriteObjectBegin();
111
                 eventDataWriter.WriteObjectBegin();
109
                 {
112
                 {
110
                     WriteProperty(eventDataWriter, L"code", httpCode);
113
                     WriteProperty(eventDataWriter, L"code", httpCode);
111
-                    WriteWebViewNavigationEventArg(m_webView, eventDataWriter);
114
+                    WriteWebViewNavigationEventArg(eventDataWriter);
112
                 }
115
                 }
113
                 eventDataWriter.WriteObjectEnd();
116
                 eventDataWriter.WriteObjectEnd();
114
             });
117
             });
131
 
134
 
132
     void ReactWebView::PostMessage(winrt::hstring const& message) {
135
     void ReactWebView::PostMessage(winrt::hstring const& message) {
133
         m_reactContext.DispatchEvent(
136
         m_reactContext.DispatchEvent(
134
-            *this,
137
+            m_webView,
135
             L"topMessage",
138
             L"topMessage",
136
             [&](winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter) noexcept {
139
             [&](winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter) noexcept {
137
                 eventDataWriter.WriteObjectBegin();
140
                 eventDataWriter.WriteObjectBegin();

+ 2
- 1
windows/ReactNativeWebView/ReactWebView.h Ver arquivo

12
     class ReactWebView : public ReactWebViewT<ReactWebView> {
12
     class ReactWebView : public ReactWebViewT<ReactWebView> {
13
     public:
13
     public:
14
         ReactWebView(Microsoft::ReactNative::IReactContext const& reactContext);
14
         ReactWebView(Microsoft::ReactNative::IReactContext const& reactContext);
15
+        winrt::Windows::UI::Xaml::Controls::WebView GetView();
15
         void PostMessage(winrt::hstring const& message);
16
         void PostMessage(winrt::hstring const& message);
16
 
17
 
17
     private:
18
     private:
23
         winrt::Windows::UI::Xaml::Controls::WebView::ScriptNotify_revoker m_scriptNotifyRevoker{};
24
         winrt::Windows::UI::Xaml::Controls::WebView::ScriptNotify_revoker m_scriptNotifyRevoker{};
24
 
25
 
25
         void RegisterEvents();
26
         void RegisterEvents();
26
-        void WriteWebViewNavigationEventArg(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
27
+        void WriteWebViewNavigationEventArg(winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
27
         void OnNavigationStarting(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationStartingEventArgs const& args);
28
         void OnNavigationStarting(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationStartingEventArgs const& args);
28
         void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
29
         void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
29
         void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
30
         void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);

+ 1
- 0
windows/ReactNativeWebView/ReactWebView.idl Ver arquivo

2
     [default_interface]
2
     [default_interface]
3
     runtimeclass ReactWebView : Windows.UI.Xaml.Controls.UserControl{
3
     runtimeclass ReactWebView : Windows.UI.Xaml.Controls.UserControl{
4
         ReactWebView(Microsoft.ReactNative.IReactContext context);
4
         ReactWebView(Microsoft.ReactNative.IReactContext context);
5
+        Windows.UI.Xaml.Controls.WebView GetView();
5
         void PostMessage(String message);
6
         void PostMessage(String message);
6
     };
7
     };
7
 } // namespace ReactNativeWebView
8
 } // namespace ReactNativeWebView

+ 5
- 11
windows/ReactNativeWebView/ReactWebViewManager.cpp Ver arquivo

23
     }
23
     }
24
 
24
 
25
     winrt::FrameworkElement ReactWebViewManager::CreateView() noexcept {
25
     winrt::FrameworkElement ReactWebViewManager::CreateView() noexcept {
26
-      auto view = winrt::ReactNativeWebView::ReactWebView(m_reactContext);
27
-      return view;
26
+        m_reactWebView = *winrt::make_self<ReactWebView>(m_reactContext);
27
+        return m_reactWebView.GetView();
28
     }
28
     }
29
 
29
 
30
     // IViewManagerWithReactContext
30
     // IViewManagerWithReactContext
46
     void ReactWebViewManager::UpdateProperties(
46
     void ReactWebViewManager::UpdateProperties(
47
         FrameworkElement const& view,
47
         FrameworkElement const& view,
48
         IJSValueReader const& propertyMapReader) noexcept {
48
         IJSValueReader const& propertyMapReader) noexcept {
49
-        auto control = view.try_as<winrt::UserControl>();
50
-        auto content = control.Content();
51
-        if (auto webView = content.try_as<winrt::WebView>()) {
49
+        if (auto webView = view.try_as<winrt::WebView>()) {
52
             const JSValueObject& propertyMap = JSValueObject::ReadFrom(propertyMapReader);
50
             const JSValueObject& propertyMap = JSValueObject::ReadFrom(propertyMapReader);
53
 
51
 
54
             for (auto const& pair : propertyMap) {
52
             for (auto const& pair : propertyMap) {
118
         FrameworkElement const& view,
116
         FrameworkElement const& view,
119
         winrt::hstring const& commandId,
117
         winrt::hstring const& commandId,
120
         winrt::IJSValueReader const& commandArgsReader) noexcept {
118
         winrt::IJSValueReader const& commandArgsReader) noexcept {
121
-        auto control = view.try_as<winrt::UserControl>();
122
-        auto content = control.Content();
123
         auto commandArgs = JSValue::ReadArrayFrom(commandArgsReader);
119
         auto commandArgs = JSValue::ReadArrayFrom(commandArgsReader);
124
-        if (auto webView = content.try_as<winrt::WebView>()) {
120
+        if (auto webView = view.try_as<winrt::WebView>()) {
125
             if (commandId == L"goForward") {
121
             if (commandId == L"goForward") {
126
                 if (webView.CanGoForward()) {
122
                 if (webView.CanGoForward()) {
127
                     webView.GoForward();
123
                     webView.GoForward();
141
             else if (commandId == L"injectJavaScript") {
137
             else if (commandId == L"injectJavaScript") {
142
                 webView.InvokeScriptAsync(L"eval", { winrt::to_hstring(commandArgs[0].AsString()) });
138
                 webView.InvokeScriptAsync(L"eval", { winrt::to_hstring(commandArgs[0].AsString()) });
143
             } else if(commandId == L"postMessage") {
139
             } else if(commandId == L"postMessage") {
144
-                if (auto reactWebView = view.try_as<ReactNativeWebView::ReactWebView>()) {
145
-                    reactWebView.PostMessage(winrt::to_hstring(commandArgs[0].AsString()));
146
-                }
140
+                m_reactWebView.PostMessage(winrt::to_hstring(commandArgs[0].AsString()));
147
             }
141
             }
148
         }
142
         }
149
     }
143
     }

+ 1
- 0
windows/ReactNativeWebView/ReactWebViewManager.h Ver arquivo

47
             winrt::Microsoft::ReactNative::IJSValueReader const& commandArgsReader) noexcept;
47
             winrt::Microsoft::ReactNative::IJSValueReader const& commandArgsReader) noexcept;
48
 
48
 
49
     private:
49
     private:
50
+        winrt::ReactNativeWebView::ReactWebView m_reactWebView{ nullptr };
50
         winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
51
         winrt::Microsoft::ReactNative::IReactContext m_reactContext{ nullptr };
51
 
52
 
52
     };
53
     };

+ 1307
- 1367
yarn.lock
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo