-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from Tinkoff/bugfix/MIC-6012-sbp-flickering
[MIC-6012] Fix flickering buttons in the payment form
- Loading branch information
Showing
7 changed files
with
250 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+3.95 KB
TinkoffASDKUI/TinkoffASDKUI/Assets.xcassets/buttonIconSBP.imageset/buttonIconSBP_dark.pdf
Binary file not shown.
166 changes: 166 additions & 0 deletions
166
TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/ASDKButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
TinkoffASDKUI/TinkoffASDKUI/Buttons/Button/Button+Styles.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters