Skip to content

Commit

Permalink
(android) wrap custom view in FrameLayout
Browse files Browse the repository at this point in the history
Wraps the custom view in a FrameLayout in order
to capture key events and redirect them to SystemWebView's
dispatchKeyEvent.
  • Loading branch information
Chuckytuh committed Aug 29, 2019
1 parent c93e3e9 commit fdc4da5
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions framework/src/org/apache/cordova/CordovaWebViewImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ public void showWebPage(String url, boolean openExternal, boolean clearHistory,
}
}


private static class WrapperView extends FrameLayout {

private final CordovaWebViewEngine engine;

public WrapperView(Context context, CordovaWebViewEngine engine) {
super(context);
this.engine = engine;
}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
return engine.getView().dispatchKeyEvent(event);
}
}

@Override
@Deprecated
public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
Expand All @@ -255,13 +271,16 @@ public void showCustomView(View view, WebChromeClient.CustomViewCallback callbac
return;
}

WrapperView wrapperView = new WrapperView(getContext(), engine);
wrapperView.addView(view);

// Store the view and its callback for later (to kill it properly)
mCustomView = view;
mCustomView = wrapperView;
mCustomViewCallback = callback;

// Add the custom view to its container.
ViewGroup parent = (ViewGroup) engine.getView().getParent();
parent.addView(view, new FrameLayout.LayoutParams(
parent.addView(wrapperView, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER));
Expand Down Expand Up @@ -497,8 +516,8 @@ protected class EngineClient implements CordovaWebViewEngine.Client {
public void clearLoadTimeoutTimer() {
loadUrlTimeout++;
}

@Override

public void onPageStarted(String newUrl) {
LOG.d(TAG, "onPageDidNavigate(" + newUrl + ")");
boundKeyCodes.clear();
Expand Down

0 comments on commit fdc4da5

Please sign in to comment.