Skip to content

Commit 02013c4

Browse files
authored
Merge pull request #58 from RougeWare/feature/56-Compiler-error-SwiftUI-previews_v3
#56: Moved SwiftUI stuff to new file
2 parents f61bbf4 + e577664 commit 02013c4

File tree

2 files changed

+70
-65
lines changed

2 files changed

+70
-65
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// EdgeInsets + FourSided + SwiftUI.swift
3+
//
4+
//
5+
// Created by Ben Leggiero on 2021-05-05.
6+
//
7+
8+
#if canImport(SwiftUI) && !RECTANGLETOOLS_EXCLUDE_SWIFTUI_EDGEINSETS
9+
import SwiftUI
10+
11+
12+
13+
@available(macOS 10.15, *)
14+
@available(iOS 13, *)
15+
@available(tvOS 13, *)
16+
@available(watchOS 6, *)
17+
extension EdgeInsets: FourSidedAbsolute {
18+
public init(top: CGFloat, right: CGFloat, bottom: CGFloat, left: CGFloat) {
19+
switch UserInterfaceLayoutDirection.current {
20+
case .leftToRight:
21+
self.init(top: top, leading: left, bottom: bottom, trailing: right)
22+
23+
case .rightToLeft:
24+
self.init(top: top, leading: right, bottom: bottom, trailing: left)
25+
26+
@unknown default:
27+
assertionFailure("Unknown user interface layout direction (will assume LTR): \(UserInterfaceLayoutDirection.current)")
28+
self.init(top: top, leading: left, bottom: bottom, trailing: right)
29+
}
30+
}
31+
32+
33+
public init(top: CGFloat, trailing: CGFloat, bottom: CGFloat, leading: CGFloat) {
34+
self.init(top: top, leading: leading, bottom: bottom, trailing: trailing)
35+
}
36+
}
37+
38+
39+
40+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
41+
public extension EdgeInsets {
42+
/// The value of whichever edge inset is leading in the current app's UI direction
43+
var right: CGFloat {
44+
switch UserInterfaceLayoutDirection.current {
45+
case .leftToRight: return trailing
46+
case .rightToLeft: return leading
47+
@unknown default:
48+
assertionFailure("Unknown user interface layout direction (will assume LTR): \(UserInterfaceLayoutDirection.current)")
49+
return trailing
50+
}
51+
}
52+
53+
54+
/// The value of whichever edge inset is trailing in the current app's UI direction
55+
var left: CGFloat {
56+
switch UserInterfaceLayoutDirection.current {
57+
case .leftToRight: return leading
58+
case .rightToLeft: return trailing
59+
@unknown default:
60+
assertionFailure("Unknown user interface layout direction (will assume LTR): \(UserInterfaceLayoutDirection.current)")
61+
return leading
62+
}
63+
}
64+
}
65+
#else
66+
67+
public typealias EdgeInsets = NativeEdgeInsets
68+
69+
#endif
70+

Sources/RectangleTools/Default Conformances/EdgeInsets + FourSided.swift

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -85,71 +85,6 @@ extension NSEdgeInsets: Equatable {}
8585

8686

8787

88-
#if canImport(SwiftUI) && !RECTANGLETOOLS_EXCLUDE_SWIFTUI_EDGEINSETS
89-
import SwiftUI
90-
91-
92-
93-
@available(macOS 10.15, *)
94-
@available(iOS 13, *)
95-
@available(tvOS 13, *)
96-
@available(watchOS 6, *)
97-
extension EdgeInsets: FourSidedAbsolute {
98-
public init(top: CGFloat, right: CGFloat, bottom: CGFloat, left: CGFloat) {
99-
switch UserInterfaceLayoutDirection.current {
100-
case .leftToRight:
101-
self.init(top: top, leading: left, bottom: bottom, trailing: right)
102-
103-
case .rightToLeft:
104-
self.init(top: top, leading: right, bottom: bottom, trailing: left)
105-
106-
@unknown default:
107-
assertionFailure("Unknown user interface layout direction (will assume LTR): \(UserInterfaceLayoutDirection.current)")
108-
self.init(top: top, leading: left, bottom: bottom, trailing: right)
109-
}
110-
}
111-
112-
113-
public init(top: CGFloat, trailing: CGFloat, bottom: CGFloat, leading: CGFloat) {
114-
self.init(top: top, leading: leading, bottom: bottom, trailing: trailing)
115-
}
116-
}
117-
118-
119-
120-
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
121-
public extension EdgeInsets {
122-
/// The value of whichever edge inset is leading in the current app's UI direction
123-
var right: CGFloat {
124-
switch UserInterfaceLayoutDirection.current {
125-
case .leftToRight: return trailing
126-
case .rightToLeft: return leading
127-
@unknown default:
128-
assertionFailure("Unknown user interface layout direction (will assume LTR): \(UserInterfaceLayoutDirection.current)")
129-
return trailing
130-
}
131-
}
132-
133-
134-
/// The value of whichever edge inset is trailing in the current app's UI direction
135-
var left: CGFloat {
136-
switch UserInterfaceLayoutDirection.current {
137-
case .leftToRight: return leading
138-
case .rightToLeft: return trailing
139-
@unknown default:
140-
assertionFailure("Unknown user interface layout direction (will assume LTR): \(UserInterfaceLayoutDirection.current)")
141-
return leading
142-
}
143-
}
144-
}
145-
#else
146-
147-
public typealias EdgeInsets = NativeEdgeInsets
148-
149-
#endif
150-
151-
152-
15388
@available(watchOS 2.1, *)
15489
public extension UserInterfaceLayoutDirection {
15590
// TODO: Move this to some other package

0 commit comments

Comments
 (0)