fix: resolve issues with safe area / systembars plugin - #8535
Conversation
| if (isSafeAreaPluginPresent()) { | ||
| Logger.warn( | ||
| "SystemBars", | ||
| "You should uninstall `@capacitor-community/safe-area`. Having this library installed can lead to unexpected behavior." |
There was a problem hiding this comment.
Having this warning here seems fair to me, as the two are strictly incompatible and there are still loads of users installing the community plugin
There was a problem hiding this comment.
Ended up removing this warning. Because, actually, I think it makes more sense to solve this using an updating peerDependencies policy in the plugin itself. Nonetheless it might be good to mention somewhere in the docs that the use of (any) third party safe area plugins is discouraged. And if a developer wants to use such a plugin, that insetsHandling should be set to disable to prevent interference
| .build(); | ||
| } | ||
|
|
||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
There was a problem hiding this comment.
I'm still not sure what this if-statement was meant for. I asked about it a few times in other PRs but never got a response, so I dont know the rationale behind it. Seems unnecessary to me. Moreover, it seems to be the root cause of many bug reports
There was a problem hiding this comment.
There were some internal requirements we had to adhere to. Its not necessary anymore.
| * | ||
| * @default false | ||
| */ | ||
| initialViewportFitCover?: boolean; |
There was a problem hiding this comment.
This one is really important to prevent layout jumps
There was a problem hiding this comment.
Ended up renaming this to initialViewportFitValueHint (in 7abde6f) because it sounds a bit more logical
| if (!systemBarsInsetsHandling.equals("disable") && keyboardResizeOnFullScreen) { | ||
| Logger.warn( | ||
| "SystemBars", | ||
| "You should omit `Keyboard.resizeOnFullScreen` in your `capacitor.config.json`. Other values can lead to unexpected behavior." |
There was a problem hiding this comment.
As I mentioned before, I think this config value should be deprecated altogether. If you still want it, I think it makes much more sense to include it in this plugin to prevent future bugs and resolve present bugs
There was a problem hiding this comment.
We've had discussions about this internally, and we agree. We'll get to it eventually. For now, this warning will do.
| Insets safeAreaInsets = calcSafeAreaInsets(newInsets); | ||
| injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left); |
There was a problem hiding this comment.
I simplified this, because it was doing redundant recalculations which caused bugs across different webview versions
There was a problem hiding this comment.
We might want to call EdgeToEdge.enable(this) inside BridgeActivity.onCreate (if insetsHandling !== 'disable'). Because it's easy to forget. See #8522 for example.
However, one could argue that it's breaking change. In that case, it should then be documented somewhere, and instead be added in Capacitor v9.
On the other hand, your app will express unexpected behavior when not calling EdgeToEdge.enable(this), and there already were quite a few breaking changes in non-major updates in Capacitor v8 regarding the safe area. So it might make sense to add it nonetheless
There was a problem hiding this comment.
Just to reduce the amount of churn and potential for upstream breaking changes for some of the other teams depending on Capacitor 8 currently, I'll just make note of this in the docs. We'll make all of this default in Cap 9.
c202f7f to
7abde6f
Compare
…ortFitValueHint`
7abde6f to
9b35343
Compare
7b2d246 to
4d9996b
Compare
|
you can try to make a patch with https://capgo.app/docs/plugins/capacitor-patch/ to use it and get it or https://github.com/Cap-go/capacitor-plus merged to capacitor |
…rred conflicts)
…rite Upstream ionic-team#8535 removed navBarVisible state; tests that reflected on the private field caused NoSuchFieldException in test-android. Keep hide/show WindowInsetsController coverage. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
…rred conflicts)
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
…rred conflicts)
theproducer
left a comment
There was a problem hiding this comment.
Thanks for consolidating and drilling down these edge to edge bugs!
| if (!systemBarsInsetsHandling.equals("disable") && keyboardResizeOnFullScreen) { | ||
| Logger.warn( | ||
| "SystemBars", | ||
| "You should omit `Keyboard.resizeOnFullScreen` in your `capacitor.config.json`. Other values can lead to unexpected behavior." |
There was a problem hiding this comment.
We've had discussions about this internally, and we agree. We'll get to it eventually. For now, this warning will do.
| .build(); | ||
| } | ||
|
|
||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
There was a problem hiding this comment.
There were some internal requirements we had to adhere to. Its not necessary anymore.
…l/capacitor into fix/resolve-issues-with-safe-area
🎉 you're welcome! And thank you for taking the time to review it and making it happen. Appreciated! |
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.
|
Hi, after upgrading to 8.5.2 we hit a regression that we traced to the listener move in this PR, filed as #8603. On API < 30, attaching the Measured on a PAX A920Pro (Android 10, WebView 147): |
This resolves some (most/all maybe even) current issues with the safe area / systembars plugin. These changes have been battle tested in production for several months now.
Closes #8525
Closes #8528
Closes #8416
Closes ionic-team/capacitor-keyboard#68
Closes ionic-team/capacitor-keyboard#61
Closes ionic-team/capacitor-keyboard#46
Closes ionic-team/capacitor-keyboard#28
Closes ionic-team/capacitor-keyboard#53
Closes ionic-team/capacitor-keyboard#57
And potentially some more. I haven't had time to look at all issues.
We already had a conversation about some of these design approaches earlier on. See #8268 and #8384 (comment)