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-1500] Update and use banners for ppo #2094

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Expand Up @@ -3,24 +3,31 @@ import SwiftUI

struct MessageBannerView: View {
@Binding var viewModel: MessageBannerViewViewModel?
@SwiftUI.Environment(\.accessibilityVoiceOverEnabled) private var voiceOverEnabled

var body: some View {
if let vm = viewModel {
ZStack {
RoundedRectangle(cornerRadius: 4)
.foregroundColor(vm.bannerBackgroundColor)
Label(vm.bannerMessage, image: vm.iconImageName)
HStack(alignment: .center, spacing: 12) {
Image(vm.iconImageName, bundle: Bundle.framework)
Text(vm.bannerMessage)
.font(Font(UIFont.ksr_subhead()))
.foregroundColor(vm.messageTextColor)
.lineLimit(3)
.multilineTextAlignment(vm.messageTextAlignment)
.padding(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))
.frame(
maxWidth: .infinity,
minHeight: 40,
alignment: self.alignmentFromTextAlignment(vm.messageTextAlignment)
)
}
.foregroundColor(vm.messageTextColor)
.padding(EdgeInsets(top: 16, leading: 9, bottom: 16, trailing: 9))
.background {
RoundedRectangle(cornerRadius: 6)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This corner radius (and possibly the padding) matches the figma for PPO but is different from the UIKit banners. I'm going to confirm with Alison if we want to match the figma or if we want to be consistent with the app before I submit the pr.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about having some kind of MessageBannerViewLayout enum to avoid hardcoding the padding, cornerRadius, minHeight, and spacing values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I wanted to do a shared enum between the swiftUI and UIKit versions, but the UIKit version is primarily a storyboard, so I gave up on that pretty quickly... I've also changed some of the values (and re-recorded screenshots) after talking to Alison and determining that PPO styling should match current standards, not our Figma mocks.

.foregroundColor(vm.bannerBackgroundColor)
}
.accessibilityElement()
.accessibilityLabel(vm.bannerMessageAccessibilityLabel)
.padding()
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
DispatchQueue.main.asyncAfter(deadline: .now() + (self.voiceOverEnabled ? 8 : 4)) {
self.viewModel = nil
}
}
Expand All @@ -29,4 +36,19 @@ struct MessageBannerView: View {
}
}
}

// MARK: - Helpers

private func alignmentFromTextAlignment(_ textAligment: TextAlignment) -> Alignment {
switch textAligment {
case .center: return .center
case .leading: return .leading
case .trailing: return .trailing
}
}
}

#Preview {
@State var viewModel: MessageBannerViewViewModel? = MessageBannerViewViewModel((.success, "Short string"))
return MessageBannerView(viewModel: $viewModel)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@testable import Kickstarter_Framework
// @testable import KsApi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we can remove this import for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

import Library
import SnapshotTesting
import SwiftUI
import XCTest

