Skip to content

fix: resolve issues with safe area / systembars plugin#8535

Open
tafelnl wants to merge 6 commits into
ionic-team:mainfrom
tafelnl:fix/resolve-issues-with-safe-area
Open

fix: resolve issues with safe area / systembars plugin#8535
tafelnl wants to merge 6 commits into
ionic-team:mainfrom
tafelnl:fix/resolve-issues-with-safe-area

Conversation

@tafelnl

@tafelnl tafelnl commented Jul 21, 2026

Copy link
Copy Markdown

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)

Comment thread core/system-bars.md

@tafelnl tafelnl Jul 21, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

@tafelnl tafelnl Jul 21, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

@tafelnl tafelnl Jul 21, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@tafelnl tafelnl Jul 21, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@tafelnl tafelnl Jul 21, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread cli/src/declarations.ts
*
* @default false
*/
initialViewportFitCover?: boolean;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@tafelnl tafelnl Jul 21, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread cli/src/declarations.ts
* This option is only supported on Android.
*
* @default `DEFAULT`
* @default 'css'

@tafelnl tafelnl Jul 21, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary for the keyboard animation to have the correct background color

}

initWindowInsetsListener();
initSafeAreaCSSVariables();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was redundant, because it's already being handled in the initWindowInsetsListener

Comment on lines -243 to -244
Insets safeAreaInsets = calcSafeAreaInsets(newInsets);
injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified this, because it was doing redundant recalculations which caused bugs across different webview versions

@Vissie2

Vissie2 commented Jul 22, 2026

Copy link
Copy Markdown

@theproducer

@theproducer theproducer self-assigned this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment