-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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: RCTAlertController's UserInterfaceStyle to follow root window #34218
Conversation
Base commit: 7909b91 |
Base commit: e6ef083 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR. 👏 👏
I left a feedback and a question!
@@ -29,6 +29,9 @@ - (UIWindow *)alertWindow | |||
|
|||
- (void)show:(BOOL)animated completion:(void (^)(void))completion | |||
{ | |||
if (@available(iOS 13.0, *)) { | |||
self.overrideUserInterfaceStyle = UIApplication.sharedApplication.delegate.window.overrideUserInterfaceStyle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of UIApplication.sharedApplication
, can yo use initWithFrame:RCTSharedApplication()
?
The UIApplication is not always available (in extensions, for example).
What happens if UIApplication.sharedApplication.delegate.window.overrideUserInterfaceStyle;
returns nil
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cipolleschi I have refactored the code to use RCTSharedApplication()
What happens if ...overrideUserInterfaceStyle; returns nil?
I don't believe that should be happening; it'd rather be UIUserInterfaceStyleUnspecified
. But to be on the safe side of things, I made the assignment default to UIUserInterfaceStyleUnspecified
in case RCTSharedApplication()
were to return nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, if any part of the chain is nil
, it can happen due to opional chaining - this is in Swift, but it works in the same way for Objective-C.
If RCTSharedApplication
return null
, the final object returned will be null
, for example. In Objective-C, you can call any method on a null
instance and get a null
in return! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, if any part of the chain is nil, it can happen
yes, I'm aware of that 🙂 and it's why I made the assignment default to UIUserInterfaceStyleUnspecified
.
maybe I don't understand extensions enough, I just thought this code wouldn't be called in an extension, but I can be wrong 😄
there is also this part which I thought would handle the nil case more explicitly if there was a risk of having nil
RCTSharedApplication()
. Is that part okay from that point of view? Thanks.
_alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes!
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Hi! There are some failure in the CI, but I think they will go away after a rebase. Could you please try @vonovak? 🙏 |
9f079d4
to
cbf71fb
Compare
done. the failures I see seem unrelated... |
Hi @vonovak, sorry to ask this, but could you rebase it again.. 😅 |
cbf71fb
to
793a5a8
Compare
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @vonovak in 18542b6. When will my fix make it into a release? | Upcoming Releases |
Summary
The motivation of this PR is for the Alert to follow the same style override (
overrideUserInterfaceStyle
being light/dark) as the one used by the root window (UIApplication.sharedApplication.delegate.window
).This is something that has worked previously because
RCTPResentedViewController()
was used to present the Alert (the behavior has changed in vonovak@f319ff3). With the former approach, the alert would "inherit" theuserInterfaceStyle
of the view controller it was presented within (and that one, in turn, would "inherit" fromUIApplication.sharedApplication.delegate.window
).With the current approach, the "style inheritance" does not work with the view controller being created here.
Because this viewcontroller instance does not have where to "inherit" the styling from, the styling might be different from the rest of the app. This PR fixes that.
Changelog
[iOS] [Fixed] - fix: RCTAlertController's UserInterfaceStyle to follow root window
Test Plan
Instead of
you can do
and observe the result. So if the override is set, it'll manifest itself. If it's not set, the value of
UIApplication.sharedApplication.delegate.window.overrideUserInterfaceStyle
will beUIUserInterfaceStyleUnspecified
, and it'll have no effect.screenshot