forked from OneBusAway/onebusaway-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRefreshButton.swift
47 lines (38 loc) · 1.16 KB
/
RefreshButton.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// RefreshButton.swift
// OBAWidget
//
// Created by Manu on 2024-10-18.
//
import SwiftUI
import AppIntents
import WidgetKit
// MARK: - RefreshWidgetIntent
/// this intent serves as a way to refresh the widget and its timelines.
struct RefreshWidgetIntent: AppIntent {
static var title: LocalizedStringResource = "Refresh Widget"
func perform() async throws -> some IntentResult {
WidgetCenter.shared.reloadAllTimelines()
return .result()
}
}
/// A button to manually trigger the widget refresh.
struct RefreshButton: View {
var body: some View {
Button(intent: RefreshWidgetIntent()) {
HStack(spacing: 2){
Image(systemName: "arrow.trianglehead.clockwise")
.imageScale(.small)
.foregroundStyle(.white)
Text("Refresh")
.font(.system(size: 12))
.foregroundColor(.white)
}
.padding(.horizontal,6)
.padding(.vertical, 4)
.background(Color(.brand))
.cornerRadius(8)
}
.buttonStyle(.plain)
}
}