@javascriptcommon/react-native-webview 13.12.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +82 -0
- package/android/build.gradle +110 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +15 -0
- package/android/src/main/AndroidManifestNew.xml +13 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCBasicAuthCredential.java +11 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebChromeClient.java +372 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java +450 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewClient.java +328 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewConfig.java +11 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewFileProvider.java +14 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt +720 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewMessagingModule.kt +19 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModuleImpl.java +554 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewPackage.java +56 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewWrapper.kt +39 -0
- package/android/src/main/java/com/reactnativecommunity/webview/URLUtil.java +179 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopCustomMenuSelectionEvent.kt +24 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopHttpErrorEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingErrorEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingFinishEvent.kt +24 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingProgressEvent.kt +24 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingStartEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopMessageEvent.kt +24 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopNewWindowEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopRenderProcessGoneEvent.kt +26 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopShouldStartLoadWithRequestEvent.kt +29 -0
- package/android/src/main/res/xml/file_provider_paths.xml +6 -0
- package/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java +553 -0
- package/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewModule.java +63 -0
- package/android/src/oldarch/com/reactnativecommunity/webview/RNCWebViewManager.java +328 -0
- package/android/src/oldarch/com/reactnativecommunity/webview/RNCWebViewModule.java +59 -0
- package/apple/RCTConvert+WKDataDetectorTypes.h +11 -0
- package/apple/RCTConvert+WKDataDetectorTypes.m +27 -0
- package/apple/RNCWKProcessPoolManager.h +15 -0
- package/apple/RNCWKProcessPoolManager.m +36 -0
- package/apple/RNCWebView.h +35 -0
- package/apple/RNCWebView.mm +546 -0
- package/apple/RNCWebViewDecisionManager.h +20 -0
- package/apple/RNCWebViewDecisionManager.m +47 -0
- package/apple/RNCWebViewImpl.h +161 -0
- package/apple/RNCWebViewImpl.m +1979 -0
- package/apple/RNCWebViewManager.h +9 -0
- package/apple/RNCWebViewManager.mm +215 -0
- package/apple/RNCWebViewModule.h +23 -0
- package/apple/RNCWebViewModule.mm +34 -0
- package/index.d.ts +65 -0
- package/index.js +4 -0
- package/ios/RNCWebView.xcodeproj/project.pbxproj +273 -0
- package/lib/NativeRNCWebViewModule.d.ts +10 -0
- package/lib/NativeRNCWebViewModule.js +1 -0
- package/lib/RNCWebViewNativeComponent.d.ts +242 -0
- package/lib/RNCWebViewNativeComponent.js +1 -0
- package/lib/WebView.android.d.ts +6 -0
- package/lib/WebView.android.js +1 -0
- package/lib/WebView.d.ts +6 -0
- package/lib/WebView.ios.d.ts +6 -0
- package/lib/WebView.ios.js +1 -0
- package/lib/WebView.js +1 -0
- package/lib/WebView.macos.d.ts +6 -0
- package/lib/WebView.macos.js +1 -0
- package/lib/WebView.styles.d.ts +38 -0
- package/lib/WebView.styles.js +1 -0
- package/lib/WebView.windows.d.ts +17 -0
- package/lib/WebView.windows.js +1 -0
- package/lib/WebViewNativeComponent.macos.d.ts +3 -0
- package/lib/WebViewNativeComponent.macos.js +1 -0
- package/lib/WebViewNativeComponent.windows.d.ts +3 -0
- package/lib/WebViewNativeComponent.windows.js +1 -0
- package/lib/WebViewShared.d.ts +38 -0
- package/lib/WebViewShared.js +1 -0
- package/lib/WebViewTypes.d.ts +1093 -0
- package/lib/WebViewTypes.js +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +1 -0
- package/macos/RNCWebView.xcodeproj/project.pbxproj +363 -0
- package/package.json +101 -0
- package/react-native-webview.podspec +46 -0
- package/react-native.config.js +44 -0
- package/src/NativeRNCWebViewModule.ts +15 -0
- package/src/RNCWebViewNativeComponent.ts +342 -0
- package/src/WebView.android.tsx +317 -0
- package/src/WebView.ios.tsx +299 -0
- package/src/WebView.macos.tsx +245 -0
- package/src/WebView.styles.ts +41 -0
- package/src/WebView.tsx +25 -0
- package/src/WebView.windows.tsx +210 -0
- package/src/WebViewNativeComponent.macos.ts +7 -0
- package/src/WebViewNativeComponent.windows.ts +8 -0
- package/src/WebViewShared.tsx +283 -0
- package/src/WebViewTypes.ts +1332 -0
- package/src/__tests__/WebViewShared-test.js +323 -0
- package/src/__tests__/__snapshots__/WebViewShared-test.js.snap +8 -0
- package/src/index.ts +4 -0
- package/windows/ExperimentalFeatures.props +11 -0
- package/windows/ReactNativeWebView/PropertySheet.props +16 -0
- package/windows/ReactNativeWebView/ReactNativeWebView.def +3 -0
- package/windows/ReactNativeWebView/ReactNativeWebView.filters +33 -0
- package/windows/ReactNativeWebView/ReactNativeWebView.vcxproj +189 -0
- package/windows/ReactNativeWebView/ReactPackageProvider.cpp +26 -0
- package/windows/ReactNativeWebView/ReactPackageProvider.h +20 -0
- package/windows/ReactNativeWebView/ReactPackageProvider.idl +7 -0
- package/windows/ReactNativeWebView/ReactWebView.cpp +242 -0
- package/windows/ReactNativeWebView/ReactWebView.h +56 -0
- package/windows/ReactNativeWebView/ReactWebView.idl +31 -0
- package/windows/ReactNativeWebView/ReactWebView2.cpp +473 -0
- package/windows/ReactNativeWebView/ReactWebView2.h +91 -0
- package/windows/ReactNativeWebView/ReactWebView2Manager.cpp +205 -0
- package/windows/ReactNativeWebView/ReactWebView2Manager.h +57 -0
- package/windows/ReactNativeWebView/ReactWebViewHelpers.cpp +70 -0
- package/windows/ReactNativeWebView/ReactWebViewHelpers.h +16 -0
- package/windows/ReactNativeWebView/ReactWebViewManager.cpp +224 -0
- package/windows/ReactNativeWebView/ReactWebViewManager.h +58 -0
- package/windows/ReactNativeWebView/WebBridge.cpp +19 -0
- package/windows/ReactNativeWebView/WebBridge.h +24 -0
- package/windows/ReactNativeWebView/WebBridge.idl +11 -0
- package/windows/ReactNativeWebView/pch.cpp +1 -0
- package/windows/ReactNativeWebView/pch.h +37 -0
- package/windows/ReactNativeWebView.sln +185 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
package com.reactnativecommunity.webview;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.graphics.Rect;
|
|
5
|
+
import android.text.TextUtils;
|
|
6
|
+
import android.view.ActionMode;
|
|
7
|
+
import android.view.Menu;
|
|
8
|
+
import android.view.MenuItem;
|
|
9
|
+
import android.view.MotionEvent;
|
|
10
|
+
import android.view.View;
|
|
11
|
+
import android.webkit.JavascriptInterface;
|
|
12
|
+
import android.webkit.ValueCallback;
|
|
13
|
+
import android.webkit.WebChromeClient;
|
|
14
|
+
import android.webkit.WebView;
|
|
15
|
+
import android.webkit.WebViewClient;
|
|
16
|
+
|
|
17
|
+
import androidx.annotation.Nullable;
|
|
18
|
+
|
|
19
|
+
import com.facebook.common.logging.FLog;
|
|
20
|
+
import com.facebook.react.bridge.Arguments;
|
|
21
|
+
import com.facebook.react.bridge.LifecycleEventListener;
|
|
22
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
23
|
+
import com.facebook.react.bridge.ReactContext;
|
|
24
|
+
import com.facebook.react.bridge.WritableMap;
|
|
25
|
+
import com.facebook.react.bridge.WritableNativeMap;
|
|
26
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
27
|
+
import com.facebook.react.uimanager.UIManagerHelper;
|
|
28
|
+
import com.facebook.react.uimanager.events.ContentSizeChangeEvent;
|
|
29
|
+
import com.facebook.react.uimanager.events.Event;
|
|
30
|
+
import com.facebook.react.views.scroll.OnScrollDispatchHelper;
|
|
31
|
+
import com.facebook.react.views.scroll.ScrollEvent;
|
|
32
|
+
import com.facebook.react.views.scroll.ScrollEventType;
|
|
33
|
+
import com.reactnativecommunity.webview.events.TopCustomMenuSelectionEvent;
|
|
34
|
+
import com.reactnativecommunity.webview.events.TopMessageEvent;
|
|
35
|
+
|
|
36
|
+
import org.json.JSONException;
|
|
37
|
+
import org.json.JSONObject;
|
|
38
|
+
|
|
39
|
+
import java.util.List;
|
|
40
|
+
import java.util.Map;
|
|
41
|
+
|
|
42
|
+
public class RNCWebView extends WebView implements LifecycleEventListener {
|
|
43
|
+
protected @Nullable
|
|
44
|
+
String injectedJS;
|
|
45
|
+
protected @Nullable
|
|
46
|
+
String injectedJSBeforeContentLoaded;
|
|
47
|
+
protected static final String JAVASCRIPT_INTERFACE = "ReactNativeWebView";
|
|
48
|
+
protected @Nullable
|
|
49
|
+
RNCWebViewBridge bridge;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* android.webkit.WebChromeClient fundamentally does not support JS injection into frames other
|
|
53
|
+
* than the main frame, so these two properties are mostly here just for parity with iOS & macOS.
|
|
54
|
+
*/
|
|
55
|
+
protected boolean injectedJavaScriptForMainFrameOnly = true;
|
|
56
|
+
protected boolean injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true;
|
|
57
|
+
|
|
58
|
+
protected boolean messagingEnabled = false;
|
|
59
|
+
protected @Nullable
|
|
60
|
+
String messagingModuleName;
|
|
61
|
+
protected @Nullable
|
|
62
|
+
RNCWebViewMessagingModule mMessagingJSModule;
|
|
63
|
+
protected @Nullable
|
|
64
|
+
RNCWebViewClient mRNCWebViewClient;
|
|
65
|
+
protected boolean sendContentSizeChangeEvents = false;
|
|
66
|
+
private OnScrollDispatchHelper mOnScrollDispatchHelper;
|
|
67
|
+
protected boolean hasScrollEvent = false;
|
|
68
|
+
protected boolean nestedScrollEnabled = false;
|
|
69
|
+
protected ProgressChangedFilter progressChangedFilter;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* WebView must be created with an context of the current activity
|
|
73
|
+
* <p>
|
|
74
|
+
* Activity Context is required for creation of dialogs internally by WebView
|
|
75
|
+
* Reactive Native needed for access to ReactNative internal system functionality
|
|
76
|
+
*/
|
|
77
|
+
public RNCWebView(ThemedReactContext reactContext) {
|
|
78
|
+
super(reactContext);
|
|
79
|
+
ReactApplicationContext appContext = reactContext.getReactApplicationContext();
|
|
80
|
+
mMessagingJSModule = new RNCWebViewMessagingModule(appContext);
|
|
81
|
+
progressChangedFilter = new ProgressChangedFilter();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public void setIgnoreErrFailedForThisURL(String url) {
|
|
85
|
+
mRNCWebViewClient.setIgnoreErrFailedForThisURL(url);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public void setBasicAuthCredential(RNCBasicAuthCredential credential) {
|
|
89
|
+
mRNCWebViewClient.setBasicAuthCredential(credential);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public void setSendContentSizeChangeEvents(boolean sendContentSizeChangeEvents) {
|
|
93
|
+
this.sendContentSizeChangeEvents = sendContentSizeChangeEvents;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public void setHasScrollEvent(boolean hasScrollEvent) {
|
|
97
|
+
this.hasScrollEvent = hasScrollEvent;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public void setNestedScrollEnabled(boolean nestedScrollEnabled) {
|
|
101
|
+
this.nestedScrollEnabled = nestedScrollEnabled;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Override
|
|
105
|
+
protected void onWindowVisibilityChanged(int visibility) {
|
|
106
|
+
if (visibility != View.GONE && visibility != View.INVISIBLE) super.onWindowVisibilityChanged(visibility);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Override
|
|
110
|
+
public void onHostResume() {
|
|
111
|
+
// do nothing
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@Override
|
|
115
|
+
public void onHostPause() {
|
|
116
|
+
// do nothing
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@Override
|
|
120
|
+
public void onHostDestroy() {
|
|
121
|
+
cleanupCallbacksAndDestroy();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@Override
|
|
125
|
+
public boolean onTouchEvent(MotionEvent event) {
|
|
126
|
+
if (this.nestedScrollEnabled) {
|
|
127
|
+
requestDisallowInterceptTouchEvent(true);
|
|
128
|
+
}
|
|
129
|
+
return super.onTouchEvent(event);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Override
|
|
133
|
+
protected void onSizeChanged(int w, int h, int ow, int oh) {
|
|
134
|
+
super.onSizeChanged(w, h, ow, oh);
|
|
135
|
+
|
|
136
|
+
if (sendContentSizeChangeEvents) {
|
|
137
|
+
dispatchEvent(
|
|
138
|
+
this,
|
|
139
|
+
new ContentSizeChangeEvent(
|
|
140
|
+
RNCWebViewWrapper.getReactTagFromWebView(this),
|
|
141
|
+
w,
|
|
142
|
+
h
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
protected @Nullable
|
|
149
|
+
List<Map<String, String>> menuCustomItems;
|
|
150
|
+
|
|
151
|
+
public void setMenuCustomItems(List<Map<String, String>> menuCustomItems) {
|
|
152
|
+
this.menuCustomItems = menuCustomItems;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@Override
|
|
156
|
+
public ActionMode startActionMode(ActionMode.Callback callback, int type) {
|
|
157
|
+
if(menuCustomItems == null ){
|
|
158
|
+
return super.startActionMode(callback, type);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return super.startActionMode(new ActionMode.Callback2() {
|
|
162
|
+
@Override
|
|
163
|
+
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
164
|
+
for (int i = 0; i < menuCustomItems.size(); i++) {
|
|
165
|
+
menu.add(Menu.NONE, i, i, (menuCustomItems.get(i)).get("label"));
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@Override
|
|
171
|
+
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@Override
|
|
176
|
+
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
177
|
+
WritableMap wMap = Arguments.createMap();
|
|
178
|
+
RNCWebView.this.evaluateJavascript(
|
|
179
|
+
"(function(){return {selection: window.getSelection().toString()} })()",
|
|
180
|
+
new ValueCallback<String>() {
|
|
181
|
+
@Override
|
|
182
|
+
public void onReceiveValue(String selectionJson) {
|
|
183
|
+
Map<String, String> menuItemMap = menuCustomItems.get(item.getItemId());
|
|
184
|
+
wMap.putString("label", menuItemMap.get("label"));
|
|
185
|
+
wMap.putString("key", menuItemMap.get("key"));
|
|
186
|
+
String selectionText = "";
|
|
187
|
+
try {
|
|
188
|
+
selectionText = new JSONObject(selectionJson).getString("selection");
|
|
189
|
+
} catch (JSONException ignored) {}
|
|
190
|
+
wMap.putString("selectedText", selectionText);
|
|
191
|
+
dispatchEvent(RNCWebView.this, new TopCustomMenuSelectionEvent(RNCWebViewWrapper.getReactTagFromWebView(RNCWebView.this), wMap));
|
|
192
|
+
mode.finish();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@Override
|
|
200
|
+
public void onDestroyActionMode(ActionMode mode) {
|
|
201
|
+
mode = null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@Override
|
|
205
|
+
public void onGetContentRect (ActionMode mode,
|
|
206
|
+
View view,
|
|
207
|
+
Rect outRect){
|
|
208
|
+
if (callback instanceof ActionMode.Callback2) {
|
|
209
|
+
((ActionMode.Callback2) callback).onGetContentRect(mode, view, outRect);
|
|
210
|
+
} else {
|
|
211
|
+
super.onGetContentRect(mode, view, outRect);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}, type);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
@Override
|
|
218
|
+
public void setWebViewClient(WebViewClient client) {
|
|
219
|
+
super.setWebViewClient(client);
|
|
220
|
+
if (client instanceof RNCWebViewClient) {
|
|
221
|
+
mRNCWebViewClient = (RNCWebViewClient) client;
|
|
222
|
+
mRNCWebViewClient.setProgressChangedFilter(progressChangedFilter);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
WebChromeClient mWebChromeClient;
|
|
227
|
+
@Override
|
|
228
|
+
public void setWebChromeClient(WebChromeClient client) {
|
|
229
|
+
this.mWebChromeClient = client;
|
|
230
|
+
super.setWebChromeClient(client);
|
|
231
|
+
if (client instanceof RNCWebChromeClient) {
|
|
232
|
+
((RNCWebChromeClient) client).setProgressChangedFilter(progressChangedFilter);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public WebChromeClient getWebChromeClient() {
|
|
237
|
+
return this.mWebChromeClient;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public @Nullable
|
|
241
|
+
RNCWebViewClient getRNCWebViewClient() {
|
|
242
|
+
return mRNCWebViewClient;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public boolean getMessagingEnabled() {
|
|
246
|
+
return this.messagingEnabled;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
|
|
250
|
+
if (bridge == null) {
|
|
251
|
+
bridge = new RNCWebViewBridge(webView);
|
|
252
|
+
addJavascriptInterface(bridge, JAVASCRIPT_INTERFACE);
|
|
253
|
+
}
|
|
254
|
+
return bridge;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
@SuppressLint("AddJavascriptInterface")
|
|
258
|
+
public void setMessagingEnabled(boolean enabled) {
|
|
259
|
+
if (messagingEnabled == enabled) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
messagingEnabled = enabled;
|
|
264
|
+
|
|
265
|
+
if (enabled) {
|
|
266
|
+
createRNCWebViewBridge(this);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
protected void evaluateJavascriptWithFallback(String script) {
|
|
271
|
+
evaluateJavascript(script, null);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
public void callInjectedJavaScript() {
|
|
275
|
+
if (getSettings().getJavaScriptEnabled() &&
|
|
276
|
+
injectedJS != null &&
|
|
277
|
+
!TextUtils.isEmpty(injectedJS)) {
|
|
278
|
+
evaluateJavascriptWithFallback("(function() {\n" + injectedJS + ";\n})();");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public void callInjectedJavaScriptBeforeContentLoaded() {
|
|
283
|
+
if (getSettings().getJavaScriptEnabled() &&
|
|
284
|
+
injectedJSBeforeContentLoaded != null &&
|
|
285
|
+
!TextUtils.isEmpty(injectedJSBeforeContentLoaded)) {
|
|
286
|
+
evaluateJavascriptWithFallback("(function() {\n" + injectedJSBeforeContentLoaded + ";\n})();");
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
public void setInjectedJavaScriptObject(String obj) {
|
|
291
|
+
if (getSettings().getJavaScriptEnabled()) {
|
|
292
|
+
RNCWebViewBridge b = createRNCWebViewBridge(this);
|
|
293
|
+
b.setInjectedObjectJson(obj);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public void onMessage(String message) {
|
|
298
|
+
ThemedReactContext reactContext = getThemedReactContext();
|
|
299
|
+
RNCWebView mWebView = this;
|
|
300
|
+
|
|
301
|
+
if (mRNCWebViewClient != null) {
|
|
302
|
+
WebView webView = this;
|
|
303
|
+
webView.post(new Runnable() {
|
|
304
|
+
@Override
|
|
305
|
+
public void run() {
|
|
306
|
+
if (mRNCWebViewClient == null) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
WritableMap data = mRNCWebViewClient.createWebViewEvent(webView, webView.getUrl());
|
|
310
|
+
data.putString("data", message);
|
|
311
|
+
|
|
312
|
+
if (mMessagingJSModule != null) {
|
|
313
|
+
dispatchDirectMessage(data);
|
|
314
|
+
} else {
|
|
315
|
+
dispatchEvent(webView, new TopMessageEvent(RNCWebViewWrapper.getReactTagFromWebView(webView), data));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
} else {
|
|
320
|
+
WritableMap eventData = Arguments.createMap();
|
|
321
|
+
eventData.putString("data", message);
|
|
322
|
+
|
|
323
|
+
if (mMessagingJSModule != null) {
|
|
324
|
+
dispatchDirectMessage(eventData);
|
|
325
|
+
} else {
|
|
326
|
+
dispatchEvent(this, new TopMessageEvent(RNCWebViewWrapper.getReactTagFromWebView(this), eventData));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
protected void dispatchDirectMessage(WritableMap data) {
|
|
332
|
+
WritableNativeMap event = new WritableNativeMap();
|
|
333
|
+
event.putMap("nativeEvent", data);
|
|
334
|
+
event.putString("messagingModuleName", messagingModuleName);
|
|
335
|
+
|
|
336
|
+
ReactContext reactContext = getReactApplicationContext();
|
|
337
|
+
if (mMessagingJSModule != null && reactContext != null) {
|
|
338
|
+
mMessagingJSModule.sendEvent(reactContext, "onMessage", event);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
protected void dispatchDirectShouldStartLoadWithRequest(WritableMap data) {
|
|
343
|
+
WritableNativeMap event = new WritableNativeMap();
|
|
344
|
+
event.putMap("nativeEvent", data);
|
|
345
|
+
event.putString("messagingModuleName", messagingModuleName);
|
|
346
|
+
|
|
347
|
+
ReactContext reactContext = getReactApplicationContext();
|
|
348
|
+
if (mMessagingJSModule != null && reactContext != null) {
|
|
349
|
+
mMessagingJSModule.sendEvent(reactContext, "onShouldStartLoadWithRequest", event);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
|
|
354
|
+
super.onScrollChanged(x, y, oldX, oldY);
|
|
355
|
+
|
|
356
|
+
if (!hasScrollEvent) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (mOnScrollDispatchHelper == null) {
|
|
361
|
+
mOnScrollDispatchHelper = new OnScrollDispatchHelper();
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
|
|
365
|
+
ScrollEvent event = ScrollEvent.obtain(
|
|
366
|
+
RNCWebViewWrapper.getReactTagFromWebView(this),
|
|
367
|
+
ScrollEventType.SCROLL,
|
|
368
|
+
x,
|
|
369
|
+
y,
|
|
370
|
+
mOnScrollDispatchHelper.getXFlingVelocity(),
|
|
371
|
+
mOnScrollDispatchHelper.getYFlingVelocity(),
|
|
372
|
+
this.computeHorizontalScrollRange(),
|
|
373
|
+
this.computeVerticalScrollRange(),
|
|
374
|
+
this.getWidth(),
|
|
375
|
+
this.getHeight());
|
|
376
|
+
|
|
377
|
+
dispatchEvent(this, event);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
protected void dispatchEvent(WebView webView, Event event) {
|
|
382
|
+
ThemedReactContext reactContext = getThemedReactContext();
|
|
383
|
+
int reactTag = RNCWebViewWrapper.getReactTagFromWebView(webView);
|
|
384
|
+
UIManagerHelper.getEventDispatcherForReactTag(reactContext, reactTag).dispatchEvent(event);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
protected void cleanupCallbacksAndDestroy() {
|
|
388
|
+
setWebViewClient(null);
|
|
389
|
+
destroy();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
@Override
|
|
393
|
+
public void destroy() {
|
|
394
|
+
if (mWebChromeClient != null) {
|
|
395
|
+
mWebChromeClient.onHideCustomView();
|
|
396
|
+
}
|
|
397
|
+
super.destroy();
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
public ThemedReactContext getThemedReactContext() {
|
|
401
|
+
return (ThemedReactContext) this.getContext();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
public ReactApplicationContext getReactApplicationContext() {
|
|
405
|
+
return this.getThemedReactContext().getReactApplicationContext();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
protected class RNCWebViewBridge {
|
|
409
|
+
private String TAG = "RNCWebViewBridge";
|
|
410
|
+
RNCWebView mWebView;
|
|
411
|
+
String injectedObjectJson;
|
|
412
|
+
|
|
413
|
+
RNCWebViewBridge(RNCWebView c) {
|
|
414
|
+
mWebView = c;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
public void setInjectedObjectJson(String s) {
|
|
418
|
+
injectedObjectJson = s;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* This method is called whenever JavaScript running within the web view calls:
|
|
423
|
+
* - window[JAVASCRIPT_INTERFACE].postMessage
|
|
424
|
+
*/
|
|
425
|
+
@JavascriptInterface
|
|
426
|
+
public void postMessage(String message) {
|
|
427
|
+
if (mWebView.getMessagingEnabled()) {
|
|
428
|
+
mWebView.onMessage(message);
|
|
429
|
+
} else {
|
|
430
|
+
FLog.w(TAG, "ReactNativeWebView.postMessage method was called but messaging is disabled. Pass an onMessage handler to the WebView.");
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
@JavascriptInterface
|
|
435
|
+
public String injectedObjectJson() { return injectedObjectJson; }
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
protected static class ProgressChangedFilter {
|
|
440
|
+
private boolean waitingForCommandLoadUrl = false;
|
|
441
|
+
|
|
442
|
+
public void setWaitingForCommandLoadUrl(boolean isWaiting) {
|
|
443
|
+
waitingForCommandLoadUrl = isWaiting;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
public boolean isWaitingForCommandLoadUrl() {
|
|
447
|
+
return waitingForCommandLoadUrl;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|