-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 [JIRA: 0] list picker item styles issue (#802)
Co-authored-by: Bill Zhou <bill.zhou01@sap.com> Co-authored-by: xiaoqinggrace <52239714+xiaoqinggrace@users.noreply.github.com>
- Loading branch information
1 parent
5841ca1
commit e2e3579
Showing
8 changed files
with
125 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import SwiftUI | ||
|
||
// This VStack will ignore subviews which width or height is 0, so no extra space will be added. | ||
struct CompactVStack: Layout { | ||
var alignment: HorizontalAlignment | ||
var spacing: CGFloat | ||
|
||
init(alignment: HorizontalAlignment = .center, spacing: CGFloat = 8) { | ||
self.alignment = alignment | ||
self.spacing = spacing | ||
} | ||
|
||
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { | ||
guard let containerWidth = proposal.width else { return } | ||
var currentY: CGFloat = bounds.minY | ||
for subview in subviews { | ||
let size = subview.sizeThatFits(ProposedViewSize(width: containerWidth, height: nil)) | ||
let xPosition: CGFloat | ||
switch self.alignment { | ||
case .leading: | ||
xPosition = bounds.minX | ||
case .trailing: | ||
xPosition = bounds.maxX - size.width | ||
default: | ||
xPosition = bounds.midX - size.width / 2 | ||
} | ||
|
||
subview.place(at: CGPoint(x: xPosition, y: currentY), proposal: ProposedViewSize(width: containerWidth, height: size.height)) | ||
currentY += size.height + self.spacing | ||
} | ||
} | ||
|
||
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { | ||
guard let containerWidth = proposal.width else { return .zero } | ||
var totalHeight: CGFloat = 0 | ||
var maxWidth: CGFloat = 0 | ||
|
||
for subview in subviews { | ||
let size = subview.sizeThatFits(ProposedViewSize(width: containerWidth, height: nil)) | ||
if size.width > 0, size.height > 0 { | ||
totalHeight += size.height | ||
maxWidth = max(maxWidth, size.width) | ||
totalHeight += self.spacing | ||
} | ||
} | ||
if totalHeight > 0 { | ||
totalHeight -= self.spacing | ||
} | ||
return CGSize(width: maxWidth, height: totalHeight) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ore/_generated/ViewModels/Model+Extensions/ListPickerItemModel+Extensions.generated.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery | ||
// DO NOT EDIT | ||
import SwiftUI | ||
|
||
public extension ListPickerItemModel { | ||
var axis: Axis { | ||
return .horizontal | ||
} | ||
} |