Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for IDV #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import ActivityKit
import WidgetKit
import SwiftUI
import OneSignalLiveActivities

struct LiveActivityAttributes: ActivityAttributes {
struct FIFALiveActivityAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable {
// Dynamic stateful properties about your activity go here!
var homeScore: Int
var awayScore: Int

}

// Fixed non-changing properties about your activity go here!
Expand All @@ -23,12 +23,11 @@ struct LiveActivityAttributes: ActivityAttributes {
var awayTeam: String
var fifaLogo: String
var sponsorLogo: String

}

struct LiveActivityLiveActivity: Widget {
struct FIFALiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: LiveActivityAttributes.self) { context in
ActivityConfiguration(for: FIFALiveActivityAttributes.self) { context in
// Lock screen/banner UI goes here
ZStack {
VStack {
Expand Down Expand Up @@ -158,22 +157,22 @@ extension Color {
}
}

extension LiveActivityAttributes {
fileprivate static var preview: LiveActivityAttributes {
LiveActivityAttributes(name: "Switzerland vs. Germany", homeTeam: "Switzerland", awayTeam: "Germany", fifaLogo: "fifa_logo", sponsorLogo: "cocacola_logo")
extension FIFALiveActivityAttributes {
fileprivate static var preview: FIFALiveActivityAttributes {
FIFALiveActivityAttributes(name: "Switzerland vs. Germany", homeTeam: "Switzerland", awayTeam: "Germany", fifaLogo: "fifa_logo", sponsorLogo: "cocacola_logo")
}
}

extension LiveActivityAttributes.ContentState {
fileprivate static var smiley: LiveActivityAttributes.ContentState {
LiveActivityAttributes.ContentState(homeScore: 6, awayScore: 1)
extension FIFALiveActivityAttributes.ContentState {
fileprivate static var smiley: FIFALiveActivityAttributes.ContentState {
FIFALiveActivityAttributes.ContentState(homeScore: 6, awayScore: 1)
}

}

#Preview("Expanded Dynamic Island", as: ActivityPreviewViewKind.dynamicIsland(.expanded) , using: LiveActivityAttributes.preview) {
LiveActivityLiveActivity()
#Preview("Expanded Dynamic Island", as: ActivityPreviewViewKind.dynamicIsland(.expanded) , using: FIFALiveActivityAttributes.preview) {
FIFALiveActivity()
} contentStates: {
LiveActivityAttributes.ContentState.smiley
FIFALiveActivityAttributes.ContentState.smiley

}
4 changes: 3 additions & 1 deletion LiveActivity/LiveActivityBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import SwiftUI

@main
struct LiveActivityBundle: WidgetBundle {

var body: some Widget {
LiveActivityLiveActivity()
FIFALiveActivity()
SimpleLiveActivity()
}
}
71 changes: 71 additions & 0 deletions LiveActivity/SimpleLiveActivity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// LiveActivityLiveActivity.swift
// LiveActivity
//
// Created by William Shepherd on 1/22/24.
//

import ActivityKit
import WidgetKit
import SwiftUI
import OneSignalLiveActivities

struct SimpleLiveActivityAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable {
// Dynamic stateful properties about your activity go here!
// Update using the API by setting the `event_updates` parameter
var message: String
}

// Fixed non-changing properties about your activity go here!
var name: String
}

struct SimpleLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: FIFALiveActivityAttributes.self) { context in
// Lock screen/banner UI goes here
} dynamicIsland: { context in
DynamicIsland {
DynamicIslandExpandedRegion(.leading) {
Text("Leading")
}
DynamicIslandExpandedRegion(.trailing) {
Text("Trailing")
}
DynamicIslandExpandedRegion(.center) {
Text("C")
}
} compactLeading: {
Text("L")
} compactTrailing: {
Text("T")
} minimal: {
Text("M")
}
.widgetURL(URL(string: "http://www.onesignal.com"))
.keylineTint(Color.red)


}
}
}

extension SimpleLiveActivityAttributes {
fileprivate static var preview: SimpleLiveActivityAttributes {
SimpleLiveActivityAttributes(name: "Joe")
}
}

extension SimpleLiveActivityAttributes.ContentState {
fileprivate static var smiley: SimpleLiveActivityAttributes.ContentState {
SimpleLiveActivityAttributes.ContentState(message: "👋🏽")
}

}

#Preview("Expanded Dynamic Island", as: ActivityPreviewViewKind.dynamicIsland(.expanded) , using: SimpleLiveActivityAttributes.preview) {
SimpleLiveActivity()
} contentStates: {
SimpleLiveActivityAttributes.ContentState.smiley
}
Loading