Skip to content

Commit

Permalink
Merge pull request #36 from DatepollSystems/feature/WR-339-table-grou…
Browse files Browse the repository at this point in the history
…p-filtering

WR-339 table group filtering
  • Loading branch information
kaulex99 committed May 12, 2024
2 parents 7c38665 + b856805 commit 69dc502
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 50 deletions.
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
}
}
101 changes: 101 additions & 0 deletions WaiterRobot/Ui/Core/ButtonStyles.swift
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)
}
}
120 changes: 120 additions & 0 deletions WaiterRobot/Ui/Core/DynamicGrid.swift
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()
}
}
32 changes: 0 additions & 32 deletions WaiterRobot/Ui/Core/WRBorderedProminentButtonStyle.swift

This file was deleted.

6 changes: 3 additions & 3 deletions WaiterRobot/Ui/Core/WrToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ struct WrToolbarModifier<ToolbarView: View>: ViewModifier {
Image(systemName: "creditcard")
.padding(12)
}
.buttonStyle(.wrBorderedProminent)
.buttonStyle(.primary)

Button {} label: {
Image(systemName: "plus")
.imageScale(.large)
.padding()
}
.buttonStyle(.wrBorderedProminent)
.buttonStyle(.primary)

Button {} label: {
Image(systemName: "plus")
.imageScale(.large)
.padding()
}
.buttonStyle(.wrBorderedProminent)
.buttonStyle(.primary)
.disabled(true)
}
}
2 changes: 1 addition & 1 deletion WaiterRobot/Ui/Order/OrderListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct OrderListItem: View {
Image(systemName: "pencil")
.padding(10)
}
.buttonStyle(.wrBorderedProminent)
.buttonStyle(.primary)
}
.padding(.vertical, 2)
.frame(maxHeight: .infinity, alignment: .center)
Expand Down
6 changes: 3 additions & 3 deletions WaiterRobot/Ui/Order/OrderScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct OrderScreen: View {
showProductSearch = initialItemId == nil ? true : false

UIToolbar.appearance().barTintColor = UIColor.systemBackground // Background color
UIToolbar.appearance().tintColor = UIColor.blue // Tint color of buttonss
UIToolbar.appearance().tintColor = UIColor.blue // Tint color of buttons
}

var body: some View {
Expand Down Expand Up @@ -98,7 +98,7 @@ struct OrderScreen: View {
.imageScale(.small)
.padding(10)
}
.buttonStyle(.wrBorderedProminent)
.buttonStyle(.primary)
.disabled(currentOrder.isEmpty)

Spacer()
Expand All @@ -110,7 +110,7 @@ struct OrderScreen: View {
.imageScale(.large)
.padding()
}
.buttonStyle(.wrBorderedProminent)
.buttonStyle(.primary)
}
.customBackNavigation(title: localize.dialog.cancel(), icon: "chevron.backward") {
if currentOrder.isEmpty {
Expand Down
4 changes: 2 additions & 2 deletions WaiterRobot/Ui/TableDetail/TableDetailScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct TableDetailScreen: View {
Image(systemName: "creditcard")
.padding(10)
}
.buttonStyle(.wrBorderedProminent)
.buttonStyle(.primary)
.disabled(orderedItems.isEmpty)

Spacer()
Expand All @@ -86,7 +86,7 @@ struct TableDetailScreen: View {
.imageScale(.large)
.padding()
}
.buttonStyle(.wrBorderedProminent)
.buttonStyle(.primary)
}
}

Expand Down
Loading

0 comments on commit 69dc502

Please sign in to comment.