Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MBL-1458 pt 1] Add alert flag for PPO #2120

Merged
merged 12 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "clock.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Icon.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import Library
import SwiftUI

struct PPOAlertFlag: View {
let alert: Alert

var body: some View {
HStack {
self.image
.renderingMode(.template)
.aspectRatio(contentMode: .fit)
.foregroundStyle(self.foregroundColor)
.frame(width: Constants.imageSize, height: Constants.imageSize)
Spacer()
.frame(width: Constants.spacerWidth)
Text(self.alert.message)
.font(Font(Constants.font))
.foregroundStyle(self.foregroundColor)
}
.padding(Constants.padding)
.background(self.backgroundColor)
.clipShape(RoundedRectangle(cornerSize: CGSize(
width: Constants.cornerRadius,
height: Constants.cornerRadius
)))
}

var image: Image {
switch self.alert.type {
case .time:
Image(Constants.timeImage)
case .alert:
Image(Constants.alertImage)
}
}

var foregroundColor: Color {
switch self.alert.icon {
case .warning:
Color(uiColor: Constants.warningForegroundColor)
case .alert:
Color(uiColor: Constants.alertForegroundColor)
}
}

var backgroundColor: Color {
switch self.alert.icon {
case .warning:
Color(uiColor: Constants.warningBackgroundColor)
case .alert:
Color(uiColor: Constants.alertBackgroundColor)
}
}

struct Alert: Identifiable {
let type: AlertType
let icon: AlertIcon
let message: String

var id: String {
"\(self.type)-\(self.icon)-\(self.message)"
}

enum AlertType: Identifiable {
case time
case alert

var id: String {
switch self {
case .time:
"time"
case .alert:
"alert"
}
}
}

enum AlertIcon: Identifiable {
case warning
case alert

var id: String {
switch self {
case .warning:
"warning"
case .alert:
"alert"
}
}
}
}

private enum Constants {
static let warningForegroundColor = UIColor.ksr_support_400
static let warningBackgroundColor = UIColor.ksr_celebrate_100

static let alertForegroundColor = UIColor.hex(0x73140D)
static let alertBackgroundColor = UIColor.hex(0xFEF2F1)

static let timeImage = ImageResource.iconLimitedTime
static let alertImage = ImageResource.iconNotice

static let imageSize: CGFloat = 18
static let spacerWidth: CGFloat = 4
static let cornerRadius: CGFloat = 6
static let font = UIFont.ksr_caption1().bolded
static let padding = EdgeInsets(top: 4, leading: 12, bottom: 4, trailing: 8)
}
}

#Preview("Stack of flags") {
VStack(alignment: .leading, spacing: 8) {
PPOAlertFlag(alert: .init(type: .time, icon: .warning, message: "Address locks in 8 hours"))
PPOAlertFlag(alert: .init(type: .alert, icon: .warning, message: "Survey available"))
PPOAlertFlag(alert: .init(type: .alert, icon: .alert, message: "Payment failed"))
PPOAlertFlag(alert: .init(type: .time, icon: .alert, message: "Pledge will be dropped in 6 days"))
PPOAlertFlag(alert: .init(type: .alert, icon: .alert, message: "Card needs authentication"))
}
}
12 changes: 12 additions & 0 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@
A7F441E91D005A9400FE6FC5 /* TwoFactorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F441AC1D005A9400FE6FC5 /* TwoFactorViewModel.swift */; };
A7F6F0C11DC7EBF7002C118C /* DateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F6F0C01DC7EBF7002C118C /* DateProtocol.swift */; };
A7FC8C061C8F1DEA00C3B49B /* CircleAvatarImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7FC8C051C8F1DEA00C3B49B /* CircleAvatarImageView.swift */; };
AA6E9E852C62B9DC001543FC /* PPOAlertFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAD2BEE82C59B981003D8B95 /* PPOAlertFlag.swift */; };
D002CAE1218CF8F1009783F2 /* WatchProjectMutation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D002CAE0218CF8F1009783F2 /* WatchProjectMutation.swift */; };
D002CAE3218CF91D009783F2 /* WatchProjectInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = D002CAE2218CF91D009783F2 /* WatchProjectInput.swift */; };
D002CAE5218CF951009783F2 /* WatchProjectResponseEnvelope.swift in Sources */ = {isa = PBXBuildFile; fileRef = D002CAE4218CF951009783F2 /* WatchProjectResponseEnvelope.swift */; };
Expand Down Expand Up @@ -2761,6 +2762,7 @@
A7F761741C85FA40005405ED /* ActivitiesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActivitiesViewController.swift; sourceTree = "<group>"; };
A7F761761C85FACB005405ED /* LoginToutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = LoginToutViewController.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
A7FC8C051C8F1DEA00C3B49B /* CircleAvatarImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CircleAvatarImageView.swift; sourceTree = "<group>"; };
AAD2BEE82C59B981003D8B95 /* PPOAlertFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PPOAlertFlag.swift; sourceTree = "<group>"; };
D002CAE0218CF8F1009783F2 /* WatchProjectMutation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WatchProjectMutation.swift; sourceTree = "<group>"; };
D002CAE2218CF91D009783F2 /* WatchProjectInput.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WatchProjectInput.swift; sourceTree = "<group>"; };
D002CAE4218CF951009783F2 /* WatchProjectResponseEnvelope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WatchProjectResponseEnvelope.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6678,6 +6680,14 @@
path = ViewModels;
sourceTree = "<group>";
};
AAD2BEE72C59B964003D8B95 /* CardView */ = {
isa = PBXGroup;
children = (
AAD2BEE82C59B981003D8B95 /* PPOAlertFlag.swift */,
);
path = CardView;
sourceTree = "<group>";
};
D01587511EEB2DE4006E7684 /* KsApi */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -7098,6 +7108,7 @@
E1BAA0332C1A18DA004F8B06 /* PledgedProjectsOverview */ = {
isa = PBXGroup;
children = (
AAD2BEE72C59B964003D8B95 /* CardView */,
392BB12B2C3C095200A5591B /* PPOEmptyStateViewTests.swift */,
392BB1292C3BEB5500A5591B /* PPOEmptyStateView.swift */,
E1BAA0382C1A1C56004F8B06 /* PPOContainerViewController.swift */,
Expand Down Expand Up @@ -8415,6 +8426,7 @@
473DE014273C551C0033331D /* ProjectRisksDisclaimerCell.swift in Sources */,
D6C3845B210B9AC400ADB671 /* SettingsNewslettersTopCell.swift in Sources */,
D6534D3822E784B500E9D279 /* PledgePaymentMethodCell.swift in Sources */,
AA6E9E852C62B9DC001543FC /* PPOAlertFlag.swift in Sources */,
777C67BB220A0FA5009F8D42 /* SettingsTableViewHeader.swift in Sources */,
A72C3AB01D00F9C10075227E /* DiscoveryFiltersDataSource.swift in Sources */,
A757EBB31D1B084F00A5C978 /* DiscoveryOnboardingCell.swift in Sources */,
Expand Down