diff --git a/Example/PaymentSheet Example/PaymentSheetUITest/PaymentSheetSnapshotTests.swift b/Example/PaymentSheet Example/PaymentSheetUITest/PaymentSheetSnapshotTests.swift index f09de655c59..77ae9a6d7d2 100644 --- a/Example/PaymentSheet Example/PaymentSheetUITest/PaymentSheetSnapshotTests.swift +++ b/Example/PaymentSheet Example/PaymentSheetUITest/PaymentSheetSnapshotTests.swift @@ -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") @@ -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) diff --git a/Stripe/PaymentMethodTypeCollectionView.swift b/Stripe/PaymentMethodTypeCollectionView.swift index bc142f58c14..0d51e375f1c 100644 --- a/Stripe/PaymentMethodTypeCollectionView.swift +++ b/Stripe/PaymentMethodTypeCollectionView.swift @@ -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 @@ -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 @@ -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 diff --git a/Stripe/ShadowedRoundedRectangleView.swift b/Stripe/ShadowedRoundedRectangleView.swift index 352f3fdbe74..7373e0d78b9 100644 --- a/Stripe/ShadowedRoundedRectangleView.swift +++ b/Stripe/ShadowedRoundedRectangleView.swift @@ -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 } } diff --git a/StripeUICore/StripeUICore/Source/Categories/CALayer+StripeUICore.swift b/StripeUICore/StripeUICore/Source/Categories/CALayer+StripeUICore.swift index a3bbb006aa7..fcc6e91319c 100644 --- a/StripeUICore/StripeUICore/Source/Categories/CALayer+StripeUICore.swift +++ b/StripeUICore/StripeUICore/Source/Categories/CALayer+StripeUICore.swift @@ -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) diff --git a/StripeUICore/StripeUICore/Source/Elements/Form/FormView.swift b/StripeUICore/StripeUICore/Source/Elements/Form/FormView.swift index 2adce879998..e113e400503 100644 --- a/StripeUICore/StripeUICore/Source/Elements/Form/FormView.swift +++ b/StripeUICore/StripeUICore/Source/Elements/Form/FormView.swift @@ -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 diff --git a/StripeUICore/StripeUICore/Source/Elements/Section/SectionContainerView.swift b/StripeUICore/StripeUICore/Source/Elements/Section/SectionContainerView.swift index 19ed00fb04f..32812bdf1b2 100644 --- a/StripeUICore/StripeUICore/Source/Elements/Section/SectionContainerView.swift +++ b/StripeUICore/StripeUICore/Source/Elements/Section/SectionContainerView.swift @@ -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 } diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheet@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheet@3x.png index 09f1b3832d2..d4c90a7635d 100644 Binary files a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheet@3x.png and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheet@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetAppearance@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetAppearance@3x.png index 6831ee1520d..a0016dcd985 100644 Binary files a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetAppearance@3x.png and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetAppearance@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetCustomNilShadows@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetCustomNilShadows@3x.png new file mode 100644 index 00000000000..ef40956a7c1 Binary files /dev/null and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetCustomNilShadows@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetCustomShadow@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetCustomShadow@3x.png new file mode 100644 index 00000000000..2bbae9f21ae Binary files /dev/null and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetCustomShadow@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetDarkMode@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetDarkMode@3x.png index 3655cdc809f..74a79fb7fec 100644 Binary files a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetDarkMode@3x.png and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetDarkMode@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetDynamicType@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetDynamicType@3x.png index 8af76116ace..f48cf4671c3 100644 Binary files a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetDynamicType@3x.png and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetDynamicType@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetNilShadows@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetNilShadows@3x.png new file mode 100644 index 00000000000..bd2c8013f88 Binary files /dev/null and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetNilShadows@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetShadow@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetShadow@3x.png new file mode 100644 index 00000000000..6496f5e0a83 Binary files /dev/null and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetShadow@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLink@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLink@3x.png index c1de2beeac5..997678228b5 100644 Binary files a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLink@3x.png and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLink@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLinkAppearance@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLinkAppearance@3x.png index 1535f52e814..7ab6f3f4842 100644 Binary files a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLinkAppearance@3x.png and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLinkAppearance@3x.png differ diff --git a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLinkDarkMode@3x.png b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLinkDarkMode@3x.png index 0eae25efd53..ac436d6f564 100644 Binary files a/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLinkDarkMode@3x.png and b/Tests/ReferenceImages_64/PaymentSheetUITest.PaymentSheetSnapshotTests/testPaymentSheetWithLinkDarkMode@3x.png differ diff --git a/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardSelected@3x.png b/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardSelected@3x.png index 1361c3297be..05b49b84517 100644 Binary files a/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardSelected@3x.png and b/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardSelected@3x.png differ diff --git a/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardSelected_forceDarkMode@3x.png b/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardSelected_forceDarkMode@3x.png index b391b26aacf..4a44b342fe8 100644 Binary files a/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardSelected_forceDarkMode@3x.png and b/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardSelected_forceDarkMode@3x.png differ diff --git a/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardUnselected@3x.png b/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardUnselected@3x.png index 35cd5b22e89..3309031930f 100644 Binary files a/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardUnselected@3x.png and b/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardUnselected@3x.png differ diff --git a/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardUnselected_forceDarkMode@3x.png b/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardUnselected_forceDarkMode@3x.png index e500ce1bf3a..a76de999c6a 100644 Binary files a/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardUnselected_forceDarkMode@3x.png and b/Tests/ReferenceImages_64/StripeiOS_Tests.PaymentTypeCellSnapshotTests/testCardUnselected_forceDarkMode@3x.png differ