Skip to content

Instantly share code, notes, and snippets.

@1998code
Created July 29, 2022 05:43
Show Gist options
  • Save 1998code/fea1227e866bc8c9a82ed1dc9654cdc3 to your computer and use it in GitHub Desktop.
Save 1998code/fea1227e866bc8c9a82ed1dc9654cdc3 to your computer and use it in GitHub Desktop.
Pizza Widget Sample
import ActivityKit
import WidgetKit
import SwiftUI
@main
struct Widgets: WidgetBundle {
var body: some Widget {
PizzaDeliveryActivityWidget()
}
}
struct PizzaDeliveryActivityWidget: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(attributesType: PizzaDeliveryAttributes.self) { context in
VStack(alignment: .leading) {
HStack {
VStack(alignment: .leading) {
Text("\(context.state.driverName) is on the way!").font(.headline)
HStack {
VStack {
Divider().frame(height: 6).overlay(.blue).cornerRadius(5)
}
Image(systemName: "box.truck.badge.clock.fill").foregroundColor(.blue)
VStack {
RoundedRectangle(cornerRadius: 5)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [5]))
.frame(height: 6)
}
Text(context.state.estimatedDeliveryTime, style: .timer)
VStack {
RoundedRectangle(cornerRadius: 5)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [5]))
.frame(height: 6)
}
Image(systemName: "house.fill").foregroundColor(.green)
}
}.padding(.trailing, 25)
Text("\(context.attributes.numberOfPizzas) 🍕").font(.title).bold()
}.padding(5)
Text("You've already paid: \(context.attributes.totalAmount) + $9.9 Delivery Fee 💸").font(.caption).foregroundColor(.secondary)
}.padding(15)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment