11import SwiftUI
22
3- /// deprecated
4- public struct RelativeLayoutModifier {
5-
6- public enum HorizontalPosition {
7- case leading
8- @available ( * , unavailable)
9- case center
10- case trailing
11- }
12-
13- public enum VerticalPosition {
14- case top
15- @available ( * , unavailable)
16- case center
17- case bottom
18- }
19-
20- }
21-
223extension View {
234
245 /**
25- * Lays out the view and positions it within the layout bounds according to vertical and horizontal positional specifiers.
26- * Can position the child at any of the 4 corners, or the middle of any of the 4 edges, as well as the center - similar to "9-part" image areas.
6+ Using frame modifier inside, let the view place itself relative to the parent view.
277 */
28- @available ( * , deprecated, message: " use relative(alignment: ) " )
29- public func relative(
30- vertical: RelativeLayoutModifier . VerticalPosition ,
31- horizontal: RelativeLayoutModifier . HorizontalPosition
32- ) -> some View {
33-
34- return self . relative ( alignment: . init(
35- horizontal: {
36- switch horizontal {
37- case . center:
38- return . center
39- case . leading:
40- return . leading
41- case . trailing:
42- return . trailing
43- }
44- } ( ) ,
45- vertical: {
46- switch vertical {
47- case . center:
48- return . center
49- case . top:
50- return . top
51- case . bottom:
52- return . bottom
53- }
54- } ( )
55- )
56- )
57- }
58-
59- @available ( * , deprecated, message: " use relative(alignment: ) " )
60- public func relative(
61- horizontal: RelativeLayoutModifier . HorizontalPosition
62- ) -> some View {
63-
64- return self . relative ( horizontalAlignment: {
65- switch horizontal {
66- case . center:
67- return . center
68- case . leading:
69- return . leading
70- case . trailing:
71- return . trailing
72- }
73- } ( )
74- )
75- }
76-
77- @available ( * , deprecated, message: " use relative(alignment: ) " )
78- public func relative(
79- vertical: RelativeLayoutModifier . VerticalPosition
80- ) -> some View {
81-
82- return self . relative ( verticalAlignment: {
83- switch vertical {
84- case . center:
85- return . center
86- case . top:
87- return . top
88- case . bottom:
89- return . bottom
90- }
91- } ( )
92- )
93- }
94-
95- public func relative(
8+ public nonisolated func relative(
969 alignment: Alignment
9710 ) -> some View {
9811 self . frame (
@@ -101,20 +14,29 @@ extension View {
10114 alignment: alignment
10215 )
10316 }
104-
105- public func relative(
17+
18+ /**
19+ Using frame modifier inside, let the view place itself relative to the parent view.
20+ */
21+ public nonisolated func relative(
10622 horizontalAlignment: HorizontalAlignment
10723 ) -> some View {
10824 self . frame ( maxWidth: . infinity, alignment: . init( horizontal: horizontalAlignment, vertical: . center) )
10925 }
110-
111- public func relative(
26+
27+ /**
28+ Using frame modifier inside, let the view place itself relative to the parent view.
29+ */
30+ public nonisolated func relative(
11231 verticalAlignment: VerticalAlignment
11332 ) -> some View {
11433 self . frame ( maxHeight: . infinity, alignment: . init( horizontal: . center, vertical: verticalAlignment) )
11534 }
116-
117- public func relative(
35+
36+ /**
37+ Using frame modifier inside, let the view place itself relative to the parent view.
38+ */
39+ public nonisolated func relative(
11840 horizontalAlignment: HorizontalAlignment ,
11941 verticalAlignment: VerticalAlignment
12042 ) -> some View {
0 commit comments