Skip to content

Commit

Permalink
Patch 2.4.0
Browse files Browse the repository at this point in the history
feat:
- Added an ability to inject EnvironmentObject (#89)
  • Loading branch information
jay-jay-lama authored May 1, 2024
1 parent 828066a commit fea5e68
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MijickPopupView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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.3.1'
s.version = '2.4.0'
s.ios.deployment_target = '14.0'
s.osx.deployment_target = '12.0'
s.swift_version = '5.0'
Expand Down
5 changes: 5 additions & 0 deletions Sources/Internal/Other/AnyPopup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ struct AnyPopup<Config: Configurable>: Popup, Hashable {
self._body = AnyView(popup)
self._configBuilder = popup.configurePopup as! (Config) -> Config
}
init(_ popup: some Popup, _ envObject: some ObservableObject) {
self.id = popup.id
self._body = AnyView(popup.environmentObject(envObject))
self._configBuilder = popup.configurePopup as! (Config) -> Config
}
}
extension AnyPopup {
func createContent() -> some View { _body }
Expand Down
6 changes: 6 additions & 0 deletions Sources/Public/Extensions/Public+Popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public extension Popup {
@discardableResult func hideOverlay() -> some Popup { PopupManager.hideOverlay(self); return self }
}

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

// MARK: - Available Popups
public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig }
public protocol CentrePopup: Popup { associatedtype Config = CentrePopupConfig }
Expand Down

0 comments on commit fea5e68

Please sign in to comment.