My app is a bit of a special case and relies on a custom view in a NSStatusItem. I use a NSHostingView and add it as a subview to my NSStatusItem's .button property.
Since macOS 26 Tahoe, even simple animations like a .frame change of a Circle won't animate smoothly even though the same SwiftUI animates normally in a WindowGroup.
class AppDelegate: NSObject, NSApplicationDelegate {
private let statusItem: NSStatusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
func applicationDidFinishLaunching(_ aNotification: Notification) {
let subview = NSHostingView(rootView: AnimationView())
let view = self.statusItem.button
view?.addSubview(subview)
subview.translatesAutoresizingMaskIntoConstraints = false
guard let view = view else { return }
NSLayoutConstraint.activate([
subview.centerXAnchor.constraint(equalTo: view.centerXAnchor),
subview.centerYAnchor.constraint(equalTo: view.centerYAnchor),
subview.widthAnchor.constraint(equalToConstant: 22),
subview.heightAnchor.constraint(equalToConstant: 22)
])
}
}
struct AnimationView: View {
@State private var isTapped = false
@State private var size: CGSize = .init(width: 4, height: 4)
var body: some View {
Circle()
.fill(.pink)
.frame(width: size.width, height: size.height)
.frame(width: 20, height: 20)
// .frame(maxHeight: .infinity)
// .padding(.horizontal, 9)
// .frame(height: 22)
.contentShape(Rectangle())
// .background(Color.blue.opacity(0.5))
.onTapGesture {
withAnimation(.interactiveSpring(response: 0.85, dampingFraction: 0.26, blendDuration: 0.45)) {
// withAnimation(.spring()) {
if isTapped {
size = .init(width: 4, height: 4)
} else {
size = .init(width: 16, height: 16)
}
}
isTapped.toggle()
}}
}
Example project: https://app.box.com/s/q28upunrgkxyyd97ovslgud9yitqaxfk