浏览代码

WebGL for Windows

Tero Paananen 4 年前
父节点
当前提交
99f83dc486
共有 3 个文件被更改,包括 52 次插入12 次删除
  1. 32
    12
      example/App.tsx
  2. 17
    0
      windows/ReactNativeWebView/ReactWebView.cpp
  3. 3
    0
      windows/ReactNativeWebView/ReactWebView.h

+ 32
- 12
example/App.tsx 查看文件

17
 import Uploads from './examples/Uploads';
17
 import Uploads from './examples/Uploads';
18
 import Injection from './examples/Injection';
18
 import Injection from './examples/Injection';
19
 import LocalPageLoad from './examples/LocalPageLoad';
19
 import LocalPageLoad from './examples/LocalPageLoad';
20
+import WebGL from './examples/WebGL';
20
 
21
 
21
 const TESTS = {
22
 const TESTS = {
23
+  WebGL: {
24
+    title: 'WebGL',
25
+    testId: 'webgl',
26
+    description: 'WebGL for Windows',
27
+    render() {
28
+      return <WebGL />;
29
+    },
30
+  },
22
   Alerts: {
31
   Alerts: {
23
     title: 'Alerts',
32
     title: 'Alerts',
24
     testId: 'alerts',
33
     testId: 'alerts',
75
       return <LocalPageLoad />;
84
       return <LocalPageLoad />;
76
     },
85
     },
77
   },
86
   },
87
+  {Platform.OS === 'windows' && (
88
+    <Button
89
+      testID="testType_messaging"
90
+      title="WebGL"
91
+      onPress={() => this._changeTest('WebGL')}
92
+    />
93
+  )}
78
 };
94
 };
79
 
95
 
80
 type Props = {};
96
 type Props = {};
81
-type State = {restarting: boolean, currentTest: Object};
97
+type State = {restarting: boolean; currentTest: Object};
82
 
98
 
83
 export default class App extends Component<Props, State> {
99
 export default class App extends Component<Props, State> {
84
   state = {
100
   state = {
90
     this.setState({restarting: true}, () => this.setState({restarting: false}));
106
     this.setState({restarting: true}, () => this.setState({restarting: false}));
91
   };
107
   };
92
 
108
 
93
-  _changeTest = testName => {
109
+  _changeTest = (testName) => {
94
     this.setState({currentTest: TESTS[testName]});
110
     this.setState({currentTest: TESTS[testName]});
95
   };
111
   };
96
 
112
 
138
             title="LocalPageLoad"
154
             title="LocalPageLoad"
139
             onPress={() => this._changeTest('PageLoad')}
155
             onPress={() => this._changeTest('PageLoad')}
140
           />
156
           />
141
-          {Platform.OS == "ios" && <Button
142
-            testID="testType_downloads"
143
-            title="Downloads"
144
-            onPress={() => this._changeTest('Downloads')}
145
-          />}
146
-          {Platform.OS === 'android' && <Button
147
-            testID="testType_uploads"
148
-            title="Uploads"
149
-            onPress={() => this._changeTest('Uploads')}
150
-          />}
157
+          {Platform.OS == 'ios' && (
158
+            <Button
159
+              testID="testType_downloads"
160
+              title="Downloads"
161
+              onPress={() => this._changeTest('Downloads')}
162
+            />
163
+          )}
164
+          {Platform.OS === 'android' && (
165
+            <Button
166
+              testID="testType_uploads"
167
+              title="Uploads"
168
+              onPress={() => this._changeTest('Uploads')}
169
+            />
170
+          )}
151
         </View>
171
         </View>
152
 
172
 
153
         {restarting ? null : (
173
         {restarting ? null : (

+ 17
- 0
windows/ReactNativeWebView/ReactWebView.cpp 查看文件

62
                     self->OnScriptNotify(sender, args);
62
                     self->OnScriptNotify(sender, args);
63
                 }
63
                 }
64
             });
64
             });
65
+    
66
+         m_permissionReguestRevoker = m_webView.PermissionRequested(
67
+            winrt::auto_revoke, [ref = get_weak()](auto const& sender, auto const& args) {
68
+                if (auto self = ref.get()) {
69
+                    self->OnPremissionRequested(sender, args);
70
+                }
71
+        });
65
     }
72
     }
66
 
73
 
67
     void ReactWebView::WriteWebViewNavigationEventArg(winrt::IJSValueWriter const& eventDataWriter) {
74
     void ReactWebView::WriteWebViewNavigationEventArg(winrt::IJSValueWriter const& eventDataWriter) {
132
         PostMessage(winrt::hstring(args.Value()));
139
         PostMessage(winrt::hstring(args.Value()));
133
     }
140
     }
134
 
141
 
142
+    void ReactWebView::OnPremissionRequested(winrt::WebView const& webView, winrt::WebViewPermissionRequestedEventArgs const& args)
143
+    {
144
+      if (args.PermissionRequest().PermissionType() == WebViewPermissionType::ImmersiveView) {
145
+        // WebGL permission request
146
+        // https://docs.microsoft.com/en-us/microsoft-edge/webvr/webvr-in-webview
147
+        args.PermissionRequest().Allow();
148
+      }
149
+      args.PermissionRequest().Deny();
150
+    }
151
+
135
     void ReactWebView::PostMessage(winrt::hstring const& message) {
152
     void ReactWebView::PostMessage(winrt::hstring const& message) {
136
         m_reactContext.DispatchEvent(
153
         m_reactContext.DispatchEvent(
137
             m_webView,
154
             m_webView,

+ 3
- 0
windows/ReactNativeWebView/ReactWebView.h 查看文件

22
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
22
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
23
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationFailed_revoker m_navigationFailedRevoker{};
23
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationFailed_revoker m_navigationFailedRevoker{};
24
         winrt::Windows::UI::Xaml::Controls::WebView::ScriptNotify_revoker m_scriptNotifyRevoker{};
24
         winrt::Windows::UI::Xaml::Controls::WebView::ScriptNotify_revoker m_scriptNotifyRevoker{};
25
+        winrt::Windows::UI::Xaml::Controls::WebView::PermissionRequested_revoker m_permissionReguestRevoker{};
25
 
26
 
26
         void RegisterEvents();
27
         void RegisterEvents();
27
         void WriteWebViewNavigationEventArg(winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
28
         void WriteWebViewNavigationEventArg(winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
29
         void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
30
         void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
30
         void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
31
         void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
31
         void OnScriptNotify(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args);
32
         void OnScriptNotify(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::NotifyEventArgs const& args);
33
+        void OnPremissionRequested(winrt::Windows::UI::Xaml::Controls::WebView const& webView, winrt::Windows::UI::Xaml::Controls::WebViewPermissionRequestedEventArgs const& args);
34
+
32
     };
35
     };
33
 } // namespace winrt::ReactNativeWebView::implementation
36
 } // namespace winrt::ReactNativeWebView::implementation
34
 
37