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
| .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
| 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
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)