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

Make screenLayout content alignment configurable #679

Merged
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
8 changes: 6 additions & 2 deletions Sources/Orbit/Support/Layout/ScreenLayoutModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct ScreenLayoutModifier: ViewModifier {

let edges: Edge.Set
let padding: ScreenLayoutPadding
let alignment: HorizontalAlignment
let maxContentWidth: CGFloat

func body(content: Content) -> some View {
Expand All @@ -55,8 +56,8 @@ struct ScreenLayoutModifier: ViewModifier {
.padding(.leading, edges.contains(.leading) ? padding.horizontal(horizontalSizeClass: horizontalSizeClass) : 0)
.padding(.trailing, edges.contains(.trailing) ? padding.horizontal(horizontalSizeClass: horizontalSizeClass) : 0)
.padding(.bottom, edges.contains(.bottom) ? padding.bottom(horizontalSizeClass: horizontalSizeClass) : 0)
// Fill the width using default leading alignment
.frame(maxWidth: maxContentWidth, alignment: .leading)
// Fill the width based on alignment
.frame(maxWidth: maxContentWidth, alignment: .init(horizontal: alignment, vertical: .center))
// Fill the rest of available width, aligning the content to center
.frame(maxWidth: .infinity)
}
Expand All @@ -74,17 +75,20 @@ public extension View {
/// - Parameters:
/// - edges: The set of edges to pad for this view. The default is `Edge.Set.all`.
/// - padding: The padding to apply for specified edges.
/// - alignment: The alignment of the screen content. The default is `.leading`.
/// - maxContentWidth: Maximum width of content, horizontally aligned to center. The default value of this
/// parameter is ``Layout/readableMaxWidth``.
func screenLayout(
_ edges: Edge.Set = .all,
padding: ScreenLayoutPadding = .default,
alignment: HorizontalAlignment = .leading,
maxContentWidth: CGFloat = Layout.readableMaxWidth
) -> some View {
modifier(
ScreenLayoutModifier(
edges: edges,
padding: padding,
alignment: alignment,
maxContentWidth: maxContentWidth
)
)
Expand Down