fix: resolve issues with safe area / systembars plugin - #8535
Conversation
There was a problem hiding this comment.
I couldn't find documentation on how to (auto)generate this doc. But I think it should be good like this
| static final String BAR_STATUS_BAR = "StatusBar"; | ||
| static final String BAR_GESTURE_BAR = "NavigationBar"; | ||
|
|
||
| // TODO: In Cap 9, add an additional option "full" |
There was a problem hiding this comment.
Not sure what this was for, but I removed it because I think with the addition of native all use cases are covered
| } | ||
|
|
||
| @JavascriptInterface | ||
| public void onDOMReady() { |
There was a problem hiding this comment.
Dong this only in the onPageCommitVisible listener seems to work equally fine in my testing
| 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
| * | ||
| * @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
| * This option is only supported on Android. | ||
| * | ||
| * @default `DEFAULT` | ||
| * @default 'css' |
There was a problem hiding this comment.
I would strongly suggest to make native the default in Capacitor v9 as that would align with how the web and iOS platforms work right now. So I think that is the more expected behavior
| } | ||
|
|
||
| ViewCompat.setOnApplyWindowInsetsListener((View) getBridge().getWebView().getParent(), (v, insets) -> { | ||
| View view = getActivity().getWindow().getDecorView(); |
There was a problem hiding this comment.
This is necessary for the keyboard animation to have the correct background color
| } | ||
|
|
||
| initWindowInsetsListener(); | ||
| initSafeAreaCSSVariables(); |
There was a problem hiding this comment.
This was redundant, because it's already being handled in the initWindowInsetsListener
| 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
37861c7 to
281dc12
Compare
…ortFitValueHint`
c202f7f to
7abde6f
Compare
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)