Skip to content

Commit

Permalink
[MBL-1457] Create empty state view for PPO (#2092)
Browse files Browse the repository at this point in the history
* Create PPO empty state view

Fix accessibility

* Add snapshot test

* Wire up button
  • Loading branch information
ifosli authored Jul 9, 2024
1 parent eb2e070 commit 0113425
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public class PPOContainerViewController: PagedContainerViewController {

// TODO: Translate these strings (MBL-1558)
self.title = "Activity"
let ppoViewController = UIHostingController(rootView: PPOView())

let tabBarController = self.tabBarController as? RootTabBarViewController
let ppoViewController = UIHostingController(rootView: PPOView(tabBarController: tabBarController))
ppoViewController.title = "Project Alerts"

let activitiesViewController = ActivitiesViewController.instantiate()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import SwiftUI

struct PPOEmptyStateView: View {
weak var tabBarController: RootTabBarViewController?

private enum Constants {
public static let largePadding = 24.0
public static let horizontalPadding = 16.0
public static let verticalButtonPadding = 13.0
public static let buttonRadius = 12.0
}

// TODO: Translate these strings (MBL-1558)
var body: some View {
VStack(alignment: .center) {
Text("You're all caught up!")
.font(Font(UIFont.ksr_title2().bolded))
.padding(EdgeInsets(
top: 0,
leading: Constants.horizontalPadding,
bottom: Constants.largePadding,
trailing: Constants.horizontalPadding
))
.multilineTextAlignment(.center)
.accessibilityAddTraits(.isHeader)

VStack(spacing: Constants.largePadding) {
Text("When projects you've backed need your attention, you'll see them here.")
.font(Font(UIFont.ksr_body()))
.multilineTextAlignment(.center)

Button {
self.tabBarController?.switchToProfile()
} label: {
Text("See all backed projects")
.frame(maxWidth: .infinity)
}
.padding(EdgeInsets(
top: Constants.verticalButtonPadding,
leading: Constants.horizontalPadding,
bottom: Constants.verticalButtonPadding,
trailing: Constants.horizontalPadding
))
.foregroundColor(.white)
.background(
Color(UIColor.ksr_create_700),
in: RoundedRectangle(cornerRadius: Constants.buttonRadius)
)
.font(Font(UIFont.ksr_body()))
}
.padding(EdgeInsets(
top: 0,
leading: Constants.largePadding,
bottom: 0,
trailing: Constants.largePadding
))
}
}
}

#Preview {
PPOEmptyStateView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@testable import Kickstarter_Framework
import SnapshotTesting
import SwiftUI
import XCTest

final class PPOEmptyStateViewTests: TestCase {
func testEmptyStateView() {
let view = PPOEmptyStateView().frame(width: 320, height: 500)
// TODO: Record multiple snapshots once translations are available (MBL-1558)
assertSnapshot(matching: view, as: .image, named: "lang_en")
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import SwiftUI

struct PPOView: View {
weak var tabBarController: RootTabBarViewController?
@StateObject private var viewModel = PPOViewModel()
var body: some View {
Text(self.viewModel.greeting)
ScrollView {
// Text(self.viewModel.greeting)
// TODO: Show empty state view if user is logged in and has no PPO updates.
PPOEmptyStateView(tabBarController: self.tabBarController)
}
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@
37FDAFAC2273BA4700662CC8 /* UIStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FDAF702273B7FF00662CC8 /* UIStackView.swift */; };
37FDAFAD2273BA4B00662CC8 /* UIStackView+Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FDAFAA2273B86800662CC8 /* UIStackView+Tests.swift */; };
37FEFBC8222F1E4F00FCA608 /* ProcessInfoType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FEFBC7222F1E4F00FCA608 /* ProcessInfoType.swift */; };
392BB12A2C3BEB5600A5591B /* PPOEmptyStateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 392BB1292C3BEB5500A5591B /* PPOEmptyStateView.swift */; };
392BB12C2C3C095200A5591B /* PPOEmptyStateViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 392BB12B2C3C095200A5591B /* PPOEmptyStateViewTests.swift */; };
3959A6282B69AE6D00FE8055 /* CombineTestObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1889D8D2B6065D6004FBE21 /* CombineTestObserverTests.swift */; };
3959A62C2B69B9CD00FE8055 /* CombineTestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1FDB1E72AEAAC6100285F93 /* CombineTestObserver.swift */; };
3959A62E2B69BBA600FE8055 /* CombineTestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1FDB1E72AEAAC6100285F93 /* CombineTestObserver.swift */; };
Expand Down Expand Up @@ -1945,6 +1947,8 @@
37FDAF702273B7FF00662CC8 /* UIStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIStackView.swift; sourceTree = "<group>"; };
37FDAFAA2273B86800662CC8 /* UIStackView+Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIStackView+Tests.swift"; sourceTree = "<group>"; };
37FEFBC7222F1E4F00FCA608 /* ProcessInfoType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProcessInfoType.swift; sourceTree = "<group>"; };
392BB1292C3BEB5500A5591B /* PPOEmptyStateView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PPOEmptyStateView.swift; sourceTree = "<group>"; };
392BB12B2C3C095200A5591B /* PPOEmptyStateViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PPOEmptyStateViewTests.swift; sourceTree = "<group>"; };
395A3BC12B8E54C90091A379 /* AttributionTracking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributionTracking.swift; sourceTree = "<group>"; };
395A3BC32B8E56800091A379 /* AttributionTrackingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributionTrackingTests.swift; sourceTree = "<group>"; };
395A3BC52BA8CAFA0091A379 /* PostCampaignCheckoutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostCampaignCheckoutViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7085,6 +7089,8 @@
E1BAA0332C1A18DA004F8B06 /* PledgedProjectsOverview */ = {
isa = PBXGroup;
children = (
392BB12B2C3C095200A5591B /* PPOEmptyStateViewTests.swift */,
392BB1292C3BEB5500A5591B /* PPOEmptyStateView.swift */,
E1BAA0382C1A1C56004F8B06 /* PPOContainerViewController.swift */,
E1BAA0342C1A1907004F8B06 /* PPOView.swift */,
E1BAA0362C1A1B13004F8B06 /* PPOViewModel.swift */,
Expand Down Expand Up @@ -8445,6 +8451,7 @@
379CFFFC2242DAE800F6F0C2 /* Nib.swift in Sources */,
A7CC14451D00E75F00035C52 /* FindFriendsDataSource.swift in Sources */,
A7808BBE1D6240B9001CF96A /* ProjectCreatorViewController.swift in Sources */,
392BB12A2C3BEB5600A5591B /* PPOEmptyStateView.swift in Sources */,
D775EBEA207C09FD00885634 /* CrossDissolveTransitionAnimator.swift in Sources */,
395A3BC72BA8CB6E0091A379 /* PostCampaignCheckoutViewController.swift in Sources */,
604453282BA08F7000B8F485 /* PostCampaignPledgeRewardsSummaryCell.swift in Sources */,
Expand Down Expand Up @@ -8586,6 +8593,7 @@
77FA6CD220F53E5E00809E31 /* SettingsDataSourceTests.swift in Sources */,
A7ED204D1E8323E900BFFA01 /* FindFriendsViewControllerTests.swift in Sources */,
015102AE1F1947CB0006C0FC /* MessageThreadsDataSourceTests.swift in Sources */,
392BB12C2C3C095200A5591B /* PPOEmptyStateViewTests.swift in Sources */,
774A76F520D98EEF0012A71F /* BetaToolsViewControllerTests.swift in Sources */,
D033E2C322A05B7400464E43 /* MockApplication.swift in Sources */,
1611EF6A23B2773A0051CDCC /* MockUUID.swift in Sources */,
Expand Down

0 comments on commit 0113425

Please sign in to comment.