File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
Sources/SwiftUIExtension/Extensions Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ let package = Package(
1616 )
1717 ] ,
1818 dependencies: [
19- . package ( url: " https://github.com/sparrowcode/SwiftBoost " , . upToNextMajor( from: " 4.0.8 " ) ) ,
20- . package ( url: " https://github.com/siteline/swiftui-introspect " , . upToNextMajor( from: " 1.2 .0 " ) )
19+ . package ( url: " https://github.com/sparrowcode/SwiftBoost " , . upToNextMajor( from: " 4.0.9 " ) ) ,
20+ . package ( url: " https://github.com/siteline/swiftui-introspect " , . upToNextMajor( from: " 1.3 .0 " ) )
2121 ] ,
2222 targets: [
2323 . target(
Original file line number Diff line number Diff line change 11import SwiftUI
2+ import Combine
23
34extension View {
45
5- public func onReceive( notification name: Notification . Name , perform action: @escaping ( NotificationCenter . Publisher . Output ) -> Void ) -> some View {
6- self . onReceive ( NotificationCenter . default. publisher ( for: name) , perform: action)
6+ public func onReceive(
7+ _ name: Notification . Name ,
8+ perform action: @escaping ( NotificationCenter . Publisher . Output ) -> Void ) -> some View {
9+ self . onReceive ( NotificationCenter . default. publisher ( for: name) , perform: action)
10+ }
11+
12+ public func onReceive(
13+ _ names: Notification . Name ... ,
14+ center: NotificationCenter = . default,
15+ object: AnyObject ? = nil ,
16+ perform action: @escaping ( Notification ) -> Void
17+ ) -> some View {
18+
19+ let mergedPublisher = names. map { name in
20+ center. publisher ( for: name, object: object)
21+ } . reduce ( Empty < Notification , Never > ( ) . eraseToAnyPublisher ( ) ) { merged, publisher in
22+ merged. merge ( with: publisher) . eraseToAnyPublisher ( )
23+ }
24+
25+ return self . onReceive ( mergedPublisher, perform: action)
726 }
827}
You can’t perform that action at this time.
0 commit comments