Skip to content

Commit c5e1fbb

Browse files
committed
Add AppLinkWidget
1 parent df9a9a2 commit c5e1fbb

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

WooCommerce/Classes/System/WooConstants.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ enum WooConstants {
5353
/// Store Info Widget Identifier.
5454
///
5555
static let storeInfoWidgetKind = "StoreInfoWidget"
56+
57+
/// App link Widget Identifier.
58+
///
59+
static let appLinkWidgetKind = "AppLinkWidget"
5660
}
5761

5862
// MARK: URLs
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import WidgetKit
2+
import SwiftUI
3+
import Experiments
4+
5+
/// Static widget - app launch button
6+
///
7+
struct AppLinkWidget: Widget {
8+
private var supportedFamilies: [WidgetFamily] {
9+
if #available(iOSApplicationExtension 16.0, *) {
10+
return [.accessoryCircular]
11+
} else {
12+
return []
13+
}
14+
}
15+
16+
var body: some WidgetConfiguration {
17+
StaticConfiguration(kind: WooConstants.appLinkWidgetKind, provider: AppLinkProvider()) { _ in
18+
AppButtonView()
19+
}
20+
.configurationDisplayName(Localization.title)
21+
.description(Localization.description)
22+
.supportedFamilies(supportedFamilies)
23+
}
24+
}
25+
26+
private struct AppLinkProvider: TimelineProvider {
27+
/// Type that represents the all the possible Widget states
28+
///
29+
enum AppLinkEntry: TimelineEntry {
30+
// Single possible state
31+
case appLink
32+
33+
// Current date, needed by the `TimelineEntry` protocol.
34+
var date: Date { Date() }
35+
}
36+
37+
func placeholder(in context: Context) -> AppLinkEntry {
38+
return .appLink
39+
}
40+
41+
func getSnapshot(in context: Context, completion: @escaping (AppLinkEntry) -> Void) {
42+
completion(.appLink)
43+
}
44+
45+
func getTimeline(in context: Context, completion: @escaping (Timeline<AppLinkEntry>) -> Void) {
46+
let timeline = Timeline<AppLinkEntry>(entries: [.appLink], policy: .never)
47+
completion(timeline)
48+
}
49+
}
50+
51+
private struct AppButtonView: View {
52+
var body: some View {
53+
ZStack {
54+
Circle()
55+
.fill(Color.black)
56+
Image(uiImage: .wooLogoWhite)
57+
.resizable()
58+
.scaledToFit()
59+
.padding(10)
60+
}
61+
}
62+
}
63+
64+
// MARK: Constants
65+
66+
/// Constants definition
67+
///
68+
private extension AppLinkWidget {
69+
enum Localization {
70+
static let title = AppLocalizedString(
71+
"appLinkWidget.displayName",
72+
value: "Icon",
73+
comment: "Widget title, displayed when selecting which widget to add"
74+
)
75+
static let description = AppLocalizedString(
76+
"appLinkWidget.description",
77+
value: "Quickly Launch WooCommerce",
78+
comment: "Widget description, displayed when selecting which widget to add"
79+
)
80+
}
81+
}
82+
83+
// MARK: Previews
84+
85+
@available(iOSApplicationExtension 16.0, *)
86+
struct AppLinkWidget_Previews: PreviewProvider {
87+
static var previews: some View {
88+
AppButtonView()
89+
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
90+
}
91+
}

