Ver código fonte

Animate paywall entry from top of screen.

Present the paywall with a smooth top-down slide and fade each time it opens, including when reopening an existing paywall window.

Made-with: Cursor
huzaifahayat12 1 semana atrás
pai
commit
dc8a1d5abc
1 arquivos alterados com 25 adições e 0 exclusões
  1. 25 0
      meetings_app/ViewController.swift

+ 25 - 0
meetings_app/ViewController.swift

@@ -749,6 +749,7 @@ private extension ViewController {
749
 
749
 
750
     private func showPaywall() {
750
     private func showPaywall() {
751
         if let existing = paywallWindow {
751
         if let existing = paywallWindow {
752
+            animatePaywallPresentation(existing)
752
             existing.makeKeyAndOrderFront(nil)
753
             existing.makeKeyAndOrderFront(nil)
753
             NSApp.activate(ignoringOtherApps: true)
754
             NSApp.activate(ignoringOtherApps: true)
754
             return
755
             return
@@ -777,9 +778,11 @@ private extension ViewController {
777
         panel.standardWindowButton(.zoomButton)?.isHidden = true
778
         panel.standardWindowButton(.zoomButton)?.isHidden = true
778
         panel.center()
779
         panel.center()
779
         panel.contentViewController = controller
780
         panel.contentViewController = controller
781
+        panel.alphaValue = 0
780
         panel.makeKeyAndOrderFront(nil)
782
         panel.makeKeyAndOrderFront(nil)
781
         NSApp.activate(ignoringOtherApps: true)
783
         NSApp.activate(ignoringOtherApps: true)
782
         paywallWindow = panel
784
         paywallWindow = panel
785
+        animatePaywallPresentation(panel)
783
 
786
 
784
         Task { [weak self] in
787
         Task { [weak self] in
785
             guard let self else { return }
788
             guard let self else { return }
@@ -788,6 +791,28 @@ private extension ViewController {
788
         }
791
         }
789
     }
792
     }
790
 
793
 
794
+    private func animatePaywallPresentation(_ window: NSWindow) {
795
+        let finalFrame = window.frame
796
+        let targetScreen = window.screen ?? NSScreen.main
797
+        let startY: CGFloat
798
+        if let screen = targetScreen {
799
+            startY = screen.visibleFrame.maxY + 12
800
+        } else {
801
+            startY = finalFrame.origin.y + 120
802
+        }
803
+        let startFrame = NSRect(x: finalFrame.origin.x, y: startY, width: finalFrame.width, height: finalFrame.height)
804
+
805
+        window.setFrame(startFrame, display: false)
806
+        window.alphaValue = 0
807
+
808
+        NSAnimationContext.runAnimationGroup { context in
809
+            context.duration = 0.28
810
+            context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
811
+            window.animator().alphaValue = 1
812
+            window.animator().setFrame(finalFrame, display: true)
813
+        }
814
+    }
815
+
791
     @objc private func closePaywallClicked(_ sender: Any?) {
816
     @objc private func closePaywallClicked(_ sender: Any?) {
792
         if let win = paywallWindow {
817
         if let win = paywallWindow {
793
             win.performClose(nil)
818
             win.performClose(nil)