SwiftDown icon indicating copy to clipboard operation
SwiftDown copied to clipboard

Support the changing of theme dynamically

Open garrettmurray opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. Currently, SwiftDownEditor stores the theme internally, and therefore the theme is not able to be changed from the outside. For modern apps which support light and dark mode, this means any SwiftDownEditors in use will always be stuck with the theme they were created with, which leads to a poor user experience.

Describe the solution you'd like Ideally, setting the theme would redraw the SwiftDownEditor, such that you could base the current theme on the environment's color scheme to automatically support light/dark modes. This would also allow for a user to change themes while utilizing the editor, with, say, a drop-down of available themes.

Describe alternatives you've considered Without this, the SwiftDownEditor would need to effectively be removed from the hierarchy, and recreated, which doesn't feel very SwiftUI-like.

Additional context A quick example of what I expected to do for supporting system-wide dark/light mode:

@Environment(\.colorScheme) var colorScheme

SwiftDownEditor(text: $itemText)
  .insetsSize(20)
  .theme(colorScheme == .dark ? Theme.BuiltIn.defaultDark.theme() : Theme.BuiltIn.defaultLight.theme())
  .debounceTime(0.5)

garrettmurray avatar Feb 18 '24 22:02 garrettmurray

👋 Thanks for the request, I agree that this should be dynamic as every other element in SwiftUI, I don't think this is a big deal though, it should be feasible by making the theme a @State variable or something like this

qeude avatar Feb 19 '24 08:02 qeude