Don't request focus explicitly if not needed

Requesting the focus explicitly actually makes the child WebView to move the focus to the first visible focusable element on the page. This makes it impossible to simply let the WebView restore the focus to the last focused element, before the activity was paused. To prevent this problem on devices other that the Samsung Galaxy Note 3, only request the focus if necessary (it might as well be possible that the original fix is not needed anymore on newer versions of Android and/or WebView).
This commit is contained in:
goffioul 2019-06-20 15:28:08 -04:00 committed by GitHub
parent 4cf3dcfaae
commit 01ab11644c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -268,9 +268,11 @@ public class CordovaActivity extends Activity {
if (this.appView == null) {
return;
}
// Force window to have focus, so application always
// receive user input. Workaround for some devices (Samsung Galaxy Note 3 at least)
this.getWindow().getDecorView().requestFocus();
if (! this.getWindow().getDecorView().hasFocus()) {
// Force window to have focus, so application always
// receive user input. Workaround for some devices (Samsung Galaxy Note 3 at least)
this.getWindow().getDecorView().requestFocus();
}
this.appView.handleResume(this.keepRunning);
}