Skip to content

feat(SystemBars): add getStyle and statusTap listener functionality - #8732

Open
theproducer wants to merge 6 commits into
mainfrom
feat/systembars/status-tap
Open

theproducer wants to merge 6 commits into
mainfrom
feat/systembars/status-tap

Conversation

@theproducer

Copy link
Copy Markdown
Contributor

Description

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

Tests or Reproductions

Screenshots / Media

Platforms Affected

  • Android
  • iOS
  • Web

Notes / Comments

@theproducer
theproducer marked this pull request as ready for review November 19, 2026 17:26

@OS-pedrogustavobilro OS-pedrogustavobilro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leaving some comments

Note: Used capacitor-testapp to test (draft PR to test the new methods ionic-team/capacitor-testapp#797)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not seeing any internal JIRA items or GitHub issues tied to this PR.

Just double checking if the PR description is missing any of those, or if this is for something that doesn't yet have a work item.

Comment on lines +34 to +44
func testDeallocatedPluginStopsObservingStatusBarTaps() {
weak var weakPlugin: SpySystemBarsPlugin?
autoreleasepool {
let plugin = makePlugin()
plugin.load()
weakPlugin = plugin
}

XCTAssertNil(weakPlugin)
NotificationCenter.default.post(name: .capacitorStatusBarTapped, object: nil)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Some suggestions by claude on the iOS tests, take em with a grain of salt

testDeallocatedPluginStopsObservingStatusBarTaps is effectively vacuous. The observer closure uses [weak self], so the weak reference is nil whether or not deinit removes the observer. The final post asserts nothing. It would pass if the deinit were deleted, so makes sense to removed the test. Removing an observer that is already a no-op can't be tested without injecting the notification center.

Suggested tests to add (some maybe more relevant than others):

  • Make testGetStyleReturnsStyleSetBySetStyle run with all styles DARK, LIGHT and DEFAULT.
  • An unknown style such as PURPLE reports DEFAULT.
  • getStyle with no bridge returns DEFAULT.
  • A status-bar tap before load() does not notify.

verify(controller, never()).show(WindowInsetsCompat.Type.statusBars());
}

@Test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Some suggestions from Claude on the android unit tests, take em with a grain of salt

Suggested new testst to add:

  • getStyle returns DEFAULT before any style is set.
  • Styling only the status bar leaves the navigation bar untouched, both its appearance and its reported style.
  • DEFAULT resolves to dark appearance in night mode while still reporting DEFAULT.
  • An explicit DARK style "survives" a configuration change.

Comment thread core/src/core-plugins.ts
* On iOS, only the status bar has a style, so this option is ignored.
*
* @since 9.0.0
* @default 'StatusBar'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: to align with other places that have a SystemBarType parameter, maybe should be

Suggested change
* @default 'StatusBar'
* @default SystemBarType.StatusBar

Comment thread core/src/core-plugins.ts
/**
* The system bar to get the style of.
*
* On iOS, only the status bar has a style, so this option is ignored.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: since you added this line, maybe worth mentioning the same for SystemBarsStyleOptions of setStyle

Comment thread core/src/core-plugins.ts
Comment on lines +637 to +644
* Get the current style of a system bar.
*
* Returns the style that was requested, so `DEFAULT` is returned as `DEFAULT`
* rather than the `LIGHT` or `DARK` style it currently resolves to.
*
* @since 9.0.0
*/
getStyle(options?: SystemBarsGetStyleOptions): Promise<SystemBarsGetStyleResult>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This works fine, but there could also be people that want to know, when DEFAULT, is the system bars LIGHT or DARK, i.e. what is the app theme.

Afaik there's no way in an official plugin to check if app is (natively) in dark mode or light mode. Which doesn't make sense to add here anyways.

Wondering if it's worth having the getStyle method return style and resolvedStyle to overcome this kind of situation, or would you say it doesn't make that much sense?

if (bar.isEmpty() || bar.equals(BAR_GESTURE_BAR)) {
currentGestureBarStyle = style;
windowInsetsControllerCompat.setAppearanceLightNavigationBars(!style.equals(STYLE_DARK));
windowInsetsControllerCompat.setAppearanceLightNavigationBars(!resolvedStyle.equals(STYLE_DARK));

@OS-pedrogustavobilro OS-pedrogustavobilro Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Claude noticed this difference between iOS and Android, it's not introduced by your PR, so this isn't necessarily the place to fix it, but I'll point it out here and leave that decision to you:

Passing an undefined style like Purple (which shouldn't happen if they're using typescript, but can happen in plain JS), on iOS it sets it to default, on Android the raw string is stored in current variable, and sets the appearance as light theme (dark text).

This issue is probably happening in 8.x too.

Makes more sense for Android to behave like iOS to me in this scenario. If you do this change, adding a test may also be nice.

Comment on lines 109 to 114
protected void handleOnConfigurationChanged(Configuration newConfig) {
super.handleOnConfigurationChanged(newConfig);

setStyle(currentGestureBarStyle, BAR_GESTURE_BAR);
setStyle(currentStatusBarStyle, BAR_STATUS_BAR);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something I noticed differs between Android and iOS. Again, this isn't specific to this PR, so doesn't need to get fixed here really, just wanted to bring it up.

This issue is probably happening in 8.x too.

When you call setStyle with DARK, and your phone/app is in dark theme, if you switch to light theme:

  • On Android: The appearance of system bars changes to LIGHT but getStyle returns DARK
  • On iOS: The appearance of system bars remains DARK and getStyle returns DARK

I think iOS is the correct one here, but because we have this handleOnConfigurationChanged code for Android specifically I'm not 100% sure.

Comment thread core/src/core-plugins.ts
Comment on lines 687 to +693
async setStyle(): Promise<void> {
this.unavailable('not available for web');
}

async getStyle(): Promise<SystemBarsGetStyleResult> {
throw this.unavailable('not available for web');
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any particular reason why we added the throw here since other methods don't have it?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants