Skip to content

Commit

Permalink
Patch 2.6.0
Browse files Browse the repository at this point in the history
feat:
- Added onDismiss modifier
  • Loading branch information
FulcrumOne authored Aug 4, 2024
1 parent 56c06db commit 70af749
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions MijickPopupView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Pod::Spec.new do |s|
PopupView is a free and open-source library dedicated for SwiftUI that makes the process of presenting popups easier and much cleaner.
DESC

s.version = '2.5.1'
s.version = '2.6.0'
s.ios.deployment_target = '14.0'
s.osx.deployment_target = '12.0'
s.osx.deployment_target = '13.0'
s.swift_version = '5.0'

s.source_files = 'Sources/**/*'
Expand Down
13 changes: 12 additions & 1 deletion Sources/Internal/Managers/PopupManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@
import SwiftUI

public class PopupManager: ObservableObject {
@Published private(set) var views: [any Popup] = []
@Published private(set) var views: [any Popup] = [] { willSet { onViewsChanged(newValue) }}
private(set) var presenting: Bool = true
private(set) var popupsWithoutOverlay: [ID] = []
private(set) var popupsToBeDismissed: [ID: DispatchSourceTimer] = [:]
private(set) var popupActionsOnDismiss: [ID: () -> ()] = [:]

static let shared: PopupManager = .init()
private init() {}
}
private extension PopupManager {
func onViewsChanged(_ newViews: [any Popup]) { newViews
.difference(from: views, by: { $0.id == $1.id })
.forEach { switch $0 {
case .remove(_, let element, _): popupActionsOnDismiss[element.id]?(); popupActionsOnDismiss.removeValue(forKey: element.id)
default: return
}}
}
}

// MARK: - Operations
enum StackOperation {
Expand All @@ -33,6 +43,7 @@ extension PopupManager {
}}
static func dismissPopupAfter(_ popup: any Popup, _ seconds: Double) { shared.popupsToBeDismissed[popup.id] = DispatchSource.createAction(deadline: seconds) { performOperation(.remove(popup.id)) } }
static func hideOverlay(_ popup: any Popup) { shared.popupsWithoutOverlay.append(popup.id) }
static func onPopupDismiss(_ popup: any Popup, _ action: @escaping () -> ()) { shared.popupActionsOnDismiss[popup.id] = action }
}
private extension PopupManager {
static func removePopupFromStackToBeDismissed(_ operation: StackOperation) { switch operation {
Expand Down
5 changes: 4 additions & 1 deletion Sources/Public/Extensions/Public+Popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ public extension Popup {
/// Hides the overlay for the selected popup
@discardableResult func hideOverlay() -> some Popup { PopupManager.hideOverlay(self); return self }

/// Supplies an observable object to a view’s hierarchy.
/// Supplies an observable object to a view’s hierarchy
@discardableResult func environmentObject<T: ObservableObject>(_ object: T) -> any Popup { AnyPopup<Config>(self, object) }

/// Action to be executed after popups is dismissed
@discardableResult func onDismiss(_ action: @escaping () -> ()) -> any Popup { PopupManager.onPopupDismiss(self, action); return self }
}

// MARK: - Available Popups
Expand Down

0 comments on commit 70af749

Please sign in to comment.