Repository navigation
fix(android): implement automatic edge-to-edge and universal keyboard handling - #8366
fabiomartino wants to merge 19 commits into
Conversation
|
@fabiomartino Thank you so much Fabio. This is such a crucial fix I'm waiting for. 🙏 |
|
This does not appear to solve #8329. Reproduction: https://github.com/aeharding/cap-kb-blank-space/tree/fabio |
Hi @aeharding give it a try... // REMOVED |
|
Unfortunately it is the same problem for me. Have you tried with my reproduction? |
|
Hi @aeharding, thank you for the feedback and for providing the reproduction repo. While we couldn't replicate the exact "blank space" behavior in our specific local environment, we performed a deep dive into the logic changes between Capacitor 8.0.1 and 8.0.2. We identified that the 8.0.2 We have refined the SystemBars.java implementation with the following improvements:
Could you please try testing with this updated version of SystemBars.java? |
…iew support - Add cachedWebViewMajorVersion field to avoid repeated WebView version lookups - Add handleOnResume() override to refresh insets on app resume - Add WindowCompat.setDecorFitsSystemWindows() calls in load(), handleOnResume(), and onDOMReady() - Add null check in setStyle() PluginMethod for safer style parameter handling - Preserve backup's applyInsets() implementation with legacy WebView compatibility - Add setViewMargins() and resetViewBottomMargin() for legacy WebView workaround - Use MIN_INSETS_VERSION (LOLLIPOP) instead of VANILLA_ICE_CREAM for broader SDK support - Use INSETS_HANDLING_CSS constant instead of hardcoded string literal - Remove unused setViewBottomMargin() and getBottomInset() methods - Rename viewportMetaJSFunction to VIEWPORT_META_JS constant Fixes edge-to-edge display issues on devices with various WebView versions.
…lder Android - Add support for API 21-34 by using LOLLIPOP instead of VANILLA_ICE_CREAM - Add legacy fallback for WebView < 140 on Android API < 30 that forces CSS safe-area vars to 0 to prevent double compensation in footer/tab-bar layouts - Preserve original legacy IME margins behavior for Android 11+ (API 30-33) - Fixes ionic-team#8394: CSS safe-area-inset-x not being applied on Android API <= 34
Scope legacy fallback to Android API < 30 and force zero CSS safe-area vars in that path to prevent double compensation on top/bottom bars, while preserving behavior on newer API levels.
Keep top safe-area inset at 0 for Android API < 30 (legacy and modern WebView paths), preserve semantic bottom inset handling, and prevent malformed safe-area CSS custom properties from persisting across keyboard/lifecycle transitions. Se vuoi una versione con riferimento issue: fix(android): stabilize safe-area CSS behavior on API < 30 (ionic-team#8394) Keep top safe-area inset at 0 for Android API < 30 (legacy and modern WebView paths), preserve semantic bottom inset handling, and prevent malformed safe-area CSS custom properties from persisting across keyboard/lifecycle transitions.
|
Thank you for this PR. It fix the webview issue on the SDK <= 34. But noticed, scroll is blocked when keyboard is opened. Can we please fix that issue? |
Resolve the SystemBars.java three-way conflict keeping the automatic edge-to-edge and universal keyboard architecture from this branch (ionic-team#8366) while adopting upstream's structural changes: - insetsHandling as a validated string field with Logger.warn fallback (upstream ionic-team#8481), replacing the boolean gate across listener registration, initial CSS variables, and onDOMReady - separate status bar and gesture bar style tracking (upstream ionic-team#8409) - per-bar show/hide with else-if semantics (upstream ionic-team#8480) - viewport JS text block TODO note for the future 'full' option Fold in compatible ideas from open PR ionic-team#8454: - navBarVisible tracking in setHidden so hidden navigation bars do not contribute phantom bottom insets - navigation_bar_height resource fallback for legacy (API < 30) OEM builds reporting zero-height nav insets, suppressed for lint (InternalInsetResource, DiscouragedApi) since no supported API exposes a static navigation bar height - IME visibility fallback below Android O via ime inset bottom > 0 - store requested styles so DEFAULT keeps following system theme changes when reapplied on configuration change or resume PR ionic-team#8528's SDK gate for IME padding needs no code here: this branch never applies window IME padding (keyboard is handled via CSS variables and the inset builder), so double keyboard spacing on API <= 34 cannot occur.
Merge upstream 8.5.2 (5e0f678) into the safe-area/edge-to-edge PR branch. Integrates upstream ionic-team#8535 (safe area / systembars fixes) while keeping the branch architecture (legacy API 21-34 support, margins + CSS variables, keyboard via CSS, no window padding): - Add 'native' insetsHandling mode: safe area handling delegated to the platform/WebView, insets passed through untouched, no CSS variables injected, and setDecorFitsSystemWindows(true) is no longer forced so apps can opt into native edge-to-edge (env(safe-area-inset-*)). - Add 'initialViewportFitValueHint' config to pre-seed hasViewportCover and prevent layout shifts on first paint. - Adopt single-webViewListener registration (prevents duplicate listeners across start cycles) gated on 'disable'. - Move viewport-fit detection from the removed @JavascriptInterface onDOMReady() into onPageCommitVisible (drop CapacitorSystemBarsAndroidInterface). - Add warnAboutUnsupportedConfigurationValues() for Keyboard.resizeOnFullScreen. - Keep: requested-style storage (DEFAULT follows system theme), nav bar resource-height fallback for API<30, pre-Oreo IME visibility handling, cached WebView major version with NumberFormatException safety, hardened CSS variable injection (removeProperty + duplicate cleanup). Validation: compileReleaseJavaWithJavac, lintRelease, testRelease pass.



Summary
This PR implements a fix for the SystemBars plugin on Android that resolves the issue where too much bottom safe area is displayed when the keyboard is visible, and adds support for safe-area CSS injection on older Android versions.
Issues Addressed
Key Changes
getInsetsIgnoringVisibilityfor status bar and cutout to prevent page jumping during keyboard transitions--safe-area-inset-bottomis set to 0 when keyboard is visibleLOLLIPOP(API 21) instead ofVANILLA_ICE_CREAM(API 36) for safe-area CSS injection, supporting Android API 21-34Behavior
WebView >= 140
--safe-area-inset-*are injected with correct values on all Android versions (API 21+)--safe-area-inset-bottom= 0 when keyboard is visibleWebView < 140 (Legacy/Broken)
--safe-area-inset-bottomforced to 0 to avoid double-offset with fixed footersKeyboard State
Configuration
Default configuration works automatically:
Technical Details
Testing
Tested on:
Breaking Changes
None. This is a bug fix that maintains existing behavior while fixing the keyboard bottom area issue and extending support to older Android versions.
Migration
No migration required. Existing configurations continue to work.