Repository navigation
feat(SystemBars): add getStyle and statusTap listener functionality - #8732
theproducer wants to merge 6 commits into
Conversation
# Conflicts: # android/capacitor/src/test/java/com/getcapacitor/plugin/SystemBarsTest.java
OS-pedrogustavobilro
left a comment
There was a problem hiding this comment.
Leaving some comments
Note: Used capacitor-testapp to test (draft PR to test the new methods ionic-team/capacitor-testapp#797)
There was a problem hiding this comment.
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.
| func testDeallocatedPluginStopsObservingStatusBarTaps() { | ||
| weak var weakPlugin: SpySystemBarsPlugin? | ||
| autoreleasepool { | ||
| let plugin = makePlugin() | ||
| plugin.load() | ||
| weakPlugin = plugin | ||
| } | ||
|
|
||
| XCTAssertNil(weakPlugin) | ||
| NotificationCenter.default.post(name: .capacitorStatusBarTapped, object: nil) | ||
| } |
There was a problem hiding this comment.
🤖 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 |
There was a problem hiding this comment.
🤖 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.
| * On iOS, only the status bar has a style, so this option is ignored. | ||
| * | ||
| * @since 9.0.0 | ||
| * @default 'StatusBar' |
There was a problem hiding this comment.
Minor: to align with other places that have a SystemBarType parameter, maybe should be
| * @default 'StatusBar' | |
| * @default SystemBarType.StatusBar |
| /** | ||
| * The system bar to get the style of. | ||
| * | ||
| * On iOS, only the status bar has a style, so this option is ignored. |
There was a problem hiding this comment.
Minor: since you added this line, maybe worth mentioning the same for SystemBarsStyleOptions of setStyle
| * 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>; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
🤖 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.
| protected void handleOnConfigurationChanged(Configuration newConfig) { | ||
| super.handleOnConfigurationChanged(newConfig); | ||
|
|
||
| setStyle(currentGestureBarStyle, BAR_GESTURE_BAR); | ||
| setStyle(currentStatusBarStyle, BAR_STATUS_BAR); | ||
| } |
There was a problem hiding this comment.
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
LIGHTbutgetStylereturnsDARK - On iOS: The appearance of system bars remains
DARKandgetStylereturnsDARK
I think iOS is the correct one here, but because we have this handleOnConfigurationChanged code for Android specifically I'm not 100% sure.
| async setStyle(): Promise<void> { | ||
| this.unavailable('not available for web'); | ||
| } | ||
|
|
||
| async getStyle(): Promise<SystemBarsGetStyleResult> { | ||
| throw this.unavailable('not available for web'); | ||
| } |
There was a problem hiding this comment.
Any particular reason why we added the throw here since other methods don't have it?
Description
Change Type
Rationale / Problems Fixed
Tests or Reproductions
Screenshots / Media
Platforms Affected
Notes / Comments