Skip to content

Commit

Permalink
Merge pull request #141 from Tinkoff/bugfix/MIC-6012-sbp-flickering
Browse files Browse the repository at this point in the history
[MIC-6012] Fix flickering buttons in the payment form
  • Loading branch information
akhaman authored Aug 5, 2022
2 parents d013a9a + d641779 commit c4616b0
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
## [Unreleased]

### Fixed

* [MIC-6021] Fix logger's crash
* [MIC-6012] Flickering buttons in the payment form

## [2.8.0] - 2022-07-04

Expand Down
33 changes: 19 additions & 14 deletions TinkoffASDKUI/TinkoffASDKUI/AcquiringPaymentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ class AcquiringPaymentViewController: PopUpViewContoller {
guard case let .allowed(version: version) = tinkoffPayStatus else { return }
onTinkoffPayButton?(version, self)
}

@objc private func sbpButtonTapped() {
onTouchButtonSBP?(self)
}
}

extension AcquiringPaymentViewController: UITableViewDataSource {
Expand Down Expand Up @@ -506,20 +510,13 @@ extension AcquiringPaymentViewController: UITableViewDataSource {
}

case .buttonPaySBP:
if let cell = tableView.dequeueReusableCell(withIdentifier: "ButtonTableViewCell") as? ButtonTableViewCell {
cell.buttonAction.setTitle(AcqLoc.instance.localize("TinkoffAcquiring.button.payBy"), for: .normal)
cell.buttonAction.tintColor = UIColor.asdk.dynamic.button.sbp.tint
cell.buttonAction.backgroundColor = UIColor.asdk.dynamic.button.sbp.background
cell.setButtonIcon(UIImage(named: "buttonIconSBP", in: .uiResources, compatibleWith: nil))

cell.onButtonTouch = { [weak self] in
guard let self = self else { return }
self.onTouchButtonSBP?(self)
}

return cell
guard let cell = tableView.dequeueReusableCell(withIdentifier: ContainerTableViewCell.reuseIdentifier) as? ContainerTableViewCell else {
break
}

let button = ASDKButton(style: .sbpPayment)
button.addTarget(self, action: #selector(sbpButtonTapped), for: .touchUpInside)
cell.setContent(button, insets: .buttonInContainerInsets)
return cell
case .secureLogos:
if let cell = tableView.dequeueReusableCell(withIdentifier: "PSLogoTableViewCell") as? PSLogoTableViewCell {
return cell
Expand Down Expand Up @@ -550,7 +547,7 @@ extension AcquiringPaymentViewController: UITableViewDataSource {
btn.addTarget(self,
action: #selector(handleTinkoffPayButtonTouch),
for: .touchUpInside)
cell.setContent(btn, insets: UIEdgeInsets(top: 7, left: 20, bottom: 7, right: 20))
cell.setContent(btn, insets: .buttonInContainerInsets)
return cell
}
}
Expand Down Expand Up @@ -681,3 +678,11 @@ extension AcquiringPaymentViewController: AcquiringPaymentControllerDelegate {
onInitFinished?(result)
}
}

// MARK: - UIEdgeInsets + Constants

private extension UIEdgeInsets {
static var buttonInContainerInsets: UIEdgeInsets {
UIEdgeInsets(top: 7, left: 20, bottom: 7, right: 20)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
{
"filename" : "buttonIconSBP.pdf",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "buttonIconSBP_dark.pdf",
"idiom" : "universal"
}
],
"info" : {
Expand Down
Binary file not shown.
166 changes: 166 additions & 0 deletions TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/ASDKButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
//
//
// ASDKButton.swift
//
// Copyright (c) 2021 Tinkoff Bank
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//


import Foundation

final class ASDKButton: UIButton {
// MARK: Style

struct Style {
struct Border {
let cornerRadius: CGFloat
let width: CGFloat
let color: UIColor

init(
cornerRadius: CGFloat = .zero,
width: CGFloat = .zero,
color: UIColor = .clear
) {
self.cornerRadius = cornerRadius
self.width = width
self.color = color
}
}

struct Title {
let text: String
let color: UIColor
let font: UIFont
let transform: CGAffineTransform

init(
text: String,
color: UIColor = .asdk.textPrimary,
font: UIFont = .systemFont(ofSize: 15, weight: .regular),
transform: CGAffineTransform = .identity
) {
self.text = text
self.color = color
self.font = font
self.transform = transform
}
}

struct Icon {
let image: UIImage?
let transform: CGAffineTransform

init(image: UIImage? = nil, transform: CGAffineTransform = .identity) {
self.image = image
self.transform = transform
}
}

struct IntrinsicSize {
let height: CGFloat?
let width: CGFloat?

init(height: CGFloat? = nil, width: CGFloat? = nil) {
self.height = height
self.width = width
}
}

let title: Title
let icon: Icon?
let border: Border
let size: IntrinsicSize?
let backgroundColor: UIColor
let tintColor: UIColor
let transform: CGAffineTransform

init(
title: Title,
icon: Icon? = nil,
border: Border = Border(),
size: IntrinsicSize? = nil,
backgroundColor: UIColor,
tintColor: UIColor,
transform: CGAffineTransform = .identity
) {
self.title = title
self.icon = icon
self.border = border
self.size = size
self.backgroundColor = backgroundColor
self.tintColor = tintColor
self.transform = transform
}
}

// MARK: Parents Properties

override var intrinsicContentSize: CGSize {
var size = super.intrinsicContentSize
style.size?.height.map { size.height = $0 }
style.size?.width.map { size.width = $0 }
return size
}

// MARK: Properties

private let style: Style

// MARK: Init

init(style: Style) {
self.style = style
super.init(frame: .zero)
setup()
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: Parent Methods

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
updateBorderColors()
}

// MARK: Initial Configuration

private func setup() {
setTitle(style.title.text, for: .normal)
setTitleColor(style.title.color, for: .normal)
setTitleColor(style.tintColor, for: .highlighted)
titleLabel?.font = style.title.font
titleLabel?.transform = style.title.transform

setImage(style.icon?.image, for: .normal)
imageView?.transform = style.icon?.transform ?? .identity

layer.cornerRadius = style.border.cornerRadius
layer.borderWidth = style.border.width
updateBorderColors()

backgroundColor = style.backgroundColor
transform = style.transform

}

private func updateBorderColors() {
layer.borderColor = style.border.color.cgColor
}
}
52 changes: 52 additions & 0 deletions TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/Button+Styles.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
//
// Button+Styles.swift
//
// Copyright (c) 2021 Tinkoff Bank
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//


import Foundation

extension ASDKButton.Style {
static var sbpPayment: ASDKButton.Style {
ASDKButton.Style(
title: Title(
text: AcqLoc.instance.localize("TinkoffAcquiring.button.payBy"),
color: .asdk.dynamic.background.elevation1,
transform: CGAffineTransform(scaleX: -1.0, y: 1.0)
),
icon: Icon(
image: UIImage(named: "buttonIconSBP", in: .uiResources, compatibleWith: nil),
transform: CGAffineTransform(scaleX: -1.0, y: 1.0)
),
border: Border(cornerRadius: 4, width: 1, color: .borderColor),
size: IntrinsicSize(height: 44),
backgroundColor: .asdk.dynamic.button.sbp.background,
tintColor: .asdk.dynamic.button.sbp.tint.withAlphaComponent(0.7),
transform: CGAffineTransform(scaleX: -1.0, y: 1.0)
)
}
}

private extension UIColor {
static var borderColor: UIColor {
if #available(iOS 13.0, *) {
return UIColor.systemBackground
} else {
return UIColor.white
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ final class ContainerTableViewCell: UITableViewCell, ReusableCell {

private extension ContainerTableViewCell {
func setup() {
selectionStyle = .none
contentView.addSubview(containerView)
containerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
Expand Down

0 comments on commit c4616b0

Please sign in to comment.