Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace guide properties with superview property #361

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 25 additions & 38 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,9 @@ extension LayoutItem {
set { layoutItemView.accessibilityIdentifier = newValue }
}

private var marginsGuide: UILayoutGuide? {
guard let superview: UIView = layoutItemView.superview
else {
assertionFailure("Missing required superview reference")
return nil
}
return superview.layoutMarginsGuide
}

private var safeAreaGuide: UILayoutGuide? {
guard let superview: UIView = layoutItemView.superview
else {
assertionFailure("Missing required superview reference")
return nil
}
return superview.safeAreaLayoutGuide
private var superview: UIView? {
assert(layoutItemView.superview != nil, "`layoutItemView` must have a `superview`")
return layoutItemView.superview
}

// MARK: - Identifier
Expand Down Expand Up @@ -343,7 +330,7 @@ extension LayoutItem {
and trailing: NSLayoutXAxisAnchor
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview: UIView = layoutItem.layoutItemView.superview {
if let superview: UIView = layoutItem.superview {
let guide: UILayoutGuide = {
let guide: UILayoutGuide = .init()
superview.addLayoutGuide(guide)
Expand Down Expand Up @@ -399,7 +386,7 @@ extension LayoutItem {
and bottom: NSLayoutYAxisAnchor
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview: UIView = layoutItem.layoutItemView.superview {
if let superview: UIView = layoutItem.superview {
let guide: UILayoutGuide = {
let guide: UILayoutGuide = .init()
superview.addLayoutGuide(guide)
Expand Down Expand Up @@ -486,7 +473,7 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview: UIView = layoutItem.layoutItemView.superview {
if let superview: UIView = layoutItem.superview {
for edge: DirectionalEdge in insets.edgeType.allCases {
layoutItem.constraint(to: edge, of: superview, insets: insets, priority: priority)
}
Expand All @@ -507,7 +494,7 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview: UIView = layoutItem.layoutItemView.superview {
if let superview: UIView = layoutItem.superview {
for edge: CanonicalEdge in insets.edgeType.allCases {
layoutItem.constraint(to: edge, of: superview, insets: insets, priority: priority)
}
Expand All @@ -530,7 +517,7 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview: UIView = layoutItem.layoutItemView.superview {
if let superview: UIView = layoutItem.superview {
for edge: DirectionalEdge in edges {
layoutItem.constraint(to: edge, of: superview, inset: inset, priority: priority)
}
Expand All @@ -553,7 +540,7 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview: UIView = layoutItem.layoutItemView.superview {
if let superview: UIView = layoutItem.superview {
for edge: CanonicalEdge in edges {
layoutItem.constraint(to: edge, of: superview, inset: inset, priority: priority)
}
Expand Down Expand Up @@ -593,9 +580,9 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let layoutGuide: UILayoutGuide = layoutItem.marginsGuide {
if let margins: UILayoutGuide = layoutItem.superview?.margins {
for edge: DirectionalEdge in insets.edgeType.allCases {
layoutItem.constraint(to: edge, of: layoutGuide, insets: insets, priority: priority)
layoutItem.constraint(to: edge, of: margins, insets: insets, priority: priority)
}
}
}
Expand All @@ -614,9 +601,9 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let layoutGuide: UILayoutGuide = layoutItem.marginsGuide {
if let margins: UILayoutGuide = layoutItem.superview?.margins {
for edge: CanonicalEdge in insets.edgeType.allCases {
layoutItem.constraint(to: edge, of: layoutGuide, insets: insets, priority: priority)
layoutItem.constraint(to: edge, of: margins, insets: insets, priority: priority)
}
}
}
Expand All @@ -637,9 +624,9 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let layoutGuide: UILayoutGuide = layoutItem.marginsGuide {
if let margins: UILayoutGuide = layoutItem.superview?.margins {
for edge: DirectionalEdge in edges {
layoutItem.constraint(to: edge, of: layoutGuide, inset: inset, priority: priority)
layoutItem.constraint(to: edge, of: margins, inset: inset, priority: priority)
}
}
}
Expand All @@ -660,9 +647,9 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let layoutGuide: UILayoutGuide = layoutItem.marginsGuide {
if let margins: UILayoutGuide = layoutItem.superview?.margins {
for edge: CanonicalEdge in edges {
layoutItem.constraint(to: edge, of: layoutGuide, inset: inset, priority: priority)
layoutItem.constraint(to: edge, of: margins, inset: inset, priority: priority)
}
}
}
Expand Down Expand Up @@ -700,9 +687,9 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let layoutGuide: UILayoutGuide = layoutItem.safeAreaGuide {
if let safeArea: UILayoutGuide = layoutItem.superview?.safeArea {
for edge: DirectionalEdge in insets.edgeType.allCases {
layoutItem.constraint(to: edge, of: layoutGuide, insets: insets, priority: priority)
layoutItem.constraint(to: edge, of: safeArea, insets: insets, priority: priority)
}
}
}
Expand All @@ -721,9 +708,9 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let layoutGuide: UILayoutGuide = layoutItem.safeAreaGuide {
if let safeArea: UILayoutGuide = layoutItem.superview?.safeArea {
for edge: CanonicalEdge in insets.edgeType.allCases {
layoutItem.constraint(to: edge, of: layoutGuide, insets: insets, priority: priority)
layoutItem.constraint(to: edge, of: safeArea, insets: insets, priority: priority)
}
}
}
Expand All @@ -744,9 +731,9 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let layoutGuide: UILayoutGuide = layoutItem.safeAreaGuide {
if let safeArea: UILayoutGuide = layoutItem.superview?.safeArea {
for edge: DirectionalEdge in edges {
layoutItem.constraint(to: edge, of: layoutGuide, inset: inset, priority: priority)
layoutItem.constraint(to: edge, of: safeArea, inset: inset, priority: priority)
}
}
}
Expand All @@ -767,9 +754,9 @@ extension LayoutItem {
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let layoutGuide: UILayoutGuide = layoutItem.safeAreaGuide {
if let safeArea: UILayoutGuide = layoutItem.superview?.safeArea {
for edge: CanonicalEdge in edges {
layoutItem.constraint(to: edge, of: layoutGuide, inset: inset, priority: priority)
layoutItem.constraint(to: edge, of: safeArea, inset: inset, priority: priority)
}
}
}
Expand Down
Loading