internal final class MessageBannerViewTests: TestCase {
func testBannerSuccess() {
@State var viewModel: MessageBannerViewViewModel? = MessageBannerViewViewModel((
.success,
"Everything completed successfully and now's the time to celebrate! Goooooo team!"
))
let messageBannerView = MessageBannerView(viewModel: $viewModel)
.defaultPortraitFrame()

assertSnapshot(matching: messageBannerView, as: .image)
}

func testBannerError() {
@State var viewModel: MessageBannerViewViewModel? = MessageBannerViewViewModel((
.error,
"Something went wrong"
))
let messageBannerView = MessageBannerView(viewModel: $viewModel)
.defaultPortraitFrame()

assertSnapshot(matching: messageBannerView, as: .image)
}

func testBannerInfo_shortString() {
@State var viewModel: MessageBannerViewViewModel? = MessageBannerViewViewModel((
.info,
"Something happened"
))
let messageBannerView = MessageBannerView(viewModel: $viewModel)
.defaultPortraitFrame()

assertSnapshot(matching: messageBannerView, as: .image)
}

func testBannerInfo_longString() {
@State var viewModel: MessageBannerViewViewModel? = MessageBannerViewViewModel((
.info,
"Something unexpected happened but everything is probably fine."
))
let messageBannerView = MessageBannerView(viewModel: $viewModel)
.defaultPortraitFrame()

assertSnapshot(matching: messageBannerView, as: .image)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the image icon supposed to show in these snapshots? Either the checkmark or "i" info icon?

Copy link
Contributor Author

@ifosli ifosli Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we're not using an info icon - that's why the info banners are centered instead of aligned to the left. I think it's a bit of a weird choice, but it matches what our other banners do so I'm pretty sure it's intentional. I removed the empty image, though, so it should look better now!

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 31 additions & 4 deletions Kickstarter-iOS/Features/PledgedProjectsOverview/PPOView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,38 @@ import SwiftUI
struct PPOView: View {
weak var tabBarController: RootTabBarViewController?
@StateObject private var viewModel = PPOViewModel()

@AccessibilityFocusState private var isBannerFocused: Bool

var body: some View {
ScrollView {
// Text(self.viewModel.greeting)
// TODO: Show empty state view if user is logged in and has no PPO updates.
PPOEmptyStateView(tabBarController: self.tabBarController)
GeometryReader { reader in
ScrollView {
Text(self.viewModel.greeting)
// TODO: Show empty state view if user is logged in and has no PPO updates.
// PPOEmptyStateView(tabBarController: self.tabBarController)

// TODO: Remove this button once we're showing cards instead.
Button("Show banner") {
self.viewModel.shouldSendSampleMessage()
}
}
.frame(maxWidth: .infinity, alignment: .center)
.overlay(alignment: .bottom) {
MessageBannerView(viewModel: self.$viewModel.bannerViewModel)
.frame(
minWidth: reader.size.width,
idealWidth: reader.size.width,
alignment: .bottom
)
.animation(.easeInOut, value: self.viewModel.bannerViewModel != nil)
.accessibilityFocused(self.$isBannerFocused)
}

.onChange(of: self.viewModel.bannerViewModel, perform: { _ in
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.isBannerFocused = self.viewModel.bannerViewModel != nil
}
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
import Combine
import Foundation
import Library

public class PPOViewModel: ObservableObject {
let greeting = "Hello, PPO"

@Published public var bannerViewModel: MessageBannerViewViewModel? = nil

private var cancellables = Set<AnyCancellable>()

public init() {
// TODO: Send actual banner messages in response to card actions instead.
self.shouldSendSampleMessageSubject
.sink { [weak self] _ in
// self?.bannerViewModel = MessageBannerViewViewModel((
// .success,
// "Survey submitted! Need to change your address? Visit your backing details on our website."
// ))
self?.bannerViewModel = MessageBannerViewViewModel((.success, "Your payment has been processed."))
}
.store(in: &self.cancellables)
}

private let shouldSendSampleMessageSubject = PassthroughSubject<(), Never>()
public func shouldSendSampleMessage() {
self.shouldSendSampleMessageSubject.send(())
}
}
14 changes: 14 additions & 0 deletions Kickstarter-iOS/TestHelpers/SwiftUI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import SwiftUI

struct DefaultPortraitFrame: ViewModifier {
func body(content: Content) -> some View {
content
.frame(width: 320, height: 580)
}
}

extension View {
func defaultPortraitFrame() -> some View {
modifier(DefaultPortraitFrame())
}
}
8 changes: 8 additions & 0 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@
39B5E10E2B86C56600FFB720 /* RefInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B5E10D2B86C56600FFB720 /* RefInfo.swift */; };
39B5E1102B86C56E00FFB720 /* RefInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B5E10F2B86C56E00FFB720 /* RefInfoTests.swift */; };
39B5E1122B89120F00FFB720 /* CreateAttributionEvent.graphql in Resources */ = {isa = PBXBuildFile; fileRef = 39B5E1112B89120E00FFB720 /* CreateAttributionEvent.graphql */; };
39B850762C3EA5630045CBA5 /* SwiftUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B850752C3EA5620045CBA5 /* SwiftUI.swift */; };
39B850782C3EA5BB0045CBA5 /* MessageBannerViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B850772C3EA5BB0045CBA5 /* MessageBannerViewTests.swift */; };
39C6169E2BC83DB000732410 /* PostCampaignPledgeRewardsSummaryViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39C6169D2BC83DB000732410 /* PostCampaignPledgeRewardsSummaryViewModelTests.swift */; };
4705D8982742E20900A13BBE /* ProjectHeaderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4705D8972742E20900A13BBE /* ProjectHeaderCell.swift */; };
471235F7274450AC0035527F /* ProjectPamphletMainCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 471235F6274450AC0035527F /* ProjectPamphletMainCell.xib */; };
Expand Down Expand Up @@ -1957,6 +1959,8 @@
39B5E10D2B86C56600FFB720 /* RefInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefInfo.swift; sourceTree = "<group>"; };
39B5E10F2B86C56E00FFB720 /* RefInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefInfoTests.swift; sourceTree = "<group>"; };
39B5E1112B89120E00FFB720 /* CreateAttributionEvent.graphql */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CreateAttributionEvent.graphql; sourceTree = "<group>"; };
39B850752C3EA5620045CBA5 /* SwiftUI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftUI.swift; sourceTree = "<group>"; };
39B850772C3EA5BB0045CBA5 /* MessageBannerViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageBannerViewTests.swift; sourceTree = "<group>"; };
39C6169D2BC83DB000732410 /* PostCampaignPledgeRewardsSummaryViewModelTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostCampaignPledgeRewardsSummaryViewModelTests.swift; sourceTree = "<group>"; };
3D1363951F0191FB00B53420 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
4705D8972742E20900A13BBE /* ProjectHeaderCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectHeaderCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5698,6 +5702,7 @@
isa = PBXGroup;
children = (
7061848829BE4C11008F9941 /* MessageBannerView.swift */,
39B850772C3EA5BB0045CBA5 /* MessageBannerViewTests.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -6368,6 +6373,7 @@
A7ED20211E83237F00BFFA01 /* Combos.swift */,
37096C3122BC23AD003D1F40 /* MockAppEnvironment.swift */,
37096C2F22BC238C003D1F40 /* MockFeedbackGenerator.swift */,
39B850752C3EA5620045CBA5 /* SwiftUI.swift */,
3751E42A2335E7CE00047E9A /* TraitCollection.swift */,
A7ED20221E83237F00BFFA01 /* TraitController.swift */,
);
Expand Down Expand Up @@ -8564,6 +8570,7 @@
A7ED20441E8323E900BFFA01 /* ResetPasswordViewControllerTests.swift in Sources */,
1965437428C811B000457EC6 /* ProjectNotificationsViewControllerTests.swift in Sources */,
A7ED20151E83229E00BFFA01 /* DiscoveryFiltersDataSourceTests.swift in Sources */,
39B850782C3EA5BB0045CBA5 /* MessageBannerViewTests.swift in Sources */,
77A3C53D219CCF1300824FC1 /* SettingsAccountDataSourceTests.swift in Sources */,
77E84E0C2166A8C600DA8891 /* MessageBannerViewControllerTests.swift in Sources */,
8A64F16624BE6528004917E2 /* RewardAddOnSelectionViewControllerTests.swift in Sources */,
Expand Down Expand Up @@ -8621,6 +8628,7 @@
8A23EF0822F11470001262E1 /* RewardCardContainerViewTests.swift in Sources */,
1965436D28C807FB00457EC6 /* PledgePaymentMethodsViewControllerTests.swift in Sources */,
D764377C224174B700DAFC9E /* SharedFunctionsTests.swift in Sources */,
39B850762C3EA5630045CBA5 /* SwiftUI.swift in Sources */,
A7ED20431E8323E900BFFA01 /* EmptyStatesViewControllerTests.swift in Sources */,
70B1889429A521000004E293 /* FacebookResetPasswordViewControllerTests.swift in Sources */,
A7ED20421E8323E900BFFA01 /* SortPagerViewControllerTests.swift in Sources */,
Expand Down