-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProductViewController.swift
More file actions
66 lines (52 loc) · 1.97 KB
/
ProductViewController.swift
File metadata and controls
66 lines (52 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// ProductViewController.swift
// RoutingExample
//
// Created by Cassius Pacheco on 7/3/20.
// Copyright © 2020 Cassius Pacheco. All rights reserved.
//
import UIKit
import IntentsUI
final class ProductViewController: UIViewController {
private let viewModel: ProductViewModelInterface
init(viewModel: ProductViewModelInterface) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
print("👶 \(self) Created")
let wishlistButton = DefaultButton(title: "Add to Wishlist", target: self, selector: #selector(wishlistButtonTouchUpInside))
let productButton = DefaultButton(title: "Open another Product", target: self, selector: #selector(productButtonTouchUpInside))
let vStack = UIStackView(arrangedSubviews: [wishlistButton, productButton])
vStack.axis = .vertical
vStack.spacing = 8.0
view.addSubview(vStack)
vStack.layout.center(in: view)
createAddToSiriButton()
}
private func createAddToSiriButton() {
// Note that this is a useless intent. The idea is just to show the concept working.
let intent = AddToWishlistIntent()
intent.name = "Test"
let shortcutButton = INUIAddVoiceShortcutButton(style: .whiteOutline)
shortcutButton.shortcut = INShortcut(intent: intent)
shortcutButton.delegate = viewModel.siriButtonDelegate
navigationItem.setRightBarButton(UIBarButtonItem(customView: shortcutButton), animated: true)
}
@objc
private func productButtonTouchUpInside() {
viewModel.productButtonTouchUpInside()
}
@objc
private func wishlistButtonTouchUpInside() {
viewModel.wishlistButtonTouchUpInside()
}
deinit {
print("♻️ \(self) Deallocated")
}
}