sindresorhus / Settings

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

Incorrect animation for first transition to preference pane with different width #60

Closed JosephDuffy closed 1 year ago

JosephDuffy commented 4 years ago

When animating to a preference pane that has not been loaded before and has a larger width than the current pane the view is not correctly laid out initially, which causes an odd animation. The animation is correct in subsequent switches.

The example below is the example app with the width = 450 constraint removed from the Advanced tab, and the app set to open to the Advanced tab.

Screen Recording 2020-08-23 at 19 39 33 2020-08-23 19_49_52

I'm trying to figure out the exact scenarios that causes this. Starting on Accounts does not cause this same animation to happen so I'm not sure how the size change and animations are linked.

mohakapt commented 3 years ago

I'm having exactly the same issue here. Only with me it's happening with different heights.

mohakapt commented 3 years ago

I was able to make it a little bit less annoying by adding a fade animation when moving between panes.

It doesn't completely fix the issue you can still notice the jump if you're looking for it, but this anmiation made the jump somewhat less obvious.

  override func viewWillAppear() {
    super.viewWillAppear()
    self.view.subviews.first?.alphaValue = 0
    DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(300)) {
      self.view.subviews.first?.animator().alphaValue = 1
    }
  }

  override func viewWillDisappear() {
    super.viewWillDisappear()
    self.view.subviews.first?.animator().alphaValue = 0
  }
hisaac commented 3 years ago

Just want to echo that I'm also having this issue as of 2021-02-17. This is also the same as #59.

gaozhanting commented 3 years ago

I think you can make a workaround:

func fixFirstTimeLanuchOddAnimationByImplicitlyShowIt() {
     preferencesWindowController.show(preferencePane: .general)
     preferencesWindowController.show(preferencePane: .advanced)
     preferencesWindowController.show(preferencePane: .accounts)
     preferencesWindowController.close()
}

then call it in applicationDidFinishLaunching

hisaac commented 3 years ago

@gaozhanting Nice, this works! Any idea why it works?

gaozhanting commented 3 years ago

Because the odd animation only happens the first time you opened the tab which you integrate it with SwiftUI view. With this way, it already done immediately after app lanuched, only that user can't see it again afterward.