Last active
October 4, 2022 14:45
-
-
Save SarahAlsharif/c05f72def28dddff8ef2353919fb7d5e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import SwiftUI | |
struct FoodDelivery: View { | |
@State var foodDeliveryStatus : [FoodDeliveryState] = [.orderReceived] | |
@State var currentStatus : FoodDeliveryState = .orderReceived | |
@State var currentColor : Color = .teal | |
@State var accentColor : Color = .teal | |
var body: some View { | |
VStack { | |
MultiStepsView(steps: $foodDeliveryStatus, extraContent: FoodDeliveryState.allValues, extraContentPosition : .inline, extraContentSize: nil, action: {_ in }) { | |
HStack(spacing: 6) { | |
ForEach(0..<4) { _ in | |
Circle() | |
.frame(width: 4) | |
} | |
} | |
.frame(height: 20, alignment: .bottom) | |
.padding(.horizontal, 8) | |
} | |
.accentColor(accentColor) | |
.font(.title) | |
.bold() | |
.padding(4) | |
Spacer() | |
switch currentStatus { | |
case .orderReceived: | |
FoodDeliveryDetailed(icon: currentStatus.rawValue, color: .teal, text: "Order Received") | |
.transition(.push(from: .trailing)) | |
.onAppear() {currentColor = .teal; accentColor = .green} | |
case .preparingOrder: | |
FoodDeliveryDetailed(icon: currentStatus.rawValue, color: .cyan, text: "Preparing Order") | |
.transition(.push(from: .trailing)) | |
.onAppear() {currentColor = .cyan; accentColor = .yellow} | |
case .onItsWay: | |
FoodDeliveryDetailed(icon: currentStatus.rawValue, color: .blue, text: "On its way!") | |
.transition(.push(from: .trailing)) | |
.onAppear() {currentColor = .blue; accentColor = .orange} | |
case .delivered: | |
FoodDeliveryDetailed(icon: currentStatus.rawValue, color: .mint, text: "Delivered") | |
.transition(.push(from: .trailing)) | |
.onAppear() {currentColor = .mint; accentColor = .secondary} | |
} | |
Spacer() | |
} | |
.animation(.linear, value: currentStatus) | |
.onTapGesture { | |
currentStatus = currentStatus.next() | |
foodDeliveryStatus.append(currentStatus) | |
} | |
.onLongPressGesture { | |
foodDeliveryStatus.removeAll() | |
currentStatus = .orderReceived | |
foodDeliveryStatus.append(currentStatus) | |
} | |
.background(currentColor.opacity(1)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment