Skip to content

Commit

Permalink
🎨 Fix bug when shadow is nil and double apply of shadow (#1004)
Browse files Browse the repository at this point in the history
* Fix bug when shadow is nil and double apply of shadow

* Hide shadow when using `StackViewWithSeparator`

* Add shadow snapshots

* update snapshots

* resolve snapshot merge conflicts
  • Loading branch information
porter-stripe authored Apr 14, 2022
1 parent e60f3c3 commit b7212a9
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ class PaymentSheetSnapshotTests: FBSnapshotTestCase {
verify(paymentSheet.bottomSheetViewController.view!)
}

func testPaymentSheetNilShadows() {
var appearance = PaymentSheet.Appearance()
appearance.shadow = nil
appearance.borderWidth = 0.0
let requestExpectation = XCTestExpectation(description: "request expectation")
preparePaymentSheet(requestExpectation: requestExpectation, apperance: appearance)
wait(for: [requestExpectation], timeout: 20.0)
presentPaymentSheet(darkMode: false, preferredContentSizeCategory: .extraExtraLarge)
verify(paymentSheet.bottomSheetViewController.view!)
}

func testPaymentSheetShadow() {
var appearance = PaymentSheet.Appearance()
appearance.shadow = PaymentSheet.Appearance.Shadow(color: .systemRed, opacity: 0.5, offset: CGSize(width: 0, height: 2), radius: 0.5)
let requestExpectation = XCTestExpectation(description: "request expectation")
preparePaymentSheet(requestExpectation: requestExpectation, apperance: appearance)
wait(for: [requestExpectation], timeout: 20.0)
presentPaymentSheet(darkMode: false, preferredContentSizeCategory: .extraExtraLarge)
verify(paymentSheet.bottomSheetViewController.view!)
}

func testPaymentSheetCustom() {
let requestExpectation = XCTestExpectation(description: "request expectation")
preparePaymentSheet(requestExpectation: requestExpectation, customer: "snapshot")
Expand Down Expand Up @@ -106,6 +127,27 @@ class PaymentSheetSnapshotTests: FBSnapshotTestCase {
verify(paymentSheet.bottomSheetViewController.view!)
}

func testPaymentSheetCustomNilShadows() {
var appearance = PaymentSheet.Appearance()
appearance.shadow = nil
appearance.borderWidth = 0.0
let requestExpectation = XCTestExpectation(description: "request expectation")
preparePaymentSheet(requestExpectation: requestExpectation, customer: "snapshot", apperance: appearance)
wait(for: [requestExpectation], timeout: 20.0)
presentPaymentSheet(darkMode: false)
verify(paymentSheet.bottomSheetViewController.view!)
}

func testPaymentSheetCustomShadow() {
var appearance = PaymentSheet.Appearance()
appearance.shadow = PaymentSheet.Appearance.Shadow(color: .systemRed, opacity: 0.5, offset: CGSize(width: 0, height: 2), radius: 0.5)
let requestExpectation = XCTestExpectation(description: "request expectation")
preparePaymentSheet(requestExpectation: requestExpectation, customer: "snapshot", apperance: appearance)
wait(for: [requestExpectation], timeout: 20.0)
presentPaymentSheet(darkMode: false)
verify(paymentSheet.bottomSheetViewController.view!)
}

func testPaymentSheetWithLinkDarkMode() {
let requestExpectation = XCTestExpectation(description: "request expectation")
preparePaymentSheet(requestExpectation: requestExpectation, automaticPaymentMethods: false, useLink: true)
Expand Down
11 changes: 2 additions & 9 deletions Stripe/PaymentMethodTypeCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ extension PaymentMethodTypeCollectionView {
label.rightAnchor.constraint(equalTo: shadowRoundedRectangle.rightAnchor, constant: -5),
])

contentView.layer.applyShadow(theme: appearance.asElementsTheme)
contentView.layer.cornerRadius = appearance.cornerRadius
clipsToBounds = false
layer.masksToBounds = false
Expand Down Expand Up @@ -238,12 +237,10 @@ extension PaymentMethodTypeCollectionView {
// MARK: - Private Methods
private func update() {
contentView.layer.cornerRadius = appearance.cornerRadius
shadowRoundedRectangle.layer.cornerRadius = appearance.cornerRadius
shadowRoundedRectangle.roundedRectangle.layer.cornerRadius = appearance.cornerRadius
shadowRoundedRectangle.appearance = appearance
label.text = paymentMethodType.displayName

label.font = appearance.scaledFont(for: appearance.font.base.medium, style: .footnote, maximumPointSize: 20)
shadowRoundedRectangle.roundedRectangle.backgroundColor = appearance.colors.componentBackground
var image = paymentMethodType.makeImage(forDarkBackground: appearance.colors.componentBackground.contrastingColor == .white)

// tint icon primary color for a few PMs should be tinted the appearance primary color when selected
Expand All @@ -256,11 +253,7 @@ extension PaymentMethodTypeCollectionView {
paymentMethodLogoWidthConstraint.constant = paymentMethodLogoSize.height / image.size.height * image.size.width
setNeedsLayout()


// Set shadow
contentView.layer.applyShadow(theme: appearance.asElementsTheme)
shadowRoundedRectangle.shouldDisplayShadow = true


if isSelected {
// Set text color
label.textColor = appearance.colors.primary
Expand Down
3 changes: 3 additions & 0 deletions Stripe/ShadowedRoundedRectangleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class ShadowedRoundedRectangle: UIView {
var appearance: PaymentSheet.Appearance {
didSet {
layer.applyShadow(theme: appearance.asElementsTheme)
layer.cornerRadius = appearance.cornerRadius
roundedRectangle.layer.cornerRadius = appearance.cornerRadius
roundedRectangle.backgroundColor = appearance.colors.componentBackground
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import UIKit
@_spi(STP) public extension CALayer {

func applyShadow(theme: ElementsUITheme) {
guard let shadow = theme.shadow else { return }
guard let shadow = theme.shadow else {
shadowOpacity = 0
return
}

shadowColor = shadow.color.cgColor
shadowOpacity = Float(shadow.opacity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import UIKit
stack.borderColor = ElementsUITheme.current.colors.border
stack.borderCornerRadius = ElementsUITheme.current.cornerRadius
stack.spacing = ElementsUITheme.current.borderWidth
stack.hideShadow = true
stack.layer.applyShadow(theme: ElementsUITheme.current)
stack.axis = .vertical
stack.distribution = .equalSpacing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,6 @@ private func buildStackView(views: [UIView]) -> StackViewWithSeparator {
stackView.borderCornerRadius = ElementsUITheme.current.cornerRadius
stackView.customBackgroundColor = ElementsUITheme.current.colors.background
stackView.drawBorder = true
stackView.hideShadow = true // Shadow is handled by `SectionContainerView`
return stackView
}
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.
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.
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.
Binary file modified ...SheetUITest.PaymentSheetSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...ntSheetUITest.PaymentSheetSnapshotTests/[email protected]
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.
Binary file modified ...ipeiOS_Tests.PaymentTypeCellSnapshotTests/[email protected]
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.
Binary file modified ...eiOS_Tests.PaymentTypeCellSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b7212a9

Please sign in to comment.