From f782c9d13565a6bbe811924fc0d736f5a5f6fc08 Mon Sep 17 00:00:00 2001 From: Hariharan Mudaliar Date: Mon, 1 Dec 2025 22:08:31 +0530 Subject: [PATCH] Improve animation --- DynamicIsland/ContentView.swift | 29 ++++++++++--------- .../models/DynamicIslandViewModel.swift | 22 ++++++-------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/DynamicIsland/ContentView.swift b/DynamicIsland/ContentView.swift index e070a19..a700f27 100644 --- a/DynamicIsland/ContentView.swift +++ b/DynamicIsland/ContentView.swift @@ -171,24 +171,27 @@ struct ContentView: View { mainLayout .conditionalModifier(!useModernCloseAnimation) { view in - let hoverAnimationAnimation = 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 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(hoverAnimation, 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 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 view diff --git a/DynamicIsland/models/DynamicIslandViewModel.swift b/DynamicIsland/models/DynamicIslandViewModel.swift index b52cae1..a63464a 100644 --- a/DynamicIsland/models/DynamicIslandViewModel.swift +++ b/DynamicIsland/models/DynamicIslandViewModel.swift @@ -234,13 +234,11 @@ class DynamicIslandViewModel: NSObject, ObservableObject { DispatchQueue.main.async(execute: applyWindowResize) } - withAnimation(.bouncy) { - self.notchSize = targetSize - self.notchState = .open - } - - // Force music information update when notch is opened - MusicManager.shared.forceUpdate() + notchSize = targetSize + notchState = .open + + // Force music information update when notch is opened + MusicManager.shared.forceUpdate() } private func calculateDynamicNotchSize() -> CGSize { @@ -254,12 +252,10 @@ class DynamicIslandViewModel: NSObject, ObservableObject { } func close() { - withAnimation(.smooth) { [weak self] in - guard let self = self else { return } - self.notchSize = getClosedNotchSize(screen: self.screen) - self.closedNotchSize = self.notchSize - self.notchState = .closed - } + let targetSize = getClosedNotchSize(screen: screen) + notchSize = targetSize + closedNotchSize = targetSize + notchState = .closed // 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