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
| ZStack(alignment: .topLeading) { | |
| RoundedRectangle(cornerRadius: 0, style: .continuous) | |
| .fill(Color("widgetBackgroundColor")) | |
| HStack(alignment: .center, spacing: 8) { | |
| RoundedRectangle(cornerRadius: 3, style: .continuous) | |
| .fill(LinearGradient( | |
| gradient: .init(colors: [.blue, .green]), | |
| startPoint: .init(x: 0, y: 0), | |
| endPoint: .init(x: 1, y: 1) |
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
| struct Previews: PreviewProvider { | |
| static var previews: some View { | |
| Group { | |
| MainAccountEntryView(entry: previewEntry) | |
| .previewContext(WidgetPreviewContext(family: .systemSmall)) | |
| PlaceholderView() | |
| .previewContext(WidgetPreviewContext(family: .systemSmall)) | |
| } | |
| } |
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
| struct MainAccountEntryView : View { | |
| var entry: Provider.Entry | |
| var body: some View { | |
| VStack(alignment: .leading, spacing: 2) { | |
| Text(entry.product.name) | |
| Text(entry.product.iban) | |
| Text(entry.product.formattedAmount) | |
| }) | |
| } |
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
| struct PlaceholderView : View { | |
| var body: some View { | |
| Text("Placeholder View") | |
| } | |
| } | |
| struct MainAccountEntryView : View { | |
| var entry: Provider.Entry | |
| var body: some View { |
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
| @main | |
| struct MainAccount: Widget { | |
| private let kind: String = "MainAccount" | |
| public var body: some WidgetConfiguration { | |
| StaticConfiguration(kind: kind, provider: Provider(), placeholder: PlaceholderView()) { entry in | |
| MainAccountEntryView(entry: entry) | |
| } | |
| .configurationDisplayName("Main Account") | |
| .description("See information about your main account.") |
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
| public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) { | |
| let currentDate = Date() | |
| let futureDate = Calendar.current.date(byAdding: .minute, value: 10, to: currentDate)! | |
| viewModel.fetchProducts() { products in | |
| guard let mainProduct = products.first(where: { $0.type == .main }) else { return } | |
| let entry = AccountEntry(date: currentDate, product: mainProduct) | |
| let timeline = Timeline(entries: [entry], policy: .after(refreshDate)) | |
| completion(timeline) |
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
| viewModel.fetchProducts() { products in | |
| guard let mainProduct = products.first(where: { $0.type == .main }) else { return } | |
| let entry = AccountEntry(date: currentDate, product: mainProduct) | |
| let timeline = Timeline(entries: [entry], policy: .after(refreshDate)) | |
| completion(timeline) | |
| } |
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
| let currentDate = Date() | |
| let futureDate = Calendar.current.date(byAdding: .minute, value: 10, to: currentDate)! |
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
| public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) { | |
| var entries: [AccountEntry] = [] | |
| /* ... */ | |
| let timeline = Timeline(entries: entries, policy: .atEnd) | |
| completion(timeline) | |
| } |
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
| public func snapshot(with context: Context, completion: @escaping (AccountEntry) -> ()) { | |
| let previewProduct = Product( | |
| id: "123a67cf", | |
| title: "Main Account", | |
| amount: 280.25, | |
| iban: "NL27AAA0726252510", | |
| type: .main | |
| ) | |
| let entry = AccountEntry(date: Date(), product: previewProduct) | |
| completion(entry) |