sindresorhus / Settings

⚙ Add a settings window to your macOS app in minutes
MIT License
1.43k stars 100 forks source link

Animate Window Size based on content change #89

Open davidwernhart opened 1 year ago

davidwernhart commented 1 year ago

Is there a possibility to animate the change in window size, when the size of the content changes? Specifically, it would be useful in SwiftUI.

Thank you and kind regards, David

DivineDominion commented 1 year ago

@davidwernhart The latest release (v2.6.0) animates transitions when you pass animated: true to the PreferencesWindowController initializer. (Which is the default value.) The Example app in the repo also works for the current main here.

I haven't tried to host SwiftUI views inside, though. Could be the content size isn't available at the correct time?

If you could whip up a 4th pane for the Example app that uses SwiftUI and open a PR, that'd be super helpful 🙏


Edit: I just noticed that Settings.Pane is using a SwiftUI NSHostingController already for macOS 10.15, and that's being used in the example app already.

davidwernhart commented 1 year ago

@DivineDominion Hey, thank you for your response! :)

I have looked at the example app and it seems like the "accounts" pane is already implemented in SwiftUI. I have added another demo setting that expands/collapses another section in the same pane. Even though the window does animate when switching panes, it does not when the content size changes. I have created a pull request: https://github.com/sindresorhus/Preferences/pull/91

Again, thank you for your help and kind regards