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

Expose static methods to manipulate the StatusBar stack imperatively #21206

Closed

Conversation

jamesreggio
Copy link
Contributor

This PR exposes three static methods (pushStackEntry, popStackEntry, and replaceStackEntry) on StatusBar that enable imperative manipulation of the StatusBar style within the stack established by mounted StatusBar components.

Motivation:

The StatusBar component provides a sensible API for manipulating that StatusBar style: every time a StatusBar component is mounted, its props are pushed onto a stack, and the props from the most recently mounted component are applied.

However, there are some scenarios where you may need to manipulate the StatusBar style from imperative code — particularly when invoking imperative third-party APIs that cause UI to appear. (For example, a user feedback utility or bug reporter that launches a full-screen modal.)

In modern iOS development, UIViewControllerBasedStatusBarAppearance is typically set to YES, which allows the third-party UIViewController to specify its preferred status bar style. However, as has been discussed at length in #11710, React Native has disabled this setting, which means that either the app's code or the third-party's React Native wrapper needs to manually manipulate React Native's StatusBar API to achieve the desired outcome.

The existing imperative StatusBar APIs are not a good fit for these needs because they simply overwrite the existing StatusBar styles, and provide no means of reverting StatusBar style changes when the third-party UI is dismissed.

To improve upon this situation, this PR makes it possible to call StatusBar.pushStackEntry before launching the third-party UI, wait for the UI to dismiss, and then call StatusBar.popStackEntry (supplying the token returned from the push call).

I've featured the new stack-based imperative methods in the documentation, but stopped short of explicitly deprecating the older imperative methods — though I can think of no reason not to deprecate them. Feedback is welcome on this point.

Test Plan:

We've been using this patch in our production app without issue since February 2018.

I've recorded a video that shows the that the imperatively-pushed StatusBar stack entries interface correctly with mounted StatusBar components. You can see the code for this example here (though you'll need to apply this PR to run it).

2018-09-19-react-native-imperative-statusbar

Release Notes:

[GENERAL] [ENHANCEMENT] [StatusBar] - Add static methods to manipulate StatusBar stack imperatively

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2018
Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

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

eslint found some issues. You may run yarn prettier or npm run prettier to fix these.

Libraries/Components/StatusBar/StatusBar.js Show resolved Hide resolved
Libraries/Components/StatusBar/StatusBar.js Show resolved Hide resolved
Libraries/Components/StatusBar/StatusBar.js Show resolved Hide resolved
Libraries/Components/StatusBar/StatusBar.js Show resolved Hide resolved
Libraries/Components/StatusBar/StatusBar.js Show resolved Hide resolved
@jamesreggio
Copy link
Contributor Author

Regarding @analysis-bot, my method documentation is consistent with the existing code. Resolving.

@hramos
Copy link
Contributor

hramos commented Sep 19, 2018

Thanks for the PR! Importing for further review.

If merged, we'll need to update the docs at https://github.com/facebook/react-native-website, but no need to send a PR there yet.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@cpojer
Copy link
Contributor

cpojer commented Jan 22, 2019

I just rebased and updated this internally and will land it in a moment. Your explanation makes sense to me, especially since React Native chose to limit this functionality in the first place as you described.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Jan 22, 2019
@react-native-bot
Copy link
Collaborator

@jamesreggio merged commit 01f1780 into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Jan 22, 2019
@react-native-bot react-native-bot added the Merged This PR has been merged. label Jan 22, 2019
@jamesreggio jamesreggio deleted the add-static-statusbar-methods branch January 22, 2019 17:49
@hramos hramos removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 6, 2019
matt-oakes pushed a commit to matt-oakes/react-native that referenced this pull request Feb 7, 2019
…acebook#21206)

Summary:
This PR exposes three static methods (`pushStackEntry`, `popStackEntry`, and `replaceStackEntry`) on StatusBar that enable imperative manipulation of the StatusBar style within the stack established by mounted StatusBar components.

Motivation:
----------

The StatusBar **component** provides a sensible API for manipulating that StatusBar style: every time a StatusBar component is mounted, its props are pushed onto a stack, and the props from the most recently mounted component are applied.

However, there are some scenarios where you may need to manipulate the StatusBar style from imperative code — particularly when invoking imperative third-party APIs that cause UI to appear. (For example, a user feedback utility or bug reporter that launches a full-screen modal.)

In modern iOS development, `UIViewControllerBasedStatusBarAppearance` is typically set to `YES`, which allows the third-party UIViewController to specify its preferred status bar style. However, as has been discussed at length in facebook#11710, React Native has disabled this setting, which means that either the app's code or the third-party's React Native wrapper needs to manually manipulate React Native's StatusBar API to achieve the desired outcome.

The existing imperative StatusBar APIs are not a good fit for these needs because they simply overwrite the existing StatusBar styles, and provide no means of reverting StatusBar style changes when the third-party UI is dismissed.

To improve upon this situation, this PR makes it possible to call `StatusBar.pushStackEntry` before launching the third-party UI, wait for the UI to dismiss, and then call `StatusBar.popStackEntry` (supplying the token returned from the push call).

I've featured the new stack-based imperative methods in the documentation, but stopped short of explicitly deprecating the older imperative methods — though I can think of no reason not to deprecate them. Feedback is welcome on this point.

Release Notes:
--------------

[GENERAL] [ENHANCEMENT] [StatusBar] - Add static methods to manipulate StatusBar stack imperatively

Pull Request resolved: facebook#21206

Differential Revision: D9945247

Pulled By: cpojer

fbshipit-source-id: ec118268cff5b47e87be81d0b9e1728ecc3a9b02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants