fix: RCTAlertController's UserInterfaceStyle to follow root window#34218
fix: RCTAlertController's UserInterfaceStyle to follow root window#34218vonovak wants to merge 2 commits intofacebook:mainfrom
Conversation
Base commit: 7909b91 |
Base commit: e6ef083 |
cipolleschi
left a comment
There was a problem hiding this comment.
Thanks for opening this PR. 👏 👏
I left a feedback and a question!
There was a problem hiding this comment.
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.
@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.
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.
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.
cipolleschi
left a comment
There was a problem hiding this comment.
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 (
overrideUserInterfaceStylebeing 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" theuserInterfaceStyleof 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.overrideUserInterfaceStylewill beUIUserInterfaceStyleUnspecified, and it'll have no effect.screenshot