diff --git a/CHANGELOG.md b/CHANGELOG.md index b96aff8dc..86d8bb696 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/TinkoffASDKUI/TinkoffASDKUI/AcquiringPaymentViewController.swift b/TinkoffASDKUI/TinkoffASDKUI/AcquiringPaymentViewController.swift index f82d467e4..866bdd1b9 100755 --- a/TinkoffASDKUI/TinkoffASDKUI/AcquiringPaymentViewController.swift +++ b/TinkoffASDKUI/TinkoffASDKUI/AcquiringPaymentViewController.swift @@ -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 { @@ -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 @@ -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 } } @@ -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) + } +} diff --git a/TinkoffASDKUI/TinkoffASDKUI/Assets.xcassets/buttonIconSBP.imageset/Contents.json b/TinkoffASDKUI/TinkoffASDKUI/Assets.xcassets/buttonIconSBP.imageset/Contents.json index 19b0b1bfd..fa7a832a2 100644 --- a/TinkoffASDKUI/TinkoffASDKUI/Assets.xcassets/buttonIconSBP.imageset/Contents.json +++ b/TinkoffASDKUI/TinkoffASDKUI/Assets.xcassets/buttonIconSBP.imageset/Contents.json @@ -3,6 +3,16 @@ { "filename" : "buttonIconSBP.pdf", "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "filename" : "buttonIconSBP_dark.pdf", + "idiom" : "universal" } ], "info" : { diff --git a/TinkoffASDKUI/TinkoffASDKUI/Assets.xcassets/buttonIconSBP.imageset/buttonIconSBP_dark.pdf b/TinkoffASDKUI/TinkoffASDKUI/Assets.xcassets/buttonIconSBP.imageset/buttonIconSBP_dark.pdf new file mode 100644 index 000000000..e68b91d8f Binary files /dev/null and b/TinkoffASDKUI/TinkoffASDKUI/Assets.xcassets/buttonIconSBP.imageset/buttonIconSBP_dark.pdf differ diff --git a/TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/ASDKButton.swift b/TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/ASDKButton.swift new file mode 100644 index 000000000..07cb8b5ef --- /dev/null +++ b/TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/ASDKButton.swift @@ -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 + } +} diff --git a/TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/Button+Styles.swift b/TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/Button+Styles.swift new file mode 100644 index 000000000..2edcea227 --- /dev/null +++ b/TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/Button+Styles.swift @@ -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 + } + } +} diff --git a/TinkoffASDKUI/TinkoffASDKUI/Cells/ContainerTableViewCell.swift b/TinkoffASDKUI/TinkoffASDKUI/Cells/ContainerTableViewCell.swift index 28e9845ed..397319da6 100644 --- a/TinkoffASDKUI/TinkoffASDKUI/Cells/ContainerTableViewCell.swift +++ b/TinkoffASDKUI/TinkoffASDKUI/Cells/ContainerTableViewCell.swift @@ -63,6 +63,7 @@ final class ContainerTableViewCell: UITableViewCell, ReusableCell { private extension ContainerTableViewCell { func setup() { + selectionStyle = .none contentView.addSubview(containerView) containerView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([