Skip to content

Commit

Permalink
🚧 Add minimal POC of working sample
Browse files Browse the repository at this point in the history
  • Loading branch information
istornz committed Nov 15, 2022
1 parent a830583 commit 0e90a96
Show file tree
Hide file tree
Showing 19 changed files with 839 additions and 47 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
// Pointez pour afficher la description des attributs existants.
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart",
},
]
}
22 changes: 22 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PODS:
- Flutter (1.0.0)
- live_activities (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- live_activities (from `.symlinks/plugins/live_activities/ios`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
live_activities:
:path: ".symlinks/plugins/live_activities/ios"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
live_activities: 9ff56a06a2d43ecd68f56deeed13b18a8304789c

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3

COCOAPODS: 1.11.3
307 changes: 306 additions & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions example/ios/Runner.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
Expand All @@ -24,6 +26,10 @@
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSSupportsLiveActivities</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -43,9 +49,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
8 changes: 8 additions & 0 deletions example/ios/Runner/Runner.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions example/ios/extension-example/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions example/ios/extension-example/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
<key>NSSupportsLiveActivities</key>
<true/>
</dict>
</plist>
59 changes: 59 additions & 0 deletions example/ios/extension-example/extension_example.intentdefinition
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>INEnums</key>
<array/>
<key>INIntentDefinitionModelVersion</key>
<string>1.2</string>
<key>INIntentDefinitionNamespace</key>
<string>88xZPY</string>
<key>INIntentDefinitionSystemVersion</key>
<string>20A294</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>12A6144</string>
<key>INIntentDefinitionToolsVersion</key>
<string>12.0</string>
<key>INIntents</key>
<array>
<dict>
<key>INIntentCategory</key>
<string>information</string>
<key>INIntentDescriptionID</key>
<string>tVvJ9c</string>
<key>INIntentEligibleForWidgets</key>
<true/>
<key>INIntentIneligibleForSuggestions</key>
<true/>
<key>INIntentName</key>
<string>Configuration</string>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Configuration</string>
<key>INIntentTitleID</key>
<string>gpCwrM</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>View</string>
</dict>
</array>
<key>INTypes</key>
<array/>
</dict>
</plist>
164 changes: 164 additions & 0 deletions example/ios/extension-example/extension_example.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//
// extension_example.swift
// extension-example
//
// Created by Dimitri Dessus on 28/09/2022.
//

import ActivityKit
import WidgetKit
import SwiftUI

@main
struct Widgets: WidgetBundle {
var body: some Widget {
if #available(iOS 16.1, *) {
GroceryDeliveryApp()
}
}
}

class PizzaData {
var name: String
var description: String
var quantity: Int
var price: Double
var deliverName: String
var deliverStartDate: Date
var deliverEndDate: Date
var deliverDate: ClosedRange<Date>

init?(JSONData data:[String: String]) {
self.name = data["name"]!
self.description = data["description"]!
self.quantity = Int(data["quantity"]!)!
self.price = Double(data["price"]!)!
self.deliverName = data["deliverName"]!
self.deliverStartDate = Date(timeIntervalSince1970: Double(data["deliverStartDate"]!)!)
self.deliverEndDate = Date(timeIntervalSince1970: Double(data["deliverEndDate"]!)!)

deliverDate = self.deliverStartDate...self.deliverEndDate
}
}

struct LiveActivitiesAppAttributes: ActivityAttributes, Identifiable {
public typealias LiveDeliveryData = ContentState

public struct ContentState: Codable, Hashable {
var data: Dictionary<String, String>
}

var id = UUID()
}

@available(iOSApplicationExtension 16.1, *)
struct GroceryDeliveryApp: Widget {

var body: some WidgetConfiguration {
ActivityConfiguration(for: LiveActivitiesAppAttributes.self) { context in
let pizza = PizzaData(JSONData: context.state.data)
VStack(alignment: .leading) {
HStack {
VStack(alignment: .leading) {
Text("Your \(pizza!.name) is on the way!")
.font(.headline)
ZStack {
RoundedRectangle(cornerRadius: 15)
.fill(.secondary)
HStack {
RoundedRectangle(cornerRadius: 15)
.fill(.blue)
.frame(width: 50)
Image(systemName: "shippingbox.circle.fill")
.foregroundColor(.white)
.padding(.leading, -25)
Image(systemName: "arrow.forward")
.foregroundColor(.white.opacity(0.5))
Image(systemName: "ellipsis")
.foregroundColor(.white.opacity(0.5))
Text(timerInterval: pizza!.deliverDate, countsDown: true)
.bold()
.font(.caption)
.foregroundColor(.white.opacity(0.8))
.multilineTextAlignment(.center)
Image(systemName: "ellipsis")
.foregroundColor(.white.opacity(0.5))
Image(systemName: "arrow.forward")
.foregroundColor(.white.opacity(0.5))
Image(systemName: "house.circle.fill")
.foregroundColor(.green)
.background(.white)
.clipShape(Circle())
}
}
}
Spacer()
VStack {
Text("\(pizza!.description) 🍕")
.font(.title)
.bold()
Spacer()
}
}.padding(5)
Text("You've already paid: \(pizza!.price) + $9.9 Delivery Fee 💸")
.font(.caption)
.foregroundColor(.secondary)
.padding(.horizontal, 5)
}.padding(15)
} dynamicIsland: { context in
let pizza = PizzaData(JSONData: context.state.data)

return DynamicIsland {
DynamicIslandExpandedRegion(.leading) {
Label("\(pizza!.quantity) Pizzas", systemImage: "bag")
.font(.title2)
}
DynamicIslandExpandedRegion(.trailing) {
Label {
Text(timerInterval: pizza!.deliverDate, countsDown: true)
.multilineTextAlignment(.trailing)
.frame(width: 50)
.monospacedDigit()
.font(.caption2)
} icon: {
Image(systemName: "timer")
}
.font(.title2)
}
DynamicIslandExpandedRegion(.center) {
Text("\("context.state.driverName") is on his way!")
.lineLimit(1)
.font(.caption)
}
DynamicIslandExpandedRegion(.bottom) {
Button {
// Deep link into the app.
} label: {
Label("Contact driver", systemImage: "phone")
}
}
} compactLeading: {
Label {
Text("\(pizza!.quantity) Pizzas")
} icon: {
Image(systemName: "bag")
}
.font(.caption2)
} compactTrailing: {
Text(timerInterval: pizza!.deliverDate, countsDown: true)
.multilineTextAlignment(.center)
.frame(width: 40)
.font(.caption2)
} minimal: {
VStack(alignment: .center) {
Image(systemName: "timer")
Text(timerInterval: pizza!.deliverDate, countsDown: true)
.multilineTextAlignment(.center)
.monospacedDigit()
.font(.caption2)
}
}
.keylineTint(.accentColor)
}
}
}
Loading

0 comments on commit 0e90a96

Please sign in to comment.