Skip to content

fix: webview resize#1947

Open
RohitKushvaha01 wants to merge 6 commits intoAcode-Foundation:mainfrom
RohitKushvaha01:activity_resize
Open

fix: webview resize#1947
RohitKushvaha01 wants to merge 6 commits intoAcode-Foundation:mainfrom
RohitKushvaha01:activity_resize

Conversation

@RohitKushvaha01
Copy link
Member

No description provided.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 14, 2026

Greptile Summary

This PR fixes the WebView resize issue when the soft keyboard appears on Android by introducing a new SoftInputAssist class that uses WindowInsetsAnimationCompat to animate bottom padding in sync with the keyboard, and a Cordova post-process hook that patches MainActivity.java at build time to wire it in.

Key changes:

  • SoftInputAssist.java: Registers a WindowInsetsAnimationCompat.Callback on android.R.id.content and computes keyboardHeight = max(0, ime.bottom - nav.bottom) on each animation frame, applying it as bottom padding.
  • hooks/post-process.js: enableKeyboardWorkaround() injects the import, field declaration, and constructor call into MainActivity.java; the loadUrl(launchUrl) replacement has no "not-found" guard, so a mismatch silently leaves softInputAssist null while still logging success.
  • plugin.xml: Correctly registers SoftInputAssist.java as a plugin source file.

Issues found:

  • The loadUrl(launchUrl) regex replacement in enableKeyboardWorkaround() has no guard, so if the pattern is missing, the field is never initialised but the hook falsely reports success.
  • contentView.setPadding(0, 0, 0, keyboardHeight) hardcodes zero for left, top, and right padding — any existing padding applied to the content view by Cordova or another plugin would be silently wiped on every keyboard animation frame.
  • There is no ViewCompat.setOnApplyWindowInsetsListener fallback, so on devices/configurations where the keyboard appears without a visual animation, onProgress is never called and the bottom padding is never applied.

Confidence Score: 3/5

  • Safe to merge with minor robustness concerns; the core approach is correct but has edge-case gaps.
  • The WindowInsetsAnimationCompat approach is the correct modern pattern for smooth keyboard-resize handling, and the hook correctly guards against double-patching. However, the false-success log when loadUrl is not found, the destructive setPadding call that zeros non-bottom padding, and the missing static-insets fallback each represent real (if infrequent) failure modes that could cause layout regressions or silent no-ops on some devices.
  • SoftInputAssist.java (padding side-effects and missing static fallback) and hooks/post-process.js (unguarded loadUrl replacement).

Important Files Changed

Filename Overview
src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java New class that registers a WindowInsetsAnimationCompat callback to apply bottom padding equal to the keyboard height; has two concerns: setPadding zeroes out other padding dimensions, and there is no static-insets fallback for keyboards appearing without animation.
hooks/post-process.js Adds enableKeyboardWorkaround() hook that patches MainActivity.java to import and instantiate SoftInputAssist; the loadUrl(launchUrl) replacement is unguarded and can silently leave the field uninitialised while still logging success.
src/plugins/system/plugin.xml Registers SoftInputAssist.java as a new source file in the Cordova plugin manifest; change is straightforward and correct.

Sequence Diagram

sequenceDiagram
    participant Hook as post-process.js (Cordova Hook)
    participant MA as MainActivity.java (patched)
    participant SIA as SoftInputAssist
    participant CV as contentView (android.R.id.content)
    participant OS as Android OS

    Hook->>MA: inject import com.foxdebug.system.SoftInputAssist
    Hook->>MA: inject field: private SoftInputAssist softInputAssist
    Hook->>MA: inject in onCreate: softInputAssist = new SoftInputAssist(this)

    MA->>SIA: new SoftInputAssist(activity) [in onCreate]
    SIA->>CV: ViewCompat.setWindowInsetsAnimationCallback(...)

    OS-->>SIA: onProgress(insets, runningAnimations) [keyboard animation frame]
    SIA->>SIA: keyboardHeight = max(0, ime.bottom - nav.bottom)
    SIA->>CV: setPadding(0, 0, 0, keyboardHeight)

    Note over OS,CV: ⚠️ If keyboard appears without animation,<br/>onProgress is never called → padding stays 0
Loading

Last reviewed commit: 8d0300e

RohitKushvaha01 and others added 3 commits March 14, 2026 13:53
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
….java

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@RohitKushvaha01
Copy link
Member Author

@greptileai

@UnschooledGamer
Copy link
Member

Up port this fix to cordova android repo, if possible.

@RohitKushvaha01
Copy link
Member Author

RohitKushvaha01 commented Mar 14, 2026

Up port this fix to cordova android repo, if possible.

This is a WebView/Chromium issue (https://issues.chromium.org/issues/396827865
), and this solution is only a workaround, so Cordova probably won’t accept it.

@UnschooledGamer
Copy link
Member

Up port this fix to cordova android repo, if possible.

This is a WebView/Chromium issue (https://issues.chromium.org/issues/396827865
), and this solution is only a workaround, so Cordova probably won’t accept it.

I guess they might not, as referenced in apache/cordova-android#1880 (comment)

….java

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants