|
7 | 7 | // |
8 | 8 |
|
9 | 9 | import AsyncDisplayKit |
| 10 | +import UIKit |
10 | 11 |
|
11 | 12 | public final class AddButtonNode: ASButtonNode { |
12 | 13 | private var onTap: (() -> Void)? |
| 14 | + private var identifier: String? |
| 15 | + |
| 16 | + override public init() { |
| 17 | + super.init() |
| 18 | + setViewBlock { UIButton(type: .system) } |
| 19 | + } |
13 | 20 |
|
14 | 21 | public init(identifier: String, _ action: (() -> Void)?) { |
| 22 | + self.identifier = identifier |
15 | 23 | super.init() |
| 24 | + |
| 25 | + setViewBlock { UIButton(type: .system) } |
16 | 26 | onTap = action |
17 | | - backgroundColor = .main |
18 | | - accessibilityIdentifier = identifier |
19 | | - setTitle("+", with: .boldSystemFont(ofSize: 30), with: .white, for: .normal) |
20 | | - addTarget(self, action: #selector(onButtonTap), forControlEvents: .touchUpInside) |
21 | 27 | frame.size = CGSize(width: .addButtonSize, height: .addButtonSize) |
22 | | - cornerRadius = .addButtonSize / 2 |
| 28 | + } |
| 29 | + |
| 30 | + override public func didLoad() { |
| 31 | + super.didLoad() |
| 32 | + |
| 33 | + guard let button = view as? UIButton else { return } |
| 34 | + button.accessibilityIdentifier = identifier |
| 35 | + button.isAccessibilityElement = true |
| 36 | + button.addTarget(self, action: #selector(onButtonTap), for: .touchUpInside) |
| 37 | + |
| 38 | + if #available(iOS 26.0, *) { |
| 39 | + configureGlassButton(button) |
| 40 | + } else { |
| 41 | + configureLegacyButton(button) |
| 42 | + } |
23 | 43 | } |
24 | 44 |
|
25 | 45 | @objc private func onButtonTap() { |
26 | 46 | onTap?() |
27 | 47 | } |
| 48 | + |
| 49 | + @available(iOS 26.0, *) |
| 50 | + private func configureGlassButton(_ button: UIButton) { |
| 51 | + var configuration = UIButton.Configuration.glass() |
| 52 | + configuration.buttonSize = .medium |
| 53 | + configuration.cornerStyle = .capsule |
| 54 | + configuration.image = UIImage(systemName: "plus") |
| 55 | + configuration.preferredSymbolConfigurationForImage = .init( |
| 56 | + pointSize: 24, |
| 57 | + weight: .semibold |
| 58 | + ) |
| 59 | + |
| 60 | + button.configuration = configuration |
| 61 | + } |
| 62 | + |
| 63 | + private func configureLegacyButton(_ button: UIButton) { |
| 64 | + button.backgroundColor = .main |
| 65 | + button.layer.cornerRadius = .addButtonSize / 2 |
| 66 | + button.setTitle("+", for: .normal) |
| 67 | + button.setTitleColor(.white, for: .normal) |
| 68 | + button.titleLabel?.font = .boldSystemFont(ofSize: 30) |
| 69 | + } |
28 | 70 | } |
0 commit comments