-
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.
- Loading branch information
Showing
6 changed files
with
284 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// IfCondition.swift | ||
// WaiterRobot | ||
// | ||
// Created by Alexander Kauer on 25.02.24. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
extension View { | ||
/// Applies the given transform if the given condition evaluates to `true`. | ||
/// - Parameters: | ||
/// - condition: The condition to evaluate. | ||
/// - transform: The transform to apply to the source `View`. | ||
/// - Returns: Either the original `View` or the modified `View` if the condition is `true`. | ||
@ViewBuilder func ifCondition(_ condition: Bool, transform: (Self) -> some View) -> some View { | ||
if condition { | ||
transform(self) | ||
} else { | ||
self | ||
} | ||
} | ||
} |
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,32 @@ | ||
// | ||
// WRBorderedProminentButtonStyle.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 wrBorderedProminent: WRBorderedProminentButtonStyle { | ||
WRBorderedProminentButtonStyle() | ||
} | ||
} |
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,62 @@ | ||
// | ||
// WrToolbar.swift | ||
// WaiterRobot | ||
// | ||
// Created by Alexander Kauer on 25.02.24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension View { | ||
func wrBottomBar<ToolbarView: View>(@ViewBuilder toolbar: @escaping () -> ToolbarView) -> some View { | ||
modifier(WrToolbarModifier<ToolbarView>(toolbar: toolbar)) | ||
} | ||
} | ||
|
||
struct WrToolbarModifier<ToolbarView: View>: ViewModifier { | ||
@ViewBuilder | ||
let toolbar: ToolbarView | ||
|
||
func body(content: Content) -> some View { | ||
VStack(spacing: 0) { | ||
content | ||
|
||
VStack { | ||
Divider() | ||
|
||
HStack { | ||
toolbar | ||
} | ||
.frame(maxWidth: .infinity) | ||
.padding(.horizontal) | ||
.padding(.top, 4) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
Text("hello") | ||
.wrBottomBar { | ||
Button {} label: { | ||
Image(systemName: "creditcard") | ||
.padding(12) | ||
} | ||
.buttonStyle(.wrBorderedProminent) | ||
|
||
Button {} label: { | ||
Image(systemName: "plus") | ||
.imageScale(.large) | ||
.padding() | ||
} | ||
.buttonStyle(.wrBorderedProminent) | ||
|
||
Button {} label: { | ||
Image(systemName: "plus") | ||
.imageScale(.large) | ||
.padding() | ||
} | ||
.buttonStyle(.wrBorderedProminent) | ||
.disabled(true) | ||
} | ||
} |
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.