mirror of
https://github.com/status-im/react-native.git
synced 2025-02-10 16:36:25 +00:00
Consolidate event dispatch to one method that gets the context and event dispatcher
Reviewed By: andreicoman11 Differential Revision: D2827596 fb-gh-sync-id: 3971237aa5eb08934a341e1486c7130381252c99
This commit is contained in:
parent
393adacfa6
commit
f8c384ffdd
@ -34,6 +34,7 @@ import com.facebook.react.uimanager.annotations.ReactProp;
|
|||||||
import com.facebook.react.uimanager.SimpleViewManager;
|
import com.facebook.react.uimanager.SimpleViewManager;
|
||||||
import com.facebook.react.uimanager.ThemedReactContext;
|
import com.facebook.react.uimanager.ThemedReactContext;
|
||||||
import com.facebook.react.uimanager.UIManagerModule;
|
import com.facebook.react.uimanager.UIManagerModule;
|
||||||
|
import com.facebook.react.uimanager.events.Event;
|
||||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,10 +95,8 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
super.onPageStarted(webView, url, favicon);
|
super.onPageStarted(webView, url, favicon);
|
||||||
mLastLoadFailed = false;
|
mLastLoadFailed = false;
|
||||||
|
|
||||||
ReactContext reactContext = (ReactContext) ((ReactWebView) webView).getContext();
|
dispatchEvent(
|
||||||
EventDispatcher eventDispatcher =
|
webView,
|
||||||
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
|
||||||
eventDispatcher.dispatchEvent(
|
|
||||||
new TopLoadingStartEvent(
|
new TopLoadingStartEvent(
|
||||||
webView.getId(),
|
webView.getId(),
|
||||||
SystemClock.uptimeMillis(),
|
SystemClock.uptimeMillis(),
|
||||||
@ -117,14 +116,12 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
// Android WebView does it in the opposite way, so we need to simulate that behavior
|
// Android WebView does it in the opposite way, so we need to simulate that behavior
|
||||||
emitFinishEvent(webView, failingUrl);
|
emitFinishEvent(webView, failingUrl);
|
||||||
|
|
||||||
ReactContext reactContext = (ReactContext) ((ReactWebView) webView).getContext();
|
|
||||||
WritableMap eventData = createWebViewEvent(webView, failingUrl);
|
WritableMap eventData = createWebViewEvent(webView, failingUrl);
|
||||||
eventData.putDouble("code", errorCode);
|
eventData.putDouble("code", errorCode);
|
||||||
eventData.putString("description", description);
|
eventData.putString("description", description);
|
||||||
|
|
||||||
EventDispatcher eventDispatcher =
|
dispatchEvent(
|
||||||
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
webView,
|
||||||
eventDispatcher.dispatchEvent(
|
|
||||||
new TopLoadingErrorEvent(webView.getId(), SystemClock.uptimeMillis(), eventData));
|
new TopLoadingErrorEvent(webView.getId(), SystemClock.uptimeMillis(), eventData));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,26 +129,28 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
|||||||
public void doUpdateVisitedHistory(WebView webView, String url, boolean isReload) {
|
public void doUpdateVisitedHistory(WebView webView, String url, boolean isReload) {
|
||||||
super.doUpdateVisitedHistory(webView, url, isReload);
|
super.doUpdateVisitedHistory(webView, url, isReload);
|
||||||
|
|
||||||
ReactContext reactContext = (ReactContext) webView.getContext();
|
dispatchEvent(
|
||||||
EventDispatcher eventDispatcher =
|
webView,
|
||||||
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
|
||||||
eventDispatcher.dispatchEvent(
|
|
||||||
new TopLoadingStartEvent(
|
new TopLoadingStartEvent(
|
||||||
|
webView.getId(),
|
||||||
|
SystemClock.uptimeMillis(),
|
||||||
|
createWebViewEvent(webView, url)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void emitFinishEvent(WebView webView, String url) {
|
||||||
|
dispatchEvent(
|
||||||
|
webView,
|
||||||
|
new TopLoadingFinishEvent(
|
||||||
webView.getId(),
|
webView.getId(),
|
||||||
SystemClock.uptimeMillis(),
|
SystemClock.uptimeMillis(),
|
||||||
createWebViewEvent(webView, url)));
|
createWebViewEvent(webView, url)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void emitFinishEvent(WebView webView, String url) {
|
private static void dispatchEvent(WebView webView, Event event) {
|
||||||
ReactContext reactContext = (ReactContext) webView.getContext();
|
ReactContext reactContext = (ReactContext) webView.getContext();
|
||||||
|
|
||||||
EventDispatcher eventDispatcher =
|
EventDispatcher eventDispatcher =
|
||||||
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
||||||
eventDispatcher.dispatchEvent(
|
eventDispatcher.dispatchEvent(event);
|
||||||
new TopLoadingFinishEvent(
|
|
||||||
webView.getId(),
|
|
||||||
SystemClock.uptimeMillis(),
|
|
||||||
createWebViewEvent(webView, url)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private WritableMap createWebViewEvent(WebView webView, String url) {
|
private WritableMap createWebViewEvent(WebView webView, String url) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user