costachung/neumorphic

New color extension in v2.0.0 doesn't support NSColor

TheMisfit68 opened this issue · 12 comments

the newly added Color-extension drops support for NSColor

Thanks for checking. We should use Color instead of UIColor in the new color extension so it will work on both MacOS and iOS.

That would make it pure SwiftUI again, but we would need to inject the ColorScheme again I think

I am discussing this with dkk here.
#12

I think we can use take a different approach for macOS to detect the dark mode.
I have updated the code in master.

I made a new release so that you can test it.
https://github.com/costachung/neumorphic/releases/tag/v2.0.1

I'm having some refresh problems on my Mac App.
The fillcolor of the buttons doesn't change immediately when I switch modes (results are the same switching in system prefs or using Xcode debugger).
When I change tabs in my window (hiding the button) and then switch back (showing it again) the fillcolor is the correct once again.

Schermafbeelding 2021-02-14 om 11 11 15

Have you tried to add this line in your View.

@Environment(.colorScheme) var colorScheme: ColorScheme

In the Mac example project, the view refreshes when you change the mode in system preferences.

Yes but only in the main Contentview (right?).
My view is a composition of smaller views (that are implemented as extensions of their superview).

Yes but only in the main Contentview (right?).

My view is a composition of smaller views (that are implemented as extensions of their superview).

Looks like we are unable to detect the change of mode in the current implementation.

For example, When you call Color.Neumorphic.main, it returns the color based on the color scheme. So there are no problems on creation.

When the mode is changed in the system preferences, the system will update the environment variable of color scheme. If you use the environment variable ColorScheme in your view, the system will redraw your View. Otherwise it will not redraw the View.

Unless Neumorphic knows the change and it is being observed by your View, your view needs to tell Neumorphic the color scheme is updated.

On MacOS, I think you can try to solve this problem by adding this @Environment(.colorScheme) var colorScheme: ColorScheme in your view for now until a better solution comes out.

I have release a new version which fully supports Auto Color Scheme on iOS and MacOS Now.

Using DynamicProvider to init Color on both iOS and MacOS. It works without having to include environment variable colorScheme in the SwiftUI View. It will redraw the view automatically when the system appearance changes.

You can still change the color scheme type manually by setting Color.Neumorphic.colorSchemeType.
e.g. Color.Neumorphic.colorSchemeType = .dark

https://github.com/costachung/neumorphic/releases/tag/v2.0.3

Works like a charm again

Great! Thank you so much!