Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(statusbar): Simple built-in status bar support #1523

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dpogue
Copy link
Member

@dpogue dpogue commented Jan 29, 2025

Platforms affected

iOS

Motivation and Context

Web content authors should have control over how the status bar is handled using the built-in web platform functionality for UI colouring and opting in to showing behind the status bar or not.

Description

This adds a background behind the status bar automatically when a page does not request to extend itself behind the status bar using a meta tag with viewport-fit=cover. It automatically shows and hides as the value of the viewport-fit option changes.

On iOS 16.4 and newer, it will be coloured according to the meta theme-color tag, and a default colour can be set in the storyboard for a CDVViewController.

We expose a very basic JS API hanging off the existing window.statusbar property that allows controlling the visibility (of the status bar contents entirely, not just of the background view) and overriding the background colour.

The colour is determined as follows:

  1. Any colour set explicitly with the JS API (if any)
  2. Any colour pulled from the meta tag (iOS 16.4+, if any)
  3. The status bar background colour specified in the storyboard (if any)
  4. The general background colour specified in the storyboard (if any)
  5. The default system background colour

Efforts were made to ensure that this does not interfere with the existing CDVStatusBar plugin implementation (although maybe this can replace it for most common use cases), by making the display of this built-in conditional on not having the CDVStatusBar plugin installed.

Remaining Work

  • Wire the StatusBarBackgroundColor preference up to an XCAsset colorset in the template and set it in the Main.storyboard file
  • Do a bunch of testing with CDVStatusBar installed to make sure there are no conflicts

Testing

Tested locally in an iPhone 16 Pro Max simulator.

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • I've updated the documentation if necessary

If you call scrollView on a UIView that does not have its own scrollView
method, this hijack method will keep recursively calling itself until
you run out of stack space. Try to guard against that by making sure
that it's not getting called on the same instance multiple times.

TODO: Think about thread safety, but in theory because this is
view-related stuff it's only safe to run on the main thread.
This adds a background behind the status bar automatically when a page
does not request to extend itself behind the status bar using a meta tag
with `viewport-fit=cover`. It automatically shows and hides as the value
of the viewport-fit option changes.

On iOS 16.4 and newer, it will be coloured according to the meta
`theme-color` tag, and a default colour can be set in the storyboard for
a CDVViewController.

We expose a very basic JS API hanging off the existing
`window.statusbar` property that allows controlling the visibility (of
the status bar contents entirely, not just of the background view) and
overriding the background colour.

The colour is determined as follows:
  1. Any colour set explicitly with the JS API (if any)
  2. Any colour pulled from the meta tag (iOS 16.4+, if any)
  3. The default colour specified in the storyboard (if any)
  4. The background colour specified in the storyboard (if any)
  5. The default system background colour

Efforts were made to ensure that this does not interfere with the
existing CDVStatusBar plugin implementation (although maybe this can
replace it for most common use cases), by making the display of this
built-in conditional on not having the CDVStatusBar plugin installed.
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.41%. Comparing base (5cf4d94) to head (e007faf).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1523   +/-   ##
=======================================
  Coverage   81.41%   81.41%           
=======================================
  Files          16       16           
  Lines        1862     1862           
=======================================
  Hits         1516     1516           
  Misses        346      346           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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