Part 6: Separate Widgets

xcode15-and-vision
Alan Francis 2 years ago
parent 86752a8e29
commit 642426c683
  1. 36
      JustOneThing.xcodeproj/project.pbxproj
  2. 39
      WidgetShared/AccessoryWidget.swift
  3. 63
      WidgetShared/JustOneThingWidget.swift
  4. 25
      WidgetShared/SystemWidget.swift
  5. 21
      WidgetShared/ThingView.swift
  6. 22
      WidgetShared/WidgetBundle.swift

@ -19,8 +19,8 @@
547201902A36563C005B2FCC /* Widget.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 54928C1C2A35F89900095445 /* Widget.intentdefinition */; };
547201912A36563C005B2FCC /* WidgetAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 54928C372A35F8B800095445 /* WidgetAssets.xcassets */; };
547201932A365868005B2FCC /* Widget.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 54928C1C2A35F89900095445 /* Widget.intentdefinition */; };
547201962A461DBE005B2FCC /* JustOneThingWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54928C4A2A35F8CB00095445 /* JustOneThingWidget.swift */; };
547201972A461DBE005B2FCC /* JustOneThingWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54928C4A2A35F8CB00095445 /* JustOneThingWidget.swift */; };
547201962A461DBE005B2FCC /* SystemWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54928C4A2A35F8CB00095445 /* SystemWidget.swift */; };
547201972A461DBE005B2FCC /* SystemWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54928C4A2A35F8CB00095445 /* SystemWidget.swift */; };
5483903B2A2A773900BF5624 /* JustOneThingApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5483903A2A2A773900BF5624 /* JustOneThingApp.swift */; };
5483903D2A2A773900BF5624 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5483903C2A2A773900BF5624 /* ContentView.swift */; };
5483903F2A2A773A00BF5624 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5483903E2A2A773A00BF5624 /* Assets.xcassets */; };
@ -35,11 +35,18 @@
54928C3E2A35F8B800095445 /* PhoneWidgetExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 54928C2E2A35F8B800095445 /* PhoneWidgetExtension.appex */; platformFilter = ios; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
54928C472A35F8CB00095445 /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 54928C152A35F89900095445 /* WidgetKit.framework */; };
54928C482A35F8CB00095445 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 54928C172A35F89900095445 /* SwiftUI.framework */; };
54928C4B2A35F8CB00095445 /* JustOneThingWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54928C4A2A35F8CB00095445 /* JustOneThingWidget.swift */; };
54928C542A35F8CC00095445 /* WatchWidgetExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 54928C462A35F8CB00095445 /* WatchWidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
5493A81B2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */; };
5493A81C2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */; };
5493A81D2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */; };
54BD36092A5700480022D6BE /* ThingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BD36082A5700480022D6BE /* ThingView.swift */; };
54BD360A2A5700480022D6BE /* ThingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BD36082A5700480022D6BE /* ThingView.swift */; };
54BD360B2A5700480022D6BE /* ThingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BD36082A5700480022D6BE /* ThingView.swift */; };
54BD360D2A57020E0022D6BE /* WidgetBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BD360C2A57020E0022D6BE /* WidgetBundle.swift */; };
54BD360E2A57020E0022D6BE /* WidgetBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BD360C2A57020E0022D6BE /* WidgetBundle.swift */; };
54BD360F2A57020E0022D6BE /* WidgetBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BD360C2A57020E0022D6BE /* WidgetBundle.swift */; };
54BD36122A57021E0022D6BE /* AccessoryWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BD36102A57021E0022D6BE /* AccessoryWidget.swift */; };
54BD36132A57021E0022D6BE /* AccessoryWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54BD36102A57021E0022D6BE /* AccessoryWidget.swift */; };
54EB3C1F2A5434A30082B059 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EB3C1E2A5434A30082B059 /* Thing.swift */; };
54EB3C202A5434A30082B059 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EB3C1E2A5434A30082B059 /* Thing.swift */; };
54EB3C212A5434A30082B059 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EB3C1E2A5434A30082B059 /* Thing.swift */; };
@ -133,8 +140,11 @@
54928C372A35F8B800095445 /* WidgetAssets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = WidgetAssets.xcassets; sourceTree = "<group>"; };
54928C392A35F8B800095445 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
54928C462A35F8CB00095445 /* WatchWidgetExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = WatchWidgetExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
54928C4A2A35F8CB00095445 /* JustOneThingWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustOneThingWidget.swift; sourceTree = "<group>"; };
54928C4A2A35F8CB00095445 /* SystemWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemWidget.swift; sourceTree = "<group>"; };
5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustOneThingProvider.swift; sourceTree = "<group>"; };
54BD36082A5700480022D6BE /* ThingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThingView.swift; sourceTree = "<group>"; };
54BD360C2A57020E0022D6BE /* WidgetBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetBundle.swift; sourceTree = "<group>"; };
54BD36102A57021E0022D6BE /* AccessoryWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessoryWidget.swift; sourceTree = "<group>"; };
54EB3C1E2A5434A30082B059 /* Thing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Thing.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -205,7 +215,10 @@
isa = PBXGroup;
children = (
54EB3C1E2A5434A30082B059 /* Thing.swift */,
54928C4A2A35F8CB00095445 /* JustOneThingWidget.swift */,
54BD36082A5700480022D6BE /* ThingView.swift */,
54928C4A2A35F8CB00095445 /* SystemWidget.swift */,
54BD36102A57021E0022D6BE /* AccessoryWidget.swift */,
54BD360C2A57020E0022D6BE /* WidgetBundle.swift */,
5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */,
5416C7372A56A867002196EE /* InterfaceExtensions.swift */,
54928C372A35F8B800095445 /* WidgetAssets.xcassets */,
@ -498,8 +511,10 @@
54EB3C1F2A5434A30082B059 /* Thing.swift in Sources */,
54928C212A35F89A00095445 /* Widget.intentdefinition in Sources */,
5493A81B2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */,
54BD36092A5700480022D6BE /* ThingView.swift in Sources */,
54BD360D2A57020E0022D6BE /* WidgetBundle.swift in Sources */,
5416C7382A56A867002196EE /* InterfaceExtensions.swift in Sources */,
547201972A461DBE005B2FCC /* JustOneThingWidget.swift in Sources */,
547201972A461DBE005B2FCC /* SystemWidget.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -507,9 +522,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
54BD36122A57021E0022D6BE /* AccessoryWidget.swift in Sources */,
54EB3C202A5434A30082B059 /* Thing.swift in Sources */,
547201962A461DBE005B2FCC /* JustOneThingWidget.swift in Sources */,
547201962A461DBE005B2FCC /* SystemWidget.swift in Sources */,
5493A81C2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */,
54BD360A2A5700480022D6BE /* ThingView.swift in Sources */,
54BD360E2A57020E0022D6BE /* WidgetBundle.swift in Sources */,
5416C7392A56A867002196EE /* InterfaceExtensions.swift in Sources */,
5472018E2A36563B005B2FCC /* Widget.intentdefinition in Sources */,
);
@ -519,11 +537,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
54BD36132A57021E0022D6BE /* AccessoryWidget.swift in Sources */,
54EB3C212A5434A30082B059 /* Thing.swift in Sources */,
547201902A36563C005B2FCC /* Widget.intentdefinition in Sources */,
5493A81D2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */,
54BD360B2A5700480022D6BE /* ThingView.swift in Sources */,
54BD360F2A57020E0022D6BE /* WidgetBundle.swift in Sources */,
5416C73A2A56A867002196EE /* InterfaceExtensions.swift in Sources */,
54928C4B2A35F8CB00095445 /* JustOneThingWidget.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -0,0 +1,39 @@
//
// AccessoryWidget.swift
// JustOneThing
//
// Created by Alan Francis on 06/07/2023.
//
import SwiftUI
import WidgetKit
import Intents
struct JustOneThingAccessoryWidget: Widget {
let kind: String = "JustOneThingAccessoryWidget"
var body: some WidgetConfiguration {
IntentConfiguration(kind: kind,
intent: ConfigurationIntent.self,
provider: ThingProvider()) { entry in
JustOneThingAccessoryThingView(thing: entry.thing)
}
.configurationDisplayName("One Tiny Thing")
.description("Show a random Thing in an Accessory.")
.supportedFamilies([.accessoryInline, .accessoryCircular, .accessoryRectangular])
}
}
struct JustOneThingAccessoryThingView: View {
let thing: Thing
@Environment(\.widgetFamily) var family
var body: some View {
if( family == .accessoryCircular ) {
Image(systemName:"1.magnifyingglass").font(.largeTitle)
} else {
ThingView(thing: thing)
}
}
}

@ -1,63 +0,0 @@
//
// JustOneThingWidget.swift
// JustOneThing
//
// Created by Alan Francis on 11/06/2023.
//
import WidgetKit
import SwiftUI
import Intents
@main
struct JustOneThingWidgetBundle: WidgetBundle {
var body: some Widget {
JustOneThingWidget()
}
}
struct ThingView : View {
let thing: Thing
@Environment(\.colorScheme) private var colorScheme
var body: some View {
Text(thing.text)
.fitSystemFont(lineLimit: 4)
.multilineTextAlignment(.center)
.foregroundColor(.randomForegroundColor(colorScheme))
}
}
struct ThingEntryView : View {
var entry: ThingEntry
var body: some View {
ThingView(thing: entry.thing).padding()
}
}
struct JustOneThingWidget: Widget {
let kind: String = "JustOneThingWidget"
var body: some WidgetConfiguration {
IntentConfiguration(kind: kind,
intent: ConfigurationIntent.self,
provider: ThingProvider()) { entry in
ThingEntryView(entry: entry)
}
.configurationDisplayName("My Widget")
.description("This is an example widget.")
}
}
struct Widget_Previews: PreviewProvider {
static var previews: some View {
ThingEntryView(entry: ThingEntry(thing: Thing(text: "dont forget toothepase", createdAt: Date())))
#if os(watchOS)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
#else
.previewContext(WidgetPreviewContext(family: .systemMedium))
#endif
}
}

@ -0,0 +1,25 @@
//
// JustOneThingWidget.swift
// JustOneThing
//
// Created by Alan Francis on 11/06/2023.
//
import SwiftUI
import WidgetKit
import Intents
struct JustOneThingSystemWidget: Widget {
let kind: String = "JustOneThingSystemWidget"
var body: some WidgetConfiguration {
IntentConfiguration(kind: kind,
intent: ConfigurationIntent.self,
provider: ThingProvider()) { entry in
ThingView(thing: entry.thing)
}
.configurationDisplayName("Just One Thing")
.description("Show a random Thing.")
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
}
}

@ -0,0 +1,21 @@
//
// ThingView.swift
// JustOneThing
//
// Created by Alan Francis on 06/07/2023.
//
import SwiftUI
struct ThingView : View {
let thing: Thing
@Environment(\.colorScheme) private var colorScheme
var body: some View {
Text(thing.text)
.fitSystemFont(lineLimit: 4)
.multilineTextAlignment(.center)
.foregroundColor(.randomForegroundColor(colorScheme))
}
}

@ -0,0 +1,22 @@
//
// WidgetBundle.swift
// JustOneThing
//
// Created by Alan Francis on 06/07/2023.
//
import SwiftUI
import WidgetKit
@main
struct JustOneThingWidgetBundle: WidgetBundle {
var body: some Widget {
#if !os(watchOS)
JustOneThingSystemWidget()
#endif
#if !os(macOS)
JustOneThingAccessoryWidget()
#endif
}
}
Loading…
Cancel
Save