-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from DatepollSystems/feature/WR-339-table-grou…
…p-filtering WR-339 table group filtering
- Loading branch information
Showing
10 changed files
with
334 additions
and
50 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
WaiterRobot/Resources/Colors.xcassets/second.colorset/Contents.json
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,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "display-p3", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0.967", | ||
"green" : "0.691", | ||
"red" : "0.607" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
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,101 @@ | ||
// | ||
// ButtonStyles.swift | ||
// WaiterRobot | ||
// | ||
// Created by Alexander Kauer on 25.02.24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct WRBorderedProminentButtonStyle: ButtonStyle { | ||
@Environment(\.isEnabled) private var isEnabled: Bool | ||
|
||
func makeBody(configuration: Configuration) -> some View { | ||
configuration.label | ||
.foregroundStyle(isEnabled ? .white : .white.opacity(0.8)) | ||
.background( | ||
RoundedRectangle(cornerRadius: 10) | ||
.ifCondition(isEnabled) { view in | ||
view.foregroundStyle(configuration.isPressed ? .main.opacity(0.6) : .main) | ||
} | ||
.ifCondition(!isEnabled) { view in | ||
view.foregroundStyle(.gray) | ||
} | ||
) | ||
} | ||
} | ||
|
||
extension ButtonStyle where Self == WRBorderedProminentButtonStyle { | ||
static var primary: WRBorderedProminentButtonStyle { | ||
WRBorderedProminentButtonStyle() | ||
} | ||
} | ||
|
||
struct WRSecondaryBorderedProminentButtonStyle: ButtonStyle { | ||
@Environment(\.isEnabled) private var isEnabled: Bool | ||
|
||
func makeBody(configuration: Configuration) -> some View { | ||
configuration.label | ||
.foregroundStyle(isEnabled ? .white : .white.opacity(0.8)) | ||
.background( | ||
RoundedRectangle(cornerRadius: 10) | ||
.ifCondition(isEnabled) { view in | ||
view.foregroundStyle(configuration.isPressed ? .second : .second.opacity(0.8)) | ||
} | ||
.ifCondition(!isEnabled) { view in | ||
view.foregroundStyle(.gray) | ||
} | ||
) | ||
} | ||
} | ||
|
||
extension ButtonStyle where Self == WRSecondaryBorderedProminentButtonStyle { | ||
static var secondary: WRSecondaryBorderedProminentButtonStyle { | ||
WRSecondaryBorderedProminentButtonStyle() | ||
} | ||
} | ||
|
||
struct WRBorderedProminentGreyStyle: ButtonStyle { | ||
@Environment(\.isEnabled) private var isEnabled: Bool | ||
|
||
func makeBody(configuration: Configuration) -> some View { | ||
configuration.label | ||
.background( | ||
RoundedRectangle(cornerRadius: 10) | ||
.ifCondition(isEnabled) { view in | ||
view.foregroundStyle(configuration.isPressed ? .gray.opacity(0.6) : .gray.opacity(0.3)) | ||
} | ||
.ifCondition(!isEnabled) { view in | ||
view.foregroundStyle(.gray) | ||
} | ||
) | ||
} | ||
} | ||
|
||
extension ButtonStyle where Self == WRBorderedProminentGreyStyle { | ||
static var gray: WRBorderedProminentGreyStyle { | ||
WRBorderedProminentGreyStyle() | ||
} | ||
} | ||
|
||
#Preview { | ||
VStack { | ||
Button {} label: { | ||
Text("Test") | ||
.padding() | ||
} | ||
.buttonStyle(.primary) | ||
|
||
Button {} label: { | ||
Text("Test") | ||
.padding() | ||
} | ||
.buttonStyle(.secondary) | ||
|
||
Button {} label: { | ||
Text("Test") | ||
.padding() | ||
} | ||
.buttonStyle(.gray) | ||
} | ||
} |
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,120 @@ | ||
import Foundation | ||
import SwiftUI | ||
|
||
@available(iOS 16, *) | ||
public struct DynamicGrid: Layout, Sendable { | ||
private let horizontalSpacing: CGFloat | ||
private let verticalSpacing: CGFloat | ||
|
||
public init(horizontalSpacing: CGFloat = 0, verticalSpacing: CGFloat = 0) { | ||
self.horizontalSpacing = horizontalSpacing | ||
self.verticalSpacing = verticalSpacing | ||
} | ||
|
||
public func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache _: inout ()) -> CGSize { | ||
let containerWidth = proposal.replacingUnspecifiedDimensions().width | ||
|
||
var x: CGFloat = 0 | ||
var y: CGFloat = 0 | ||
|
||
var maxYinRow: CGFloat? | ||
|
||
for subview in subviews { | ||
let size = subview.sizeThatFits(.unspecified) | ||
if (x + size.width) > containerWidth { | ||
x = 0 | ||
y += maxYinRow ?? size.height | ||
y += verticalSpacing | ||
maxYinRow = 0 | ||
} | ||
|
||
maxYinRow = max(maxYinRow ?? 0, size.height) | ||
x += size.width + horizontalSpacing | ||
} | ||
|
||
y += maxYinRow ?? 0 | ||
|
||
return CGSize(width: containerWidth, height: y) | ||
} | ||
|
||
public func placeSubviews( | ||
in bounds: CGRect, | ||
proposal: ProposedViewSize, | ||
subviews: Subviews, | ||
cache _: inout () | ||
) { | ||
let subviewSizes = subviews.map { proxy in | ||
proxy.sizeThatFits(.unspecified) | ||
} | ||
|
||
var x = bounds.minX | ||
var y: CGFloat = bounds.minY.isNaN ? 0 : bounds.minY | ||
|
||
var maxYinRow: CGFloat? | ||
|
||
for index in subviews.indices { | ||
let subviewSize = subviewSizes[index] | ||
let sizeProposal = ProposedViewSize( | ||
width: subviewSize.width, | ||
height: subviewSize.height | ||
) | ||
|
||
/// check if the next view exceeds the remaining space | ||
if (x + subviewSize.width) > bounds.maxX { | ||
x = bounds.minX | ||
y += maxYinRow ?? subviewSize.height | ||
y += verticalSpacing | ||
maxYinRow = 0 | ||
} | ||
|
||
// print("Will place item \(index) at x:\(x) y:\(y)") | ||
subviews[index] | ||
.place( | ||
at: CGPoint(x: x, y: y), | ||
anchor: .topLeading, | ||
proposal: sizeProposal | ||
) | ||
|
||
maxYinRow = max(maxYinRow ?? 0, subviewSize.height) | ||
x += subviewSize.width + horizontalSpacing | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
if #available(iOS 16, *) { | ||
ScrollView { | ||
VStack { | ||
DynamicGrid(horizontalSpacing: 10, verticalSpacing: 10) { | ||
Rectangle() | ||
.foregroundColor(.brown) | ||
.frame(width: 100, height: 50) | ||
Rectangle() | ||
.foregroundColor(.yellow) | ||
.frame(width: 80, height: 20) | ||
Rectangle() | ||
.foregroundColor(.green) | ||
.frame(width: 100, height: 60) | ||
Rectangle() | ||
.foregroundColor(.brown) | ||
.frame(width: 100, height: 50) | ||
Rectangle() | ||
.foregroundColor(.yellow) | ||
.frame(width: 250, height: 20) | ||
Rectangle() | ||
.foregroundColor(.green) | ||
.frame(width: 100, height: 60) | ||
Rectangle() | ||
.foregroundColor(.blue) | ||
.frame(width: 200, height: 50) | ||
Rectangle() | ||
.foregroundColor(.gray) | ||
.frame(width: 200, height: 110) | ||
} | ||
} | ||
.padding() | ||
} | ||
} else { | ||
EmptyView() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.