This repository was archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 387
/
Copy pathEditIssueTitleViewController.swift
80 lines (68 loc) · 2.09 KB
/
EditIssueTitleViewController.swift
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// EditIssueTitleViewController.swift
// Freetime
//
// Created by B_Litwin on 1/5/19.
// Copyright © 2019 Ryan Nystrom. All rights reserved.
//
import UIKit
import GitHubAPI
import SnapKit
import Squawk
final class EditIssueTitleViewController: UIViewController {
private let issueTitle: String
private let textView = UITextView()
public private(set) var editedIssueTitle: String?
init(issueTitle: String) {
self.issueTitle = issueTitle
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
preferredContentSize = CGSize(
width: Styles.Sizes.contextMenuSize.width,
height: 120
)
title = Constants.Strings.edit
view.addSubview(textView)
textView.snp.makeConstraints { make in
make.edges.equalTo(view)
}
textView.textContainerInset = Styles.Sizes.textViewInset
textView.text = issueTitle
navigationItem.rightBarButtonItem = UIBarButtonItem(
title: Constants.Strings.save,
style: .plain,
target: self,
action: #selector(
EditIssueTitleViewController.onSave
)
)
navigationItem.leftBarButtonItem = UIBarButtonItem(
title: Constants.Strings.cancel,
style: .plain,
target: self,
action: #selector(
EditIssueTitleViewController.onCancel
)
)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
textView.becomeFirstResponder()
}
@objc func onSave() {
textView.resignFirstResponder()
if textView.text != issueTitle {
editedIssueTitle = textView.text
}
dismiss(animated: true)
}
@objc func onCancel() {
textView.resignFirstResponder()
dismiss(animated: true)
}
}