Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] MacOS Xamarin Forms does not support dark mode #8864

Closed
steven-pearson opened this issue Dec 12, 2019 · 3 comments · Fixed by #10646
Closed

[Bug] MacOS Xamarin Forms does not support dark mode #8864

steven-pearson opened this issue Dec 12, 2019 · 3 comments · Fixed by #10646
Labels
a/darkmode e/7 🕖 7 in-progress This issue has an associated pull request that may resolve it! p/macOS t/bug 🐛
Milestone

Comments

@steven-pearson
Copy link

Description

Out of box XF does not support Dark Mode

Steps to Reproduce

  1. Create a Cross platform app iOS+Android
  2. Add a macOS Project
  3. Amend Mac project to use Xamarin Forms (see below)
  4. Run app

Steps to convert to XF

Change AppDelegate to ...

public class AppDelegate : FormsApplicationDelegate
{
    NSWindow _window;

    public override NSWindow MainWindow
    {
        get { return _window; }
    }


    public AppDelegate()
    {
        var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;

        var rect = new CoreGraphics.CGRect(200, 200, 800, 600);
        _window = new NSWindow(rect, style, NSBackingStore.Buffered, false);
        _window.TitleVisibility = NSWindowTitleVisibility.Hidden;
        _window.Title = "No Dark Mode";
    }

    public override void DidFinishLaunching(NSNotification notification)
    {
        Forms.Init();
        LoadApplication(new App());
        base.DidFinishLaunching(notification);
    }

Change MainClass to
static void Main(string[] args)
{
NSApplication.Init();
NSApplication.SharedApplication.Delegate = new AppDelegate();
NSApplication.Main(args);
}

Remove story board reference from info.plist

Expected Behavior

Window should be in dark mode

Actual Behavior

Window is not in dark mode, always in light mode.

Basic Information

Run the macOS app before converting to XF and confirm that the Window shows in dark mode.

  • Version with issue: latest
  • Last known good version: none
  • IDE: VS4Mac
  • Platform Target Frameworks:
    • macOS: Catalina
  • Nuget Packages: XF 4.4
  • Affected Devices:

Screenshots

Reproduction Link

@steven-pearson steven-pearson added s/unverified New report that has yet to be verified t/bug 🐛 labels Dec 12, 2019
@pauldipietro pauldipietro added this to New in Triage Dec 12, 2019
@VladislavAntonyuk
Copy link
Contributor

You have to manually implement this logic. To enable dark theme add this code

NSApplication.SharedApplication.SetAppearance(NSAppearance.GetAppearance(NSAppearance.NameDarkAqua));

@steven-pearson
Copy link
Author

Thanks for the info. For anyone wanting to implement the location of the change is important, must happen after Init of XF i.e.

    public override void DidFinishLaunching(NSNotification notification)
    {
        Forms.Init();

        // Set after XF is initialised
       NSApplication.SharedApplication.SetAppearance(NSAppearance.GetAppearance(NSAppearance.NameDarkAqua));

        LoadApplication(new App());

        // Insert code here to initialize your application
        base.DidFinishLaunching(notification);
    }

@kingces95 kingces95 moved this from New to Ready For Work in Triage Dec 13, 2019
@samhouts samhouts moved this from Ready For Work to Needs Estimate in Triage Dec 15, 2019
@samhouts samhouts added a/darkmode e/7 🕖 7 and removed s/unverified New report that has yet to be verified labels Jan 3, 2020
@samhouts samhouts moved this from Needs Estimate to Ready For Work in Triage Jan 3, 2020
@samhouts samhouts added this to To do in Other Ready For Work Jan 3, 2020
@samhouts samhouts removed this from Ready For Work in Triage Jan 3, 2020
@samhouts samhouts added this to To do in DarkMode/AppThemes Apr 10, 2020
@jfversluis
Copy link
Member

I have taken a quick look at this. I got the theme detection working and our own AppTheme concept pretty easily. We also have to remove hard-coded colors. The weird thing is though that some elements do update during runtime and other don't and I can't really put my finger on the why.

I'll revisit later, just putting this here in case anyone might have an idea :)

@samhouts samhouts added the in-progress This issue has an associated pull request that may resolve it! label May 28, 2020
@samhouts samhouts moved this from To do to In progress in Other Ready For Work May 28, 2020
@samhouts samhouts moved this from To do to In progress in DarkMode/AppThemes May 28, 2020
@samhouts samhouts added this to In Progress in .NET MAUI Backlog Jul 30, 2020
@samhouts samhouts removed this from In Progress in .NET MAUI Backlog Aug 4, 2020
@samhouts samhouts added this to In Progress in vNext+1 (5.0.0) Aug 11, 2020
@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts moved this from In Progress to Done in vNext+1 (5.0.0) Aug 17, 2020
myroot pushed a commit to myroot/Xamarin.Forms that referenced this issue Aug 19, 2020
* Getting there

* Some hardcoded color removal

* Fix cell issues

* Update PageRenderer.cs

fixes xamarin#8864
fixes xamarin#3777
sung-su pushed a commit to sung-su/Xamarin.Forms that referenced this issue Aug 20, 2020
* Getting there

* Some hardcoded color removal

* Fix cell issues

* Update PageRenderer.cs

fixes xamarin#8864
fixes xamarin#3777
sung-su pushed a commit to sung-su/Xamarin.Forms that referenced this issue Aug 20, 2020
* Getting there

* Some hardcoded color removal

* Fix cell issues

* Update PageRenderer.cs

fixes xamarin#8864
fixes xamarin#3777
Other Ready For Work automation moved this from In progress to Done Aug 21, 2020
DarkMode/AppThemes automation moved this from In progress to Done Aug 21, 2020
@samhouts samhouts removed this from Done in Other Ready For Work Nov 3, 2020
@samhouts samhouts removed this from Done in DarkMode/AppThemes Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/darkmode e/7 🕖 7 in-progress This issue has an associated pull request that may resolve it! p/macOS t/bug 🐛
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

6 participants