WooCommerce/StoreWidgets/StoreWidgets.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ struct StoreWidgetsBundle: WidgetBundle {
88
var body: some Widget {
99
// Add here any widget you want to be available
1010
StoreInfoWidget()
11+
AppLinkWidget()
1112
}
1213
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@
11531153
AEC95D432774D07B001571F5 /* CreateOrderAddressFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC95D422774D07B001571F5 /* CreateOrderAddressFormViewModel.swift */; };
11541154
AECD57D226DFDF7500A3B580 /* EditOrderAddressForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECD57D126DFDF7500A3B580 /* EditOrderAddressForm.swift */; };
11551155
AED089F227C794BC0020AE10 /* View+CurrencySymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED089F127C794BC0020AE10 /* View+CurrencySymbol.swift */; };
1156+
AED9012D28E5F517002B4572 /* AppLinkWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED9012C28E5F517002B4572 /* AppLinkWidget.swift */; };
11561157
AEDDDA0A25CA9C980077F9B2 /* AttributePickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEDDDA0925CA9C980077F9B2 /* AttributePickerViewController.swift */; };
11571158
AEDDDA1A25CAB2170077F9B2 /* AttributePickerViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = AEDDDA1925CAB2170077F9B2 /* AttributePickerViewController.xib */; };
11581159
AEE085B52897C871007ACE20 /* LinkedProductsPromoCampaign.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE085B42897C871007ACE20 /* LinkedProductsPromoCampaign.swift */; };
@@ -3041,6 +3042,7 @@
30413042
AEC95D422774D07B001571F5 /* CreateOrderAddressFormViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateOrderAddressFormViewModel.swift; sourceTree = "<group>"; };
30423043
AECD57D126DFDF7500A3B580 /* EditOrderAddressForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditOrderAddressForm.swift; sourceTree = "<group>"; };
30433044
AED089F127C794BC0020AE10 /* View+CurrencySymbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+CurrencySymbol.swift"; sourceTree = "<group>"; };
3045+
AED9012C28E5F517002B4572 /* AppLinkWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLinkWidget.swift; sourceTree = "<group>"; };
30443046
AEDDDA0925CA9C980077F9B2 /* AttributePickerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributePickerViewController.swift; sourceTree = "<group>"; };
30453047
AEDDDA1925CAB2170077F9B2 /* AttributePickerViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AttributePickerViewController.xib; sourceTree = "<group>"; };
30463048
AEE085B42897C871007ACE20 /* LinkedProductsPromoCampaign.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkedProductsPromoCampaign.swift; sourceTree = "<group>"; };
@@ -5353,6 +5355,7 @@
53535355
children = (
53545356
3F50FE4028C8319A00C89201 /* Entitlements */,
53555357
26FFD32828C6A0E4002E5E5E /* Images */,
5358+
AED9012B28E5F27B002B4572 /* Lockscreen */,
53565359
3F1FA84528B60125009E246C /* StoreWidgets.swift */,
53575360
265C99E028B9BA43005E6117 /* StoreInfoWidget.swift */,
53585361
265C99E328B9C834005E6117 /* StoreInfoProvider.swift */,
@@ -6476,6 +6479,14 @@
64766479
path = "Address Edit";
64776480
sourceTree = "<group>";
64786481
};
6482+
AED9012B28E5F27B002B4572 /* Lockscreen */ = {
6483+
isa = PBXGroup;
6484+
children = (
6485+
AED9012C28E5F517002B4572 /* AppLinkWidget.swift */,
6486+
);
6487+
path = Lockscreen;
6488+
sourceTree = "<group>";
6489+
};
64796490
AEDDDA0825CA9C0A0077F9B2 /* Edit Attributes */ = {
64806491
isa = PBXGroup;
64816492
children = (
@@ -9338,6 +9349,7 @@
93389349
isa = PBXSourcesBuildPhase;
93399350
buildActionMask = 2147483647;
93409351
files = (
9352+
AED9012D28E5F517002B4572 /* AppLinkWidget.swift in Sources */,
93419353
2608C50728C941D600C9DFC0 /* UserDefaults+Woo.swift in Sources */,
93429354
265C99E628B9CB8E005E6117 /* StoreInfoViewModifiers.swift in Sources */,
93439355
2608C50628C93AB700C9DFC0 /* WooConstants.swift in Sources */,

0 commit comments

Comments
 (0)