-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
@testable import Kickstarter_Framework | ||
// @testable import KsApi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like we can remove this import for now There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
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(()) | ||
} | ||
} |
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()) | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.