@@ -6,28 +6,11 @@ extension View {
6
6
self . onReceive ( NotificationCenter . default. publisher ( for: name) , perform: action)
7
7
}
8
8
9
- public func onRotate( perform action: @escaping ( UIDeviceOrientation ) -> Void ) -> some View {
10
- self . modifier ( DeviceRotationViewModifier ( action: action) )
11
- }
12
-
13
- public func containerBackgroundForWidget< Background> ( background: @escaping ( ) -> Background ) -> some View where Background: View {
9
+ public func containerBackgroundForWidget< Background> ( @ViewBuilder background: @escaping ( ) -> Background ) -> some View where Background: View {
14
10
modifier ( ContainerBackgroundForWidgetModifier ( background: background) )
15
11
}
16
12
}
17
13
18
- struct DeviceRotationViewModifier : ViewModifier {
19
-
20
- let action : ( UIDeviceOrientation ) -> Void
21
-
22
- func body( content: Content ) -> some View {
23
- content
24
- . onAppear ( )
25
- . onReceive ( NotificationCenter . default. publisher ( for: UIDevice . orientationDidChangeNotification) ) { _ in
26
- action ( UIDevice . current. orientation)
27
- }
28
- }
29
- }
30
-
31
14
struct ContainerBackgroundForWidgetModifier < Background> : ViewModifier where Background: View {
32
15
33
16
let background : ( ) -> Background
@@ -47,3 +30,27 @@ struct ContainerBackgroundForWidgetModifier<Background>: ViewModifier where Back
47
30
}
48
31
}
49
32
}
33
+
34
+ // MARK: - Only iOS
35
+
36
+ #if os(iOS)
37
+ extension View {
38
+
39
+ public func onRotate( perform action: @escaping ( UIDeviceOrientation ) -> Void ) -> some View {
40
+ self . modifier ( DeviceRotationViewModifier ( action: action) )
41
+ }
42
+ }
43
+
44
+ struct DeviceRotationViewModifier : ViewModifier {
45
+
46
+ let action : ( UIDeviceOrientation ) -> Void
47
+
48
+ func body( content: Content ) -> some View {
49
+ content
50
+ . onAppear ( )
51
+ . onReceive ( NotificationCenter . default. publisher ( for: UIDevice . orientationDidChangeNotification) ) { _ in
52
+ action ( UIDevice . current. orientation)
53
+ }
54
+ }
55
+ }
56
+ #endif
0 commit comments