Skip to content

Commit

Permalink
Add Widget Extension support to AppClips (#6287)
Browse files Browse the repository at this point in the history
* Adds widget extension support to AppClips

* Fix tests

* Remove additional fixture

* Remove non-existing fixture

---------

Co-authored-by: Alex little <alex@reelapp.co.uk>
  • Loading branch information
pepicrft and alexjameslittle committed May 16, 2024
1 parent daa042c commit 361c497
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/TuistGenerator/Linter/GraphLinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ public class GraphLinter: GraphLinting {
LintableTarget(platform: .iOS, product: .dynamicLibrary),
LintableTarget(platform: .iOS, product: .framework),
LintableTarget(platform: .iOS, product: .staticFramework),
LintableTarget(platform: .iOS, product: .appExtension),
LintableTarget(platform: .macOS, product: .macro),
],
LintableTarget(platform: .iOS, product: .extensionKitExtension): [
Expand Down
12 changes: 12 additions & 0 deletions Tests/TuistGeneratorAcceptanceTests/GenerateAcceptanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,18 @@ final class GenerateAcceptanceTestiOSAppWithAppClip: TuistAcceptanceTestCase {
architecture: "arm64"
)
try XCTAssertFrameworkEmbedded("Framework", by: "AppClip1")
try await XCTAssertProductWithDestinationContainsAppClipWithArchitecture(
"App.app",
destination: "Debug-iphonesimulator",
appClip: "AppClip1",
architecture: "arm64"
)
try XCTAssertFrameworkEmbedded("Framework", by: "AppClip1")
try await XCTAssertProductWithDestinationContainsExtension(
"AppClip1.app",
destination: "Debug-iphonesimulator",
extension: "AppClip1Widgets"
)
}
}

Expand Down
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,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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
}
}
69 changes: 69 additions & 0 deletions fixtures/ios_app_with_appclip/AppClip1Widgets/Sources/Widget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#if canImport(WidgetKit)

import SwiftUI
import WidgetKit

struct Provider: TimelineProvider {
public typealias Entry = SimpleEntry

func placeholder(in _: Context) -> SimpleEntry {
SimpleEntry(date: Date())
}

func getSnapshot(in _: Context, completion _: @escaping (SimpleEntry) -> Void) {}

func getTimeline(in _: Context, completion _: @escaping (Timeline<SimpleEntry>) -> Void) {}

public func snapshot(with _: Context, completion: @escaping (SimpleEntry) -> Void) {
let entry = SimpleEntry(date: Date())
completion(entry)
}

public func timeline(with _: Context, completion: @escaping (Timeline<Entry>) -> Void) {
var entries: [SimpleEntry] = []

// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 5 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
let entry = SimpleEntry(date: entryDate)
entries.append(entry)
}

let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
}

struct SimpleEntry: TimelineEntry {
public let date: Date
}

struct PlaceholderView: View {
var body: some View {
Text("Placeholder View")
}
}

struct MyWidgetEntryView: View {
var entry: Provider.Entry

var body: some View {
Text(entry.date, style: .time)
}
}

@main
struct MyWidget: Widget {
private let kind: String = "MyWidget"

public var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
MyWidgetEntryView(entry: entry)
}
.configurationDisplayName("MyWidget")
.description("This is an example widget.")
}
}

#endif
18 changes: 18 additions & 0 deletions fixtures/ios_app_with_appclip/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ let project = Project(
dependencies: [
.target(name: "Framework"),
.target(name: "StaticFramework"),
.target(name: "AppClip1Widgets"),
]
),
.target(
Expand All @@ -69,5 +70,22 @@ let project = Project(
.target(name: "AppClip1"),
]
),
.target(
name: "AppClip1Widgets",
destinations: .iOS,
product: .appExtension,
bundleId: "io.tuist.App.Clip.Widgets",
infoPlist: .extendingDefault(with: [
"CFBundleDisplayName": "$(PRODUCT_NAME)",
"NSExtension": [
"NSExtensionPointIdentifier": "com.apple.widgetkit-extension",
],
]),
sources: "AppClip1Widgets/Sources/**",
resources: "AppClip1Widgets/Resources/**",
dependencies: [
.target(name: "StaticFramework"),
]
),
]
)

0 comments on commit 361c497

Please sign in to comment.