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

Fix user interface style in native stack view controllers #481

Merged

Conversation

tsapeta
Copy link
Member

@tsapeta tsapeta commented Apr 28, 2020

Why

In Expo client, which supports both light and dark styles, you can open an experience that has strict setting to light or dark mode. In that case experience's root view controller is set to the style specified by the user, however view controllers presented over it or added as a child have overrideUserInterfaceStyle set to UIUserInterfaceStyleUnspecified which causes the view controller to use the style that is set in system settings so we get some UIKit's views rendered with incorrect interface style 😞 This only affects view controllers presented modally, thus doing the same for pushed screens is not necessary.
@brentvatne prepared reproducible example: https://github.com/brentvatne/modal-example

How

Native stack's view controllers will inherit overrideUserInterfaceStyle from presenting view controller.

Test Plan

Example https://github.com/brentvatne/modal-example works as expected in Expo client with style set to Dark in system settings. *This also requires one small change in the client itself, so it won't work in the current version in the app store.

Copy link
Member

@kmagiera kmagiera left a comment

Choose a reason for hiding this comment

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

Looks good, left a few minor comments. Also wanted to clarify if I understand this correctly: this only applies to VC's presented modally and does not affect pushed screens? If that's the case can you update description to indicate that the problem was only with modals and hence this fix only makes changes to the logic responsible for presenting modals?


if (@available(iOS 13.0, *)) {
// Inherit UI style from its parent - solves an issue with incorrect style being applied to some UIKit views like date picker or segmented control.
next.overrideUserInterfaceStyle = previous.overrideUserInterfaceStyle;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should make any difference in your case but I think it'd be more intuitive if presented controllers would inherit styles from their container and not from the sibling modal. If so I'd copy the property from _controller.overrideUserInterfaceStyle here and not from previous

@@ -285,6 +285,12 @@ - (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
for (NSUInteger i = changeRootIndex; i < controllers.count; i++) {
UIViewController *next = controllers[i];
BOOL lastModal = (i == controllers.count - 1);

if (@available(iOS 13.0, *)) {
Copy link
Member

Choose a reason for hiding this comment

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

This also does not matter I think as soon appstore will stop accepting builds made with prev versions of xcode (if that isn't the case already) but for consistency can we add #ifdef __IPHONE_13_0 to wrap this call much like we do in other cases where we do version checks

@kmagiera kmagiera merged commit 4f7142c into software-mansion:master Apr 29, 2020
tsapeta added a commit to expo/expo that referenced this pull request Apr 29, 2020
# Why

Followup software-mansion/react-native-screens#481

# How

Copied my changes I made to `react-native-screens` into our codebase and backported them to SDK37. I also had to force `EXAppViewController`s child to use parent's interface style as well. Previously I though this issue happens only for view controllers that are being presented modally.

# Test Plan

Tested against https://github.com/brentvatne/modal-example
tsapeta added a commit to expo/expo that referenced this pull request Apr 29, 2020
# Why

Followup software-mansion/react-native-screens#481

# How

Copied my changes I made to `react-native-screens` into our codebase and backported them to SDK37. I also had to force `EXAppViewController`s child to use parent's interface style as well. Previously I though this issue happens only for view controllers that are being presented modally.

# Test Plan

Tested against https://github.com/brentvatne/modal-example
@tsapeta tsapeta deleted the @tsapeta/fix-user-interface-style branch May 7, 2020 13:23
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