-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add ColorScheme
environment
#136
Conversation
} | ||
|
||
struct ColorSchemeKey: EnvironmentKey { | ||
static let defaultValue: ColorScheme = .light |
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.
Would it be possible for this to match the value of the (prefers-color-scheme: dark)
media query? You could create the query with window.matchMedia('(prefers-color-scheme: dark)')
and add an event listener to update this value on change.
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.
Yes, that's what I'm working right now. I think it would make sense to add the listener in an onAppear
closure on the new DOMEnvironment
view introduced in this PR, but this obviously needs a working onAppear
implementation first, which is what I'm working on right now 🙂
This is required to unblock #136 as I think it would make sense for the `DOMEnvironment` view there to add/remove its color scheme listener in `onAppear`/`onDisappear` closures. I've also restored full SwiftUI compatibility in the signature of `func modifier<Modifier>(_ modifier: Modifier)`. Consequently `ViewDeferredToRenderer` had to be implemented on `ModifiedContent` then instead of `_ViewModifier_Content` to make it work.
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.
Nice to see it automatically pick up the scheme 🔥
Yes, the listener works, but environment changes aren't propagated properly yet, I'm looking into that now. |
Is this unblocked since #170 ? |
# Conflicts: # Sources/TokamakDOM/DOMRenderer.swift # Sources/TokamakDOM/Modifiers/Effects/DOMEnvironment.swift # Sources/TokamakDOM/Tokens/Tokens.swift # Sources/TokamakDemo/EnvironmentDemo.swift
I'm still seeing some issues with environment propagation (at least in this PR), working on that right now... |
# Conflicts: # Sources/TokamakCore/MountedViews/MountedCompositeView.swift # Sources/TokamakCore/MountedViews/MountedHostView.swift # Sources/TokamakCore/MountedViews/MountedView.swift # Sources/TokamakCore/StackReconciler.swift # Sources/TokamakDOM/DOMRenderer.swift # Sources/TokamakDemo/TokamakDemo.swift
# Conflicts: # Sources/TokamakDOM/DOMRenderer.swift
# Conflicts: # Sources/TokamakDOM/DOMRenderer.swift
The last known environment update issue is fixed and it's ready for review. You can see the dark scheme environment text representation updated in |
I gave it a test and it seems like clicking the dark mode toggle in Safari Developer Tools does not work unless you click it before the first render — subsequent changes are not reflected in the view. |
I was testing with the globally set dark mode in System Preferences, do you see the same behavior with that one? |
Yes, I see the same behavior there |
Hm, I had this same issue caused by the environment bug, which was fixed in c397eb6. Maybe you're not on the latest commit of this branch? |
It's working for me in Chrome. Maybe a bug in Safari? |
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.
Weird, works fine now ¯\_(ツ)_/¯
Sources/TokamakStaticHTML/Core.swift
Outdated
@@ -55,6 +76,8 @@ public typealias CGSize = TokamakCore.CGSize | |||
|
|||
// MARK: Views | |||
|
|||
public typealias Button = TokamakCore.Button |
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.
I intentionally left out things like Button
and TextField
as they're pretty much useless without State
. Do you think we should include them?
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.
What we can add which will make TokamakStaticHTML more useful is Link
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.
I wonder if we could still render stateful View
s to static HTML, any listeners on those would be just ignored. But that would obviously come as a separate PR. LMK if you think that these should be removed in this PR.
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.
I think they should be removed, plus they only have HTML bodies in TokamakDOM.
Was temporarily blocked by #135.