react-native-ios-widget 0.0.8 → 0.0.9-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin/build/index.d.ts +2 -2
- package/plugin/build/index.js +5 -5
- package/plugin/build/lib/getWidgetExtensionEntitlements.d.ts +4 -4
- package/plugin/build/lib/getWidgetExtensionEntitlements.js +5 -5
- package/plugin/build/lib/getWidgetFiles.d.ts +1 -2
- package/plugin/build/lib/getWidgetFiles.js +9 -10
- package/plugin/build/types.d.ts +1 -1
- package/plugin/build/withConfig.d.ts +2 -2
- package/plugin/build/withPodfile.d.ts +2 -2
- package/plugin/build/withPodfile.js +14 -14
- package/plugin/build/withWidgetExtensionEntitlements.d.ts +2 -2
- package/plugin/build/withXcode.d.ts +2 -2
- package/plugin/src/index.ts +7 -7
- package/plugin/src/lib/getWidgetExtensionEntitlements.ts +6 -6
- package/plugin/src/lib/getWidgetFiles.ts +8 -8
- package/plugin/src/types.ts +1 -1
- package/plugin/src/withConfig.ts +2 -2
- package/plugin/src/withPodfile.ts +16 -16
- package/plugin/src/withWidgetExtensionEntitlements.ts +2 -2
- package/plugin/src/withXcode.ts +2 -2
- package/_widgets/EmojiRanger/AdventureActivityConfiguration.swift +0 -71
- package/_widgets/EmojiRanger/AllCharactersView.swift +0 -43
- package/_widgets/EmojiRanger/Assets.xcassets/AccentColor.colorset/Contents.json +0 -11
- package/_widgets/EmojiRanger/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -13
- package/_widgets/EmojiRanger/Assets.xcassets/Contents.json +0 -6
- package/_widgets/EmojiRanger/Assets.xcassets/WidgetBackground.colorset/Contents.json +0 -11
- package/_widgets/EmojiRanger/Attributes.swift +0 -21
- package/_widgets/EmojiRanger/EmojiRanger.swift +0 -248
- package/_widgets/EmojiRanger/EmojiRangersWidget.intentdefinition +0 -118
- package/_widgets/EmojiRanger/EmojiRangersWidget.swift +0 -189
- package/_widgets/EmojiRanger/EmojiRangersWidgetBundle.swift +0 -21
- package/_widgets/EmojiRanger/ImageURLProtocol.swift +0 -66
- package/_widgets/EmojiRanger/Info.plist +0 -11
- package/_widgets/EmojiRanger/LeaderboardWidget.swift +0 -93
- package/_widgets/EmojiRanger/Module.swift +0 -94
- package/_widgets/PizzaDelivery/Assets.xcassets/AccentColor.colorset/Contents.json +0 -11
- package/_widgets/PizzaDelivery/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -13
- package/_widgets/PizzaDelivery/Assets.xcassets/Contents.json +0 -6
- package/_widgets/PizzaDelivery/Assets.xcassets/WidgetBackground.colorset/Contents.json +0 -11
- package/_widgets/PizzaDelivery/Attributes.swift +0 -15
- package/_widgets/PizzaDelivery/Info.plist +0 -11
- package/_widgets/PizzaDelivery/LiveActivity.swift +0 -108
- package/_widgets/PizzaDelivery/Module.swift +0 -94
- package/_widgets/PizzaDelivery/WidgetBundle.swift +0 -13
- package/_widgets/PizzaDelivery/Widgets.swift +0 -59
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
See the LICENSE.txt file for this sample’s licensing information.
|
|
3
|
-
|
|
4
|
-
Abstract:
|
|
5
|
-
A widget that shows a leaderboard of all available heroes.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import WidgetKit
|
|
9
|
-
import SwiftUI
|
|
10
|
-
|
|
11
|
-
struct LeaderboardProvider: TimelineProvider {
|
|
12
|
-
|
|
13
|
-
public typealias Entry = LeaderboardEntry
|
|
14
|
-
|
|
15
|
-
func placeholder(in context: Context) -> LeaderboardEntry {
|
|
16
|
-
return LeaderboardEntry(date: Date(), heros: EmojiRanger.availableHeros)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
func getSnapshot(in context: Context, completion: @escaping (LeaderboardEntry) -> Void) {
|
|
20
|
-
let entry = LeaderboardEntry(date: Date(), heros: EmojiRanger.availableHeros)
|
|
21
|
-
completion(entry)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func getTimeline(in context: Context, completion: @escaping (Timeline<LeaderboardEntry>) -> Void) {
|
|
25
|
-
EmojiRanger.loadLeaderboardData { (heros, error) in
|
|
26
|
-
guard let heros = heros else {
|
|
27
|
-
let timeline = Timeline(entries: [LeaderboardEntry(date: Date(), heros: EmojiRanger.availableHeros)], policy: .atEnd)
|
|
28
|
-
|
|
29
|
-
completion(timeline)
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
let timeline = Timeline(entries: [LeaderboardEntry(date: Date(), heros: heros)], policy: .atEnd)
|
|
34
|
-
completion(timeline)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
struct LeaderboardEntry: TimelineEntry {
|
|
40
|
-
public let date: Date
|
|
41
|
-
var heros: [EmojiRanger]?
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
struct LeaderboardPlaceholderView: View {
|
|
45
|
-
var body: some View {
|
|
46
|
-
LeaderboardWidgetEntryView(entry: LeaderboardEntry(date: Date(), heros: nil))
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
struct LeaderboardWidgetEntryView: View {
|
|
51
|
-
var entry: LeaderboardProvider.Entry
|
|
52
|
-
|
|
53
|
-
var body: some View {
|
|
54
|
-
AllCharactersView(heros: entry.heros)
|
|
55
|
-
.padding()
|
|
56
|
-
.widgetBackground()
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
struct LeaderboardWidget: Widget {
|
|
61
|
-
|
|
62
|
-
private static var supportedFamilies: [WidgetFamily] {
|
|
63
|
-
#if os(iOS)
|
|
64
|
-
if #available(iOS 15, *) {
|
|
65
|
-
return [.systemLarge, .systemExtraLarge]
|
|
66
|
-
} else {
|
|
67
|
-
return [.systemLarge]
|
|
68
|
-
}
|
|
69
|
-
#else
|
|
70
|
-
return []
|
|
71
|
-
#endif
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public var body: some WidgetConfiguration {
|
|
75
|
-
StaticConfiguration(kind: EmojiRanger.LeaderboardWidgetKind, provider: LeaderboardProvider()) { entry in
|
|
76
|
-
LeaderboardWidgetEntryView(entry: entry)
|
|
77
|
-
}
|
|
78
|
-
.configurationDisplayName("Ranger Leaderboard")
|
|
79
|
-
.description("See all the rangers.")
|
|
80
|
-
.supportedFamilies(LeaderboardWidget.supportedFamilies)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
struct LeaderboardWidget_Previews: PreviewProvider {
|
|
85
|
-
static var previews: some View {
|
|
86
|
-
Group {
|
|
87
|
-
#if os(iOS)
|
|
88
|
-
LeaderboardWidgetEntryView(entry: LeaderboardEntry(date: Date(), heros: nil))
|
|
89
|
-
.previewContext(WidgetPreviewContext(family: .systemLarge))
|
|
90
|
-
#endif
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import ExpoModulesCore
|
|
2
|
-
import ActivityKit
|
|
3
|
-
|
|
4
|
-
internal class MissingCurrentWindowSceneException: Exception {
|
|
5
|
-
override var reason: String {
|
|
6
|
-
"Cannot determine the current window scene in which to present the modal for requesting a review."
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public class ReactNativeWidgetExtensionModule: Module {
|
|
11
|
-
// Each module class must implement the definition function. The definition consists of components
|
|
12
|
-
// that describes the module's functionality and behavior.
|
|
13
|
-
// See https://docs.expo.dev/modules/module-api for more details about available components.
|
|
14
|
-
public func definition() -> ModuleDefinition {
|
|
15
|
-
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
|
|
16
|
-
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
|
|
17
|
-
// The module will be accessible from `requireNativeModule('ReactNativeAppClip')` in JavaScript.
|
|
18
|
-
Name("ReactNativeWidgetExtension")
|
|
19
|
-
|
|
20
|
-
// Defines event names that the module can send to JavaScript.
|
|
21
|
-
Events("onChange")
|
|
22
|
-
|
|
23
|
-
Function("areActivitiesEnabled") { () -> Bool in
|
|
24
|
-
let logger = Logger()
|
|
25
|
-
logger.info("areActivitiesEnabled()")
|
|
26
|
-
|
|
27
|
-
if #available(iOS 16.2, *) {
|
|
28
|
-
return ActivityAuthorizationInfo().areActivitiesEnabled
|
|
29
|
-
} else {
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Function("startActivity") { (numberOfPizzas: Int, totalAmount: String, orderNumber: String, driverName: String, minutes: Int, seconds: Int) -> Void in
|
|
35
|
-
let logger = Logger()
|
|
36
|
-
logger.info("startActivity()")
|
|
37
|
-
|
|
38
|
-
if #available(iOS 16.2, *) {
|
|
39
|
-
var future = Calendar.current.date(byAdding: .minute, value: (Int(minutes) ?? 0), to: Date())!
|
|
40
|
-
future = Calendar.current.date(byAdding: .second, value: (Int(seconds) ?? 0), to: future)!
|
|
41
|
-
let date = Date.now...future
|
|
42
|
-
let initialContentState = AdventureAttributes.ContentState(driverName: driverName, deliveryTimer: date)
|
|
43
|
-
let activityAttributes = AdventureAttributes(numberOfPizzas: numberOfPizzas, totalAmount: totalAmount, orderNumber: orderNumber)
|
|
44
|
-
|
|
45
|
-
let activityContent = ActivityContent(state: initialContentState, staleDate: Calendar.current.date(byAdding: .minute, value: 30, to: Date())!)
|
|
46
|
-
|
|
47
|
-
do {
|
|
48
|
-
let deliveryActivity = try Activity.request(attributes: activityAttributes, content: activityContent)
|
|
49
|
-
logger.info("Requested a pizza delivery Live Activity \(String(describing: deliveryActivity.id)).")
|
|
50
|
-
} catch (let error) {
|
|
51
|
-
logger.info("Error requesting pizza delivery Live Activity \(error.localizedDescription).")
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Function("updateActivity") { (driverName: String, minutes: Int, seconds: Int) -> Void in
|
|
57
|
-
let logger = Logger()
|
|
58
|
-
logger.info("updateActivity()")
|
|
59
|
-
|
|
60
|
-
if #available(iOS 16.2, *) {
|
|
61
|
-
var future = Calendar.current.date(byAdding: .minute, value: (Int(minutes) ?? 0), to: Date())!
|
|
62
|
-
future = Calendar.current.date(byAdding: .second, value: (Int(seconds) ?? 0), to: future)!
|
|
63
|
-
let date = Date.now...future
|
|
64
|
-
let updatedDeliveryStatus = AdventureAttributes.PizzaDeliveryStatus(driverName: driverName, deliveryTimer: date)
|
|
65
|
-
let alertConfiguration = AlertConfiguration(title: "Delivery update", body: "Your pizza order will arrive soon.", sound: .default)
|
|
66
|
-
let updatedContent = ActivityContent(state: updatedDeliveryStatus, staleDate: nil)
|
|
67
|
-
|
|
68
|
-
Task {
|
|
69
|
-
for activity in Activity<AdventureAttributes>.activities {
|
|
70
|
-
await activity.update(updatedContent, alertConfiguration: alertConfiguration)
|
|
71
|
-
logger.info("Updated the Live Activity: \(activity.id)")
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
Function("endActivity") { (driverName: String) -> Void in
|
|
78
|
-
let logger = Logger()
|
|
79
|
-
logger.info("endActivity()")
|
|
80
|
-
|
|
81
|
-
if #available(iOS 16.2, *) {
|
|
82
|
-
let finalDeliveryStatus = AdventureAttributes.PizzaDeliveryStatus(driverName: driverName, deliveryTimer: Date.now...Date())
|
|
83
|
-
let finalContent = ActivityContent(state: finalDeliveryStatus, staleDate: nil)
|
|
84
|
-
|
|
85
|
-
Task {
|
|
86
|
-
for activity in Activity<AdventureAttributes>.activities {
|
|
87
|
-
await activity.end(finalContent, dismissalPolicy: .default)
|
|
88
|
-
logger.info("Ending the Live Activity: \(activity.id)")
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import ActivityKit
|
|
3
|
-
|
|
4
|
-
struct Attributes: ActivityAttributes {
|
|
5
|
-
public typealias PizzaDeliveryStatus = ContentState
|
|
6
|
-
|
|
7
|
-
public struct ContentState: Codable, Hashable {
|
|
8
|
-
var driverName: String
|
|
9
|
-
var deliveryTimer: ClosedRange<Date>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
var numberOfPizzas: Int
|
|
13
|
-
var totalAmount: String
|
|
14
|
-
var orderNumber: String
|
|
15
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>NSExtension</key>
|
|
6
|
-
<dict>
|
|
7
|
-
<key>NSExtensionPointIdentifier</key>
|
|
8
|
-
<string>com.apple.widgetkit-extension</string>
|
|
9
|
-
</dict>
|
|
10
|
-
</dict>
|
|
11
|
-
</plist>
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import ActivityKit
|
|
2
|
-
import WidgetKit
|
|
3
|
-
import SwiftUI
|
|
4
|
-
|
|
5
|
-
@available(iOS 16.2, *)
|
|
6
|
-
struct PizzaDeliveryLiveActivity: Widget {
|
|
7
|
-
var body: some WidgetConfiguration {
|
|
8
|
-
ActivityConfiguration(for: Attributes.self) { context in
|
|
9
|
-
LockScreenLiveActivityView(context: context)
|
|
10
|
-
} dynamicIsland: { context in
|
|
11
|
-
DynamicIsland {
|
|
12
|
-
DynamicIslandExpandedRegion(.leading) {
|
|
13
|
-
Label("\(context.attributes.numberOfPizzas) Pizzas", systemImage: "bag")
|
|
14
|
-
// .foregroundColor(.indigo)
|
|
15
|
-
.font(.caption)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
DynamicIslandExpandedRegion(.trailing) {
|
|
19
|
-
Label {
|
|
20
|
-
Text(timerInterval: context.state.deliveryTimer, countsDown: true)
|
|
21
|
-
.monospacedDigit()
|
|
22
|
-
.frame(maxWidth: .infinity, alignment: .center)
|
|
23
|
-
} icon: {
|
|
24
|
-
Image(systemName: "timer")
|
|
25
|
-
// .foregroundColor(.red)
|
|
26
|
-
}
|
|
27
|
-
.font(.caption)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
DynamicIslandExpandedRegion(.center) {
|
|
31
|
-
Text("\(context.state.driverName) is on their way!")
|
|
32
|
-
.lineLimit(1)
|
|
33
|
-
.font(.caption)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
DynamicIslandExpandedRegion(.bottom) {
|
|
37
|
-
Button {
|
|
38
|
-
// Deep link into your app.
|
|
39
|
-
} label: {
|
|
40
|
-
Label("Call driver", systemImage: "phone")
|
|
41
|
-
}
|
|
42
|
-
.foregroundColor(.green)
|
|
43
|
-
}
|
|
44
|
-
} compactLeading: {
|
|
45
|
-
Label {
|
|
46
|
-
Text("\(context.attributes.numberOfPizzas) Pizzas")
|
|
47
|
-
} icon: {
|
|
48
|
-
Image(systemName: "bag")
|
|
49
|
-
// .foregroundColor(.indigo)
|
|
50
|
-
}
|
|
51
|
-
// .font(.caption2)
|
|
52
|
-
} compactTrailing: {
|
|
53
|
-
Text(timerInterval: context.state.deliveryTimer, countsDown: true)
|
|
54
|
-
.monospacedDigit()
|
|
55
|
-
// .multilineTextAlignment(.center)
|
|
56
|
-
// .frame(width: 40)
|
|
57
|
-
.font(.caption)
|
|
58
|
-
} minimal: {
|
|
59
|
-
VStack(alignment: .center) {
|
|
60
|
-
Image(systemName: "timer")
|
|
61
|
-
Text(timerInterval: context.state.deliveryTimer, countsDown: true)
|
|
62
|
-
// .multilineTextAlignment(.center)
|
|
63
|
-
.monospacedDigit()
|
|
64
|
-
.font(.caption)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
.keylineTint(.cyan)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@available(iOS 16.2, *)
|
|
73
|
-
struct LockScreenLiveActivityView: View {
|
|
74
|
-
let context: ActivityViewContext<Attributes>
|
|
75
|
-
|
|
76
|
-
var body: some View {
|
|
77
|
-
VStack {
|
|
78
|
-
Spacer()
|
|
79
|
-
Text("\(context.state.driverName) is on their way with your pizza!")
|
|
80
|
-
Spacer()
|
|
81
|
-
HStack {
|
|
82
|
-
Spacer()
|
|
83
|
-
Label {
|
|
84
|
-
Text("\(context.attributes.numberOfPizzas) Pizzas")
|
|
85
|
-
} icon: {
|
|
86
|
-
Image(systemName: "bag")
|
|
87
|
-
.foregroundColor(.indigo)
|
|
88
|
-
}
|
|
89
|
-
.font(.title2)
|
|
90
|
-
Spacer()
|
|
91
|
-
Label {
|
|
92
|
-
Text(timerInterval: context.state.deliveryTimer, countsDown: true)
|
|
93
|
-
.multilineTextAlignment(.center)
|
|
94
|
-
.frame(width: 75)
|
|
95
|
-
.monospacedDigit()
|
|
96
|
-
} icon: {
|
|
97
|
-
Image(systemName: "timer")
|
|
98
|
-
.foregroundColor(.indigo)
|
|
99
|
-
}
|
|
100
|
-
.font(.title2)
|
|
101
|
-
Spacer()
|
|
102
|
-
}
|
|
103
|
-
Spacer()
|
|
104
|
-
}
|
|
105
|
-
.activitySystemActionForegroundColor(.cyan)
|
|
106
|
-
.activityBackgroundTint(.cyan)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import ExpoModulesCore
|
|
2
|
-
import ActivityKit
|
|
3
|
-
|
|
4
|
-
internal class MissingCurrentWindowSceneException: Exception {
|
|
5
|
-
override var reason: String {
|
|
6
|
-
"Cannot determine the current window scene in which to present the modal for requesting a review."
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public class ReactNativeWidgetExtensionModule: Module {
|
|
11
|
-
// Each module class must implement the definition function. The definition consists of components
|
|
12
|
-
// that describes the module's functionality and behavior.
|
|
13
|
-
// See https://docs.expo.dev/modules/module-api for more details about available components.
|
|
14
|
-
public func definition() -> ModuleDefinition {
|
|
15
|
-
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
|
|
16
|
-
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
|
|
17
|
-
// The module will be accessible from `requireNativeModule('ReactNativeAppClip')` in JavaScript.
|
|
18
|
-
Name("ReactNativeWidgetExtension")
|
|
19
|
-
|
|
20
|
-
// Defines event names that the module can send to JavaScript.
|
|
21
|
-
Events("onChange")
|
|
22
|
-
|
|
23
|
-
Function("areActivitiesEnabled") { () -> Bool in
|
|
24
|
-
let logger = Logger()
|
|
25
|
-
logger.info("areActivitiesEnabled()")
|
|
26
|
-
|
|
27
|
-
if #available(iOS 16.2, *) {
|
|
28
|
-
return ActivityAuthorizationInfo().areActivitiesEnabled
|
|
29
|
-
} else {
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Function("startActivity") { (numberOfPizzas: Int, totalAmount: String, orderNumber: String, driverName: String, minutes: Int, seconds: Int) -> Void in
|
|
35
|
-
let logger = Logger()
|
|
36
|
-
logger.info("startActivity()")
|
|
37
|
-
|
|
38
|
-
if #available(iOS 16.2, *) {
|
|
39
|
-
var future = Calendar.current.date(byAdding: .minute, value: (Int(minutes) ?? 0), to: Date())!
|
|
40
|
-
future = Calendar.current.date(byAdding: .second, value: (Int(seconds) ?? 0), to: future)!
|
|
41
|
-
let date = Date.now...future
|
|
42
|
-
let initialContentState = Attributes.ContentState(driverName: driverName, deliveryTimer: date)
|
|
43
|
-
let activityAttributes = Attributes(numberOfPizzas: numberOfPizzas, totalAmount: totalAmount, orderNumber: orderNumber)
|
|
44
|
-
|
|
45
|
-
let activityContent = ActivityContent(state: initialContentState, staleDate: Calendar.current.date(byAdding: .minute, value: 30, to: Date())!)
|
|
46
|
-
|
|
47
|
-
do {
|
|
48
|
-
let deliveryActivity = try Activity.request(attributes: activityAttributes, content: activityContent)
|
|
49
|
-
logger.info("Requested a pizza delivery Live Activity \(String(describing: deliveryActivity.id)).")
|
|
50
|
-
} catch (let error) {
|
|
51
|
-
logger.info("Error requesting pizza delivery Live Activity \(error.localizedDescription).")
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Function("updateActivity") { (driverName: String, minutes: Int, seconds: Int) -> Void in
|
|
57
|
-
let logger = Logger()
|
|
58
|
-
logger.info("updateActivity()")
|
|
59
|
-
|
|
60
|
-
if #available(iOS 16.2, *) {
|
|
61
|
-
var future = Calendar.current.date(byAdding: .minute, value: (Int(minutes) ?? 0), to: Date())!
|
|
62
|
-
future = Calendar.current.date(byAdding: .second, value: (Int(seconds) ?? 0), to: future)!
|
|
63
|
-
let date = Date.now...future
|
|
64
|
-
let updatedDeliveryStatus = Attributes.PizzaDeliveryStatus(driverName: driverName, deliveryTimer: date)
|
|
65
|
-
let alertConfiguration = AlertConfiguration(title: "Delivery update", body: "Your pizza order will arrive soon.", sound: .default)
|
|
66
|
-
let updatedContent = ActivityContent(state: updatedDeliveryStatus, staleDate: nil)
|
|
67
|
-
|
|
68
|
-
Task {
|
|
69
|
-
for activity in Activity<Attributes>.activities {
|
|
70
|
-
await activity.update(updatedContent, alertConfiguration: alertConfiguration)
|
|
71
|
-
logger.info("Updated the Live Activity: \(activity.id)")
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
Function("endActivity") { (driverName: String) -> Void in
|
|
78
|
-
let logger = Logger()
|
|
79
|
-
logger.info("endActivity()")
|
|
80
|
-
|
|
81
|
-
if #available(iOS 16.2, *) {
|
|
82
|
-
let finalDeliveryStatus = Attributes.PizzaDeliveryStatus(driverName: driverName, deliveryTimer: Date.now...Date())
|
|
83
|
-
let finalContent = ActivityContent(state: finalDeliveryStatus, staleDate: nil)
|
|
84
|
-
|
|
85
|
-
Task {
|
|
86
|
-
for activity in Activity<Attributes>.activities {
|
|
87
|
-
await activity.end(finalContent, dismissalPolicy: .default)
|
|
88
|
-
logger.info("Ending the Live Activity: \(activity.id)")
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import WidgetKit
|
|
2
|
-
import SwiftUI
|
|
3
|
-
|
|
4
|
-
struct Provider: TimelineProvider {
|
|
5
|
-
func placeholder(in context: Context) -> SimpleEntry {
|
|
6
|
-
SimpleEntry(date: Date())
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
|
|
10
|
-
let entry = SimpleEntry(date: Date())
|
|
11
|
-
completion(entry)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
|
|
15
|
-
var entries: [SimpleEntry] = []
|
|
16
|
-
|
|
17
|
-
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
|
|
18
|
-
let currentDate = Date()
|
|
19
|
-
for hourOffset in 0 ..< 5 {
|
|
20
|
-
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
|
|
21
|
-
let entry = SimpleEntry(date: entryDate)
|
|
22
|
-
entries.append(entry)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let timeline = Timeline(entries: entries, policy: .atEnd)
|
|
26
|
-
completion(timeline)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
struct SimpleEntry: TimelineEntry {
|
|
31
|
-
let date: Date
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
struct PizzaDeliveryWidgetsEntryView : View {
|
|
35
|
-
var entry: Provider.Entry
|
|
36
|
-
|
|
37
|
-
var body: some View {
|
|
38
|
-
Text(entry.date, style: .time)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
struct PizzaDeliveryWidgets: Widget {
|
|
43
|
-
let kind: String = "PizzaDeliveryWidgets"
|
|
44
|
-
|
|
45
|
-
var body: some WidgetConfiguration {
|
|
46
|
-
StaticConfiguration(kind: kind, provider: Provider()) { entry in
|
|
47
|
-
PizzaDeliveryWidgetsEntryView(entry: entry)
|
|
48
|
-
}
|
|
49
|
-
.configurationDisplayName("My Widget")
|
|
50
|
-
.description("This is an example widget.")
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
struct PizzaDeliveryWidgets_Previews: PreviewProvider {
|
|
55
|
-
static var previews: some View {
|
|
56
|
-
PizzaDeliveryWidgetsEntryView(entry: SimpleEntry(date: Date()))
|
|
57
|
-
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
|
58
|
-
}
|
|
59
|
-
}
|