Implemented the FullWidthModifier modifier in the UI library, and implemented the "fullWidth(alignment: )" function for its View+Modifiers extension.
This commit is contained in:
parent
b522cebea8
commit
58ac11eaf7
18
Libraries/UI/Kit/Sources/Extensions/View+Modifiers.swift
Normal file
18
Libraries/UI/Kit/Sources/Extensions/View+Modifiers.swift
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// View+Modifiers.swift
|
||||
// ReviewsUIKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 19/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
extension View {
|
||||
|
||||
// MARK: Functions
|
||||
public func fullWidth(alignment: Alignment = .leading) -> some View {
|
||||
modifier(FullWidthModifier(alignment: alignment))
|
||||
}
|
||||
|
||||
}
|
43
Libraries/UI/Kit/Sources/Modifiers/FullWidthModifier.swift
Normal file
43
Libraries/UI/Kit/Sources/Modifiers/FullWidthModifier.swift
Normal file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// FullWidthModifier.swift
|
||||
// ReviewsUIKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 19/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FullWidthModifier: ViewModifier {
|
||||
|
||||
// MARK: Constants
|
||||
private let alignment: Alignment
|
||||
|
||||
// MARK: Initialisers
|
||||
init(alignment: Alignment) {
|
||||
self.alignment = alignment
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.frame(
|
||||
maxWidth: .infinity,
|
||||
alignment: alignment
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
#Preview {
|
||||
Group {
|
||||
Text("Hello, world!")
|
||||
.modifier(FullWidthModifier(alignment: .leading))
|
||||
Text("Hello, world!")
|
||||
.modifier(FullWidthModifier(alignment: .center))
|
||||
Text("Hello, world!")
|
||||
.modifier(FullWidthModifier(alignment: .trailing))
|
||||
}
|
||||
.padding(.horizontal)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user