Improve animation

This commit is contained in:
Hariharan Mudaliar 2025-12-01 22:08:31 +05:30
commit f782c9d135
2 changed files with 24 additions and 25 deletions

View file

@ -171,24 +171,27 @@ struct ContentView: View {
mainLayout mainLayout
.conditionalModifier(!useModernCloseAnimation) { view in .conditionalModifier(!useModernCloseAnimation) { view in
let hoverAnimationAnimation = Animation.bouncy.speed(1.2) let hoverAnimation = Animation.bouncy.speed(1.2)
let notchStateAnimation = Animation.spring.speed(1.2)
let viewTransitionAnimation = Animation.easeInOut(duration: 0.4)
return view
.animation(hoverAnimationAnimation, value: isHovering)
.animation(notchStateAnimation, value: vm.notchState)
.animation(viewTransitionAnimation, value: coordinator.currentView)
.animation(.smooth, value: gestureProgress)
.transition(.blurReplace.animation(.interactiveSpring(dampingFraction: 1.2)))
}
.conditionalModifier(useModernCloseAnimation) { view in
let hoverAnimationAnimation = Animation.bouncy.speed(1.2)
let notchStateAnimation = Animation.spring.speed(1.2) let notchStateAnimation = Animation.spring.speed(1.2)
let viewTransitionAnimation = Animation.easeInOut(duration: 0.4) let viewTransitionAnimation = Animation.easeInOut(duration: 0.4)
return view return view
.animation(hoverAnimationAnimation, value: isHovering) .animation(hoverAnimation, value: isHovering)
.animation(notchStateAnimation, value: vm.notchState) .animation(notchStateAnimation, value: vm.notchState)
.animation(viewTransitionAnimation, value: coordinator.currentView) .animation(viewTransitionAnimation, value: coordinator.currentView)
.animation(.smooth, value: gestureProgress)
.transition(.blurReplace.animation(.interactiveSpring(dampingFraction: 1.2)))
}
.conditionalModifier(useModernCloseAnimation) { view in
let hoverAnimation = Animation.bouncy.speed(1.2)
let openAnimation = Animation.spring(response: 0.42, dampingFraction: 0.8, blendDuration: 0)
let closeAnimation = Animation.spring(response: 0.45, dampingFraction: 1.0, blendDuration: 0)
let viewTransitionAnimation = Animation.easeInOut(duration: 0.4)
let notchAnimation = vm.notchState == .open ? openAnimation : closeAnimation
return view
.animation(hoverAnimation, value: isHovering)
.animation(notchAnimation, value: vm.notchState)
.animation(viewTransitionAnimation, value: coordinator.currentView)
.animation(.smooth, value: gestureProgress)
} }
.conditionalModifier(interactionsEnabled) { view in .conditionalModifier(interactionsEnabled) { view in
view view

View file

@ -234,13 +234,11 @@ class DynamicIslandViewModel: NSObject, ObservableObject {
DispatchQueue.main.async(execute: applyWindowResize) DispatchQueue.main.async(execute: applyWindowResize)
} }
withAnimation(.bouncy) { notchSize = targetSize
self.notchSize = targetSize notchState = .open
self.notchState = .open
} // Force music information update when notch is opened
MusicManager.shared.forceUpdate()
// Force music information update when notch is opened
MusicManager.shared.forceUpdate()
} }
private func calculateDynamicNotchSize() -> CGSize { private func calculateDynamicNotchSize() -> CGSize {
@ -254,12 +252,10 @@ class DynamicIslandViewModel: NSObject, ObservableObject {
} }
func close() { func close() {
withAnimation(.smooth) { [weak self] in let targetSize = getClosedNotchSize(screen: screen)
guard let self = self else { return } notchSize = targetSize
self.notchSize = getClosedNotchSize(screen: self.screen) closedNotchSize = targetSize
self.closedNotchSize = self.notchSize notchState = .closed
self.notchState = .closed
}
// Set the current view to shelf if it contains files and the user enables openShelfByDefault // Set the current view to shelf if it contains files and the user enables openShelfByDefault
// Otherwise, if the user has not enabled openLastShelfByDefault, set the view to home // Otherwise, if the user has not enabled openLastShelfByDefault, set the view to home