From 86cae63a689fc548a55aad326157be2efa34418f Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sat, 14 Mar 2026 13:46:36 +0530 Subject: [PATCH 1/6] fix: webview resize --- hooks/post-process.js | 52 +++++++++++++++++++ .../com/foxdebug/system/SoftInputAssist.java | 36 +++++++++++++ src/plugins/system/plugin.xml | 15 +++--- 3 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java diff --git a/hooks/post-process.js b/hooks/post-process.js index 85aef4009..8cd2d02bf 100644 --- a/hooks/post-process.js +++ b/hooks/post-process.js @@ -28,6 +28,7 @@ copyDirRecursively(localResPath, resPath); enableLegacyJni(); enableStaticContext(); patchTargetSdkVersion(); +enableKeyboardWorkaround(); function getTmpDir() { @@ -185,6 +186,57 @@ function enableStaticContext() { } } +function enableKeyboardWorkaround() { + try{ + const prefix = execSync('npm prefix').toString().trim(); + const mainActivityPath = path.join( + prefix, + 'platforms/android/app/src/main/java/com/foxdebug/acode/MainActivity.java' + ); + + if (!fs.existsSync(mainActivityPath)) { + return; + } + + let content = fs.readFileSync(mainActivityPath, 'utf-8'); + + // Skip if already patched + if (content.includes('SoftInputAssist')) { + return; + } + + // Add import + if (!content.includes('import com.foxdebug.system.SoftInputAssist;')) { + content = content.replace( + /import java.lang.ref.WeakReference;/, + match => + match + '\nimport com.foxdebug.system.SoftInputAssist;' + ); + } + + // Declare field + if (!content.includes('private SoftInputAssist softInputAssist;')) { + content = content.replace( + /public class MainActivity extends CordovaActivity\s*\{/, + match => + match + + `\n\n private SoftInputAssist softInputAssist;\n` + ); + } + + // Initialize in onCreate + content = content.replace( + /loadUrl\(launchUrl\);/, + `loadUrl(launchUrl);\n\n softInputAssist = new SoftInputAssist(this);` + ); + + fs.writeFileSync(mainActivityPath, content, 'utf-8'); + console.log('[Cordova Hook] ✅ Enabled keyboard workaround'); + } catch (err) { + console.error('[Cordova Hook] ❌ Failed to enable keyboard workaround:', err.message); + } +} + /** * Copy directory recursively diff --git a/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java new file mode 100644 index 000000000..58db73217 --- /dev/null +++ b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java @@ -0,0 +1,36 @@ +package com.foxdebug.system; + +import android.app.Activity; +import android.graphics.Rect; +import android.view.View; + +public class SoftInputAssist { + private final View rootView; + private final View contentView; + private int baseline = -1; + + public SoftInputAssist(Activity activity) { + rootView = activity.getWindow().getDecorView(); + contentView = activity.findViewById(android.R.id.content); + + rootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> { + Rect r = new Rect(); + rootView.getWindowVisibleDisplayFrame(r); + + int heightDiff = rootView.getHeight() - (r.bottom - r.top); + + // Save baseline (system bars only) + if (baseline == -1) { + baseline = heightDiff; + } + + int keyboardHeight = heightDiff - baseline; + + if (keyboardHeight > 0) { + contentView.setPadding(0, 0, 0, keyboardHeight); + } else { + contentView.setPadding(0, 0, 0, 0); + } + }); + } +} \ No newline at end of file diff --git a/src/plugins/system/plugin.xml b/src/plugins/system/plugin.xml index cca8cce88..caa34109f 100644 --- a/src/plugins/system/plugin.xml +++ b/src/plugins/system/plugin.xml @@ -37,10 +37,11 @@ - - - - - - - + + + + + + + + From 348cc69c4bfc2d8c0f9991b62d13ef1a605b2e16 Mon Sep 17 00:00:00 2001 From: Rohit Kushvaha Date: Sat, 14 Mar 2026 13:53:07 +0530 Subject: [PATCH 2/6] Update hooks/post-process.js Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- hooks/post-process.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/post-process.js b/hooks/post-process.js index 8cd2d02bf..21c411934 100644 --- a/hooks/post-process.js +++ b/hooks/post-process.js @@ -208,7 +208,7 @@ function enableKeyboardWorkaround() { // Add import if (!content.includes('import com.foxdebug.system.SoftInputAssist;')) { content = content.replace( - /import java.lang.ref.WeakReference;/, + /import java.lang.ref.WeakReference;|import org\.apache\.cordova\.\*;/, match => match + '\nimport com.foxdebug.system.SoftInputAssist;' ); From 918adad40de2fcca7cacb84b3fff09d79fcafd28 Mon Sep 17 00:00:00 2001 From: Rohit Kushvaha Date: Sat, 14 Mar 2026 13:53:24 +0530 Subject: [PATCH 3/6] Update src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .../system/android/com/foxdebug/system/SoftInputAssist.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java index 58db73217..08c235a00 100644 --- a/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java +++ b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java @@ -20,7 +20,7 @@ public SoftInputAssist(Activity activity) { int heightDiff = rootView.getHeight() - (r.bottom - r.top); // Save baseline (system bars only) - if (baseline == -1) { + if (baseline == -1 || heightDiff < baseline) { baseline = heightDiff; } From 8d0300e003a0e0b439faa9f0fc10e77b721e30e8 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sat, 14 Mar 2026 14:12:14 +0530 Subject: [PATCH 4/6] feat: animations --- .../com/foxdebug/system/SoftInputAssist.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java index 08c235a00..00881b22d 100644 --- a/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java +++ b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java @@ -1,36 +1,38 @@ package com.foxdebug.system; import android.app.Activity; -import android.graphics.Rect; import android.view.View; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.core.view.WindowInsetsAnimationCompat; + public class SoftInputAssist { - private final View rootView; - private final View contentView; - private int baseline = -1; public SoftInputAssist(Activity activity) { - rootView = activity.getWindow().getDecorView(); - contentView = activity.findViewById(android.R.id.content); + View contentView = activity.findViewById(android.R.id.content); - rootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> { - Rect r = new Rect(); - rootView.getWindowVisibleDisplayFrame(r); + ViewCompat.setWindowInsetsAnimationCallback( + contentView, + new WindowInsetsAnimationCompat.Callback( + WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE + ) { + @Override + public WindowInsetsCompat onProgress( + WindowInsetsCompat insets, + java.util.List runningAnimations) { - int heightDiff = rootView.getHeight() - (r.bottom - r.top); + Insets ime = insets.getInsets(WindowInsetsCompat.Type.ime()); + Insets nav = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - // Save baseline (system bars only) - if (baseline == -1 || heightDiff < baseline) { - baseline = heightDiff; - } + int keyboardHeight = Math.max(0, ime.bottom - nav.bottom); - int keyboardHeight = heightDiff - baseline; + contentView.setPadding(0, 0, 0, keyboardHeight); - if (keyboardHeight > 0) { - contentView.setPadding(0, 0, 0, keyboardHeight); - } else { - contentView.setPadding(0, 0, 0, 0); + return insets; + } } - }); + ); } } \ No newline at end of file From eb5ff177b218620ed00e3d82b046b58a5ecee32f Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sat, 14 Mar 2026 14:24:49 +0530 Subject: [PATCH 5/6] feat: added support for keyboards with no animations --- .../com/foxdebug/system/SoftInputAssist.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java index 00881b22d..dd1027911 100644 --- a/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java +++ b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.view.View; +import java.util.List; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; @@ -10,21 +11,48 @@ public class SoftInputAssist { + private boolean animationRunning = false; + public SoftInputAssist(Activity activity) { View contentView = activity.findViewById(android.R.id.content); + ViewCompat.setOnApplyWindowInsetsListener(contentView, (v, insets) -> { + + if (!animationRunning) { + Insets ime = insets.getInsets(WindowInsetsCompat.Type.ime()); + Insets nav = insets.getInsets(WindowInsetsCompat.Type.navigationBars()); + + int keyboardHeight = Math.max(0, ime.bottom - nav.bottom); + + v.setPadding(0, 0, 0, keyboardHeight); + } + + return insets; + }); + ViewCompat.setWindowInsetsAnimationCallback( contentView, new WindowInsetsAnimationCompat.Callback( WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE ) { + + @Override + public void onPrepare(WindowInsetsAnimationCompat animation) { + animationRunning = true; + } + + @Override + public void onEnd(WindowInsetsAnimationCompat animation) { + animationRunning = false; + } + @Override public WindowInsetsCompat onProgress( WindowInsetsCompat insets, - java.util.List runningAnimations) { + List runningAnimations) { Insets ime = insets.getInsets(WindowInsetsCompat.Type.ime()); - Insets nav = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + Insets nav = insets.getInsets(WindowInsetsCompat.Type.navigationBars()); int keyboardHeight = Math.max(0, ime.bottom - nav.bottom); From 1777e408f601a0af5e4a40a96d165ad03b726836 Mon Sep 17 00:00:00 2001 From: Rohit Kushvaha Date: Sat, 14 Mar 2026 14:25:37 +0530 Subject: [PATCH 6/6] Update src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .../system/android/com/foxdebug/system/SoftInputAssist.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java index dd1027911..90b8d9ca4 100644 --- a/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java +++ b/src/plugins/system/android/com/foxdebug/system/SoftInputAssist.java @@ -56,7 +56,7 @@ public WindowInsetsCompat onProgress( int keyboardHeight = Math.max(0, ime.bottom - nav.bottom); - contentView.setPadding(0, 0, 0, keyboardHeight); + contentView.setPadding(contentView.getPaddingLeft(), contentView.getPaddingTop(), contentView.getPaddingRight(), keyboardHeight); return insets; }