Skip to content

Commit 320d981

Browse files
authored
Merge pull request #5378 from woocommerce/feat/5362-jetpack-benefits-banner-ui
Jetpack CP: benefits banner UI
2 parents 70d9a7d + 5020fa4 commit 320d981

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

WooCommerce/Classes/Styles/ColorStudio.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ enum ColorStudioName: String, CustomStringConvertible {
33
// MARK: - Base colors
44
case blue
55
case celadon
6+
case jetpackGreen
67
case gray
78
case green
89
case orange
@@ -68,6 +69,7 @@ struct ColorStudio {
6869
static let red = ColorStudio(name: .red)
6970
static let gray = ColorStudio(name: .gray)
7071
static let blue = ColorStudio(name: .blue)
72+
static let jetpackGreen = ColorStudio(name: .jetpackGreen)
7173
static let green = ColorStudio(name: .green)
7274
static let yellow = ColorStudio(name: .yellow)
7375
static let orange = ColorStudio(name: .orange)

WooCommerce/Classes/Styles/UIColor+SemanticColors.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,18 @@ extension UIColor {
301301
static var softwareUpdateProgressFill: UIColor {
302302
return UIColor(red: 0.498, green: 0.329, blue: 0.702, alpha: 1)
303303
}
304+
305+
/// Jetpack benefits banner background color.
306+
///
307+
static var jetpackBenefitsBackground: UIColor {
308+
UIColor(red: 11.0/255, green: 38.0/255, blue: 33.0/255, alpha: 1)
309+
}
310+
311+
/// Jetpack logo color.
312+
///
313+
static var jetpackGreen: UIColor {
314+
.withColorStudio(.jetpackGreen, shade: .shade20)
315+
}
304316
}
305317

306318
// MARK: - UI elements.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import SwiftUI
2+
3+
/// Hosting controller wrapper for `JetpackBenefitsBanner`
4+
///
5+
final class JetpackBenefitsBannerHostingController: UIHostingController<JetpackBenefitsBanner> {
6+
init() {
7+
super.init(rootView: JetpackBenefitsBanner())
8+
}
9+
10+
required dynamic init?(coder aDecoder: NSCoder) {
11+
fatalError("init(coder:) has not been implemented")
12+
}
13+
14+
/// Actions are set in a separate function because most of the time, they will require to access `self` to be able to present new view controllers.
15+
///
16+
func setActions(tapAction: @escaping () -> Void, dismissAction: @escaping () -> Void) {
17+
rootView.tapAction = tapAction
18+
rootView.dismissAction = dismissAction
19+
}
20+
}
21+
22+
/// A banner about Jetpack benefits that can be tapped to show more details or dismiss.
23+
struct JetpackBenefitsBanner: View {
24+
/// Closure invoked when the banner is tapped
25+
///
26+
var tapAction: () -> Void = {}
27+
28+
/// Closure invoked when the dismiss button is tapped
29+
///
30+
var dismissAction: () -> Void = {}
31+
32+
// Tracks the scale of the view due to accessibility changes
33+
@ScaledMetric private var scale: CGFloat = 1.0
34+
35+
var body: some View {
36+
Group {
37+
HStack(spacing: Layout.horizontalSpacing) {
38+
Image(uiImage: .jetpackLogoImage)
39+
.resizable()
40+
.renderingMode(.template)
41+
.foregroundColor(Color(.jetpackGreen))
42+
.frame(width: Layout.iconDimension * scale, height: Layout.iconDimension * scale)
43+
VStack(alignment: .leading, spacing: Layout.verticalTextSpacing) {
44+
Text(Localization.title)
45+
.foregroundColor(.white)
46+
.bodyStyle()
47+
Text(Localization.subtitle)
48+
.foregroundColor(Color(.gray(.shade30)))
49+
.bodyStyle()
50+
}
51+
Spacer()
52+
Button(action: dismissAction) {
53+
Image(uiImage: .closeButton)
54+
.foregroundColor(Color(.gray(.shade30)))
55+
}
56+
}
57+
.padding(insets: Layout.padding)
58+
}
59+
.background(Color(.jetpackBenefitsBackground))
60+
.fixedSize(horizontal: false, vertical: true)
61+
.contentShape(Rectangle())
62+
.onTapGesture {
63+
self.tapAction()
64+
}
65+
}
66+
}
67+
68+
private extension JetpackBenefitsBanner {
69+
enum Localization {
70+
static let title = NSLocalizedString("Get the full experience with Jetpack", comment: "Title of the Jetpack benefits banner.")
71+
static let subtitle = NSLocalizedString("See the benefits", comment: "Subtitle of the Jetpack benefits banner.")
72+
}
73+
74+
enum Layout {
75+
static let padding = EdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16)
76+
static let iconDimension = CGFloat(24)
77+
static let horizontalSpacing = CGFloat(10)
78+
static let verticalTextSpacing = CGFloat(5)
79+
}
80+
}
81+
82+
struct JetpackBenefitsBanner_Previews: PreviewProvider {
83+
static var previews: some View {
84+
JetpackBenefitsBanner()
85+
.preferredColorScheme(.dark)
86+
.environment(\.sizeCategory, .extraSmall)
87+
.previewLayout(.sizeThatFits)
88+
JetpackBenefitsBanner()
89+
.preferredColorScheme(.light)
90+
.environment(\.sizeCategory, .medium)
91+
.previewLayout(.sizeThatFits)
92+
JetpackBenefitsBanner()
93+
.preferredColorScheme(.dark)
94+
.environment(\.sizeCategory, .extraExtraLarge)
95+
.previewLayout(.sizeThatFits)
96+
JetpackBenefitsBanner()
97+
.preferredColorScheme(.light)
98+
.environment(\.sizeCategory, .extraExtraExtraLarge)
99+
.previewLayout(.sizeThatFits)
100+
}
101+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@
371371
02F67FF525806E0100C3BAD2 /* ShippingLabelTrackingURLGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F67FF425806E0100C3BAD2 /* ShippingLabelTrackingURLGeneratorTests.swift */; };
372372
02F6800325807C9B00C3BAD2 /* ShippingLabelPaperSizeOptionListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F6800225807C9B00C3BAD2 /* ShippingLabelPaperSizeOptionListView.swift */; };
373373
02F6800925807CD300C3BAD2 /* GridStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F6800825807CD300C3BAD2 /* GridStackView.swift */; };
374+
02F843DA273646A30017FE12 /* JetpackBenefitsBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F843D9273646A30017FE12 /* JetpackBenefitsBanner.swift */; };
374375
02FE89C7231FAA4100E85EF8 /* MainTabBarControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FE89C6231FAA4100E85EF8 /* MainTabBarControllerTests.swift */; };
375376
03AA165E2719B7EF005CCB7B /* ReceiptActionCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AA165D2719B7EF005CCB7B /* ReceiptActionCoordinator.swift */; };
376377
03AA16602719B83D005CCB7B /* ReceiptActionCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AA165F2719B83D005CCB7B /* ReceiptActionCoordinatorTests.swift */; };
@@ -1836,6 +1837,7 @@
18361837
02F67FF425806E0100C3BAD2 /* ShippingLabelTrackingURLGeneratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelTrackingURLGeneratorTests.swift; sourceTree = "<group>"; };
18371838
02F6800225807C9B00C3BAD2 /* ShippingLabelPaperSizeOptionListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPaperSizeOptionListView.swift; sourceTree = "<group>"; };
18381839
02F6800825807CD300C3BAD2 /* GridStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridStackView.swift; sourceTree = "<group>"; };
1840+
02F843D9273646A30017FE12 /* JetpackBenefitsBanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackBenefitsBanner.swift; sourceTree = "<group>"; };
18391841
02FE89C6231FAA4100E85EF8 /* MainTabBarControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarControllerTests.swift; sourceTree = "<group>"; };
18401842
03AA165D2719B7EF005CCB7B /* ReceiptActionCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptActionCoordinator.swift; sourceTree = "<group>"; };
18411843
03AA165F2719B83D005CCB7B /* ReceiptActionCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptActionCoordinatorTests.swift; sourceTree = "<group>"; };
@@ -3867,6 +3869,14 @@
38673869
path = "Shipping Label";
38683870
sourceTree = "<group>";
38693871
};
3872+
02F843D8273646190017FE12 /* JetpackConnectionPackageSites */ = {
3873+
isa = PBXGroup;
3874+
children = (
3875+
02F843D9273646A30017FE12 /* JetpackBenefitsBanner.swift */,
3876+
);
3877+
path = JetpackConnectionPackageSites;
3878+
sourceTree = "<group>";
3879+
};
38703880
2611EE57243A46C500A74490 /* Categories */ = {
38713881
isa = PBXGroup;
38723882
children = (
@@ -6125,6 +6135,7 @@
61256135
CE85FD5120F677460080B73E /* Dashboard */ = {
61266136
isa = PBXGroup;
61276137
children = (
6138+
02F843D8273646190017FE12 /* JetpackConnectionPackageSites */,
61286139
028BAC4322F3AE3B008BB4AF /* Stats v4 */,
61296140
029D444B22F1417400DEFA8A /* Stats v3 */,
61306141
029D444722F13F5C00DEFA8A /* Factories */,
@@ -8142,6 +8153,7 @@
81428153
B5AA7B3D20ED5D15004DA14F /* SessionManager.swift in Sources */,
81438154
74C6FEA521C2F1FA009286B6 /* AboutViewController.swift in Sources */,
81448155
B53B3F37219C75AC00DF1EB6 /* OrderLoaderViewController.swift in Sources */,
8156+
02F843DA273646A30017FE12 /* JetpackBenefitsBanner.swift in Sources */,
81458157
027D4A8D2526FD1800108626 /* SettingsViewController.swift in Sources */,
81468158
02E262C9238D0AD300B79588 /* ProductStockStatusListSelectorCommand.swift in Sources */,
81478159
CE2A9FC823C3D2D4002BEC1C /* RefundedProductsDataSource.swift in Sources */,

0 commit comments

Comments
 (0)