SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.3k stars 742 forks source link

overrideUserInterfaceStyle ignored when using SwiftMessages.show(config:, view:) with presentationContext = .window #354

Closed JanBrinker closed 4 years ago

JanBrinker commented 4 years ago

So I guess we're all currently in the phase of stumbling all over weird kinks of iOS 13. The app I'm working on right now is not dark mode ready, so we overrode the user interface style in our app delegate:

if #available(iOS 13.0, *) {
    window?.overrideUserInterfaceStyle = .light
}

This does the trick, however at one place we use SwiftMessages like this:

private func openAmountPicker(withInitialAmount initialAmount: Int) {
    var config = SwiftMessages.Config()
    config.presentationStyle = .bottom
    config.presentationContext = .window(windowLevel: .statusBar) // <-- the important bit
    config.duration = .forever
    config.dimMode = .gray(interactive: true)
    config.interactiveHide = false
    config.preferredStatusBarStyle = .lightContent

    let picker = AmountPicker() // <-- view containing a picker view and a close button
    picker.initialAmount = initialAmount
    picker.delegate = self
    SwiftMessages.show(config: config, view: picker)
}

Now if my phone is set to dark mode iOS will try to use dark mode colors for UI elements inside even though I overrode the user interface style for the window. If I use .view(someView) for presentationContext the label colors in the view are back to what they should be as the someView is inside the window defined in the AppDelegate and that is forced to .light mode.

So I guess that SwiftMessages creates a new window for .window and doesn't copy over the overrideUserInterface value.

Now the question is whether this is a bug or not. Difficult to say, but it definitely is behavior one wouldn't neccessarily expect.

wtmoose commented 4 years ago

Thanks for bringing this up. I need to add something to handle this.

wtmoose commented 4 years ago

I added SwiftMessages.Config.overrideUserInterfaceStyle on the head of master if you want to give it a try.

DhavalBhimani commented 4 years ago

@wtmoose any update on this? i am not able to show dark mode message UI using SwiftMessages.show(config: config, view: messageView). Please let me know.

i am not seeing SwiftMessages.Config.overrideUserInterfaceStyle in library now.

wtmoose commented 4 years ago

The ball is in your court. As I said, the feature is on the head of master. Try entering overrideUserInterfaceStyle in the search box.

DhavalBhimani commented 4 years ago

Thanks, i had to install master branch pod. pod 'SwiftMessages',:git => 'https://github.com/SwiftKickMobile/SwiftMessages.git', :branch => 'master'

wtmoose commented 4 years ago

Included in 8.0.0 release