소스 검색

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,8 +17,17 @@ import Downloads from './examples/Downloads';
17 17
 import Uploads from './examples/Uploads';
18 18
 import Injection from './examples/Injection';
19 19
 import LocalPageLoad from './examples/LocalPageLoad';
20
+import WebGL from './examples/WebGL';
20 21
 
21 22
 const TESTS = {
23
+  WebGL: {
24
+    title: 'WebGL',
25
+    testId: 'webgl',
26
+    description: 'WebGL for Windows',
27
+    render() {
28
+      return <WebGL />;
29
+    },
30
+  },
22 31
   Alerts: {
23 32
     title: 'Alerts',
24 33
     testId: 'alerts',
@@ -75,10 +84,17 @@ const TESTS = {
75 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 96
 type Props = {};
81
-type State = {restarting: boolean, currentTest: Object};
97
+type State = {restarting: boolean; currentTest: Object};
82 98
 
83 99
 export default class App extends Component<Props, State> {
84 100
   state = {
@@ -90,7 +106,7 @@ export default class App extends Component<Props, State> {
90 106
     this.setState({restarting: true}, () => this.setState({restarting: false}));
91 107
   };
92 108
 
93
-  _changeTest = testName => {
109
+  _changeTest = (testName) => {
94 110
     this.setState({currentTest: TESTS[testName]});
95 111
   };
96 112
 
@@ -138,16 +154,20 @@ export default class App extends Component<Props, State> {
138 154
             title="LocalPageLoad"
139 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 171
         </View>
152 172
 
153 173
         {restarting ? null : (

+ 17
- 0
windows/ReactNativeWebView/ReactWebView.cpp 파일 보기

@@ -62,6 +62,13 @@ namespace winrt::ReactNativeWebView::implementation {
62 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 74
     void ReactWebView::WriteWebViewNavigationEventArg(winrt::IJSValueWriter const& eventDataWriter) {
@@ -132,6 +139,16 @@ namespace winrt::ReactNativeWebView::implementation {
132 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 152
     void ReactWebView::PostMessage(winrt::hstring const& message) {
136 153
         m_reactContext.DispatchEvent(
137 154
             m_webView,

+ 3
- 0
windows/ReactNativeWebView/ReactWebView.h 파일 보기

@@ -22,6 +22,7 @@ namespace winrt::ReactNativeWebView::implementation {
22 22
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationCompleted_revoker m_navigationCompletedRevoker{};
23 23
         winrt::Windows::UI::Xaml::Controls::WebView::NavigationFailed_revoker m_navigationFailedRevoker{};
24 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 27
         void RegisterEvents();
27 28
         void WriteWebViewNavigationEventArg(winrt::Microsoft::ReactNative::IJSValueWriter const& eventDataWriter);
@@ -29,6 +30,8 @@ namespace winrt::ReactNativeWebView::implementation {
29 30
         void OnNavigationCompleted(winrt::Windows::UI::Xaml::Controls::WebView const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationCompletedEventArgs const& args);
30 31
         void OnNavigationFailed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::WebViewNavigationFailedEventArgs const& args);
31 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 36
 } // namespace winrt::ReactNativeWebView::implementation
34 37