Created
December 28, 2025 23:02
-
-
Save AbodiDawoud/fb74081cafeb3b8d34eff5637a9a4ab9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct NSIntelligenceUIWashAnimationView: NSViewRepresentable { | |
| let startColor: Color | |
| let endColor: Color | |
| var onFinish: () -> Void = {} | |
| func makeAnimationView() -> NSView { | |
| let UIWashAnimationView = NSClassFromString("AppKit._NSIntelligenceUIWashAnimationView") as! NSView.Type | |
| let view = UIWashAnimationView.init(frame: .zero) | |
| let selector = NSSelectorFromString("animateWithStartColor:endColor:completionHandler:") | |
| let method = class_getInstanceMethod(type(of: view), selector) | |
| let implementation = method_getImplementation(method!) | |
| typealias Function = @convention(c) (AnyObject, Selector, Any, Any, Any) -> Void | |
| let function = unsafeBitCast(implementation, to: Function.self) | |
| let completionBlock: @convention(block) () -> Void = { | |
| onFinish() | |
| } | |
| function(view, selector, NSColor(startColor), NSColor(endColor), completionBlock) | |
| return view | |
| } | |
| func makeNSView(context: Context) -> some NSView { | |
| return makeAnimationView() | |
| } | |
| func updateNSView(_ nsViewController: NSViewType, context: Context) {} | |
| } | |
| // MARK: - DemoView. | |
| struct NSIntelligenceUIWashAnimationDemoView: View { | |
| @State private var isAnimating: Bool = false | |
| var body: some View { | |
| Button { | |
| self.isAnimating = true | |
| } label: { | |
| ZStack { | |
| if isAnimating { | |
| NSIntelligenceUIWashAnimationView(startColor: .indigo, endColor: .black) { | |
| self.isAnimating = false | |
| } | |
| .frame(width: 100, height: 40) | |
| .clipShape(RoundedRectangle(cornerRadius: 10)) | |
| } | |
| Text("Animate") | |
| .font(.callout.weight(.semibold)) | |
| .foregroundStyle(isAnimating ? Color.primary : Color.gray) | |
| } | |
| .frame(width: 100, height: 40) | |
| .overlay { | |
| RoundedRectangle(cornerRadius: 10) | |
| .stroke(.quaternary, lineWidth: 1) | |
| } | |
| } | |
| .animation(.smooth, value: isAnimating) | |
| .buttonStyle(.plain) | |
| .onHover { | |
| $0 ? NSCursor.pointingHand.set() : NSCursor.pop() | |
| } | |
| } | |
| } | |
| // MARK: - Helpers. | |
| struct VisualEffectBlur: NSViewRepresentable { | |
| var material: NSVisualEffectView.Material | |
| var blendingMode: NSVisualEffectView.BlendingMode | |
| func makeNSView(context: Context) -> NSVisualEffectView { | |
| let view = NSVisualEffectView() | |
| view.material = material | |
| view.blendingMode = blendingMode | |
| view.state = .active | |
| return view | |
| } | |
| func updateNSView(_ nsView: NSVisualEffectView, context: Context) { | |
| nsView.material = material | |
| nsView.blendingMode = blendingMode | |
| } | |
| } | |
| @main | |
| struct DemoApp: App { | |
| var body: some Scene { | |
| WindowGroup { | |
| ZStack { | |
| VisualEffectBlur(material: .hudWindow, blendingMode: .behindWindow) | |
| .ignoresSafeArea() | |
| NSIntelligenceUIWashAnimationDemoView() | |
| } | |
| .frame(width: 275, height: 130, alignment: .center) | |
| } | |
| .windowResizability(.contentSize) | |
| .windowStyle(.hiddenTitleBar) | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screen.Recording.2025-12-28.at.11.58.32.PM.mov