File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Sources/SwiftUIExtension/Extensions Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ import SwiftUI
2
+
3
+ extension View {
4
+
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)
7
+ }
8
+
9
+ public func onRotate( perform action: @escaping ( UIDeviceOrientation ) -> Void ) -> some View {
10
+ self . modifier ( DeviceRotationViewModifier ( action: action) )
11
+ }
12
+ }
13
+
14
+ struct DeviceRotationViewModifier : ViewModifier {
15
+
16
+ let action : ( UIDeviceOrientation ) -> Void
17
+
18
+ func body( content: Content ) -> some View {
19
+ content
20
+ . onAppear ( )
21
+ . onReceive ( NotificationCenter . default. publisher ( for: UIDevice . orientationDidChangeNotification) ) { _ in
22
+ action ( UIDevice . current. orientation)
23
+ }
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments