@@ -5,6 +5,7 @@ import UIKit
5
5
final class UserCredentialsViewController : TableViewController {
6
6
fileprivate var cells : [ UITableViewCell ]
7
7
fileprivate let headerLabel : UILabel
8
+ fileprivate var activityView : ActivityTitleView
8
9
fileprivate let cardType : CardType
9
10
10
11
fileprivate let configuration : CardCreatorConfiguration
@@ -34,6 +35,11 @@ final class UserCredentialsViewController: TableViewController {
34
35
self . cardType = cardType
35
36
36
37
self . headerLabel = UILabel ( )
38
+ self . activityView = ActivityTitleView ( title:
39
+ NSLocalizedString (
40
+ " Signing In... " ,
41
+ comment: " A title telling the user that the app is busy signing in with the new account that was just created. " ) )
42
+ self . activityView. isHidden = true
37
43
38
44
self . usernameCell = SummaryCell ( section: NSLocalizedString ( " Username " , comment: " Title of the section for the user's chosen username " ) ,
39
45
cellText: self . username)
@@ -62,6 +68,12 @@ final class UserCredentialsViewController: TableViewController {
62
68
target: self ,
63
69
action: #selector( openCatalog) )
64
70
71
+ NotificationCenter . default. addObserver (
72
+ self ,
73
+ selector: #selector( UserCredentialsViewController . signInFinished) ,
74
+ name: NSNotification . Name ( rawValue: " NYPLSettingsAccountsSignInFinishedNotification " ) ,
75
+ object: nil )
76
+
65
77
self . prepareTableViewCells ( )
66
78
}
67
79
@@ -102,31 +114,23 @@ final class UserCredentialsViewController: TableViewController {
102
114
103
115
self . tableView. estimatedRowHeight = 120
104
116
self . tableView. allowsSelection = false
105
- self . tableView. tableHeaderView = headerLabel
106
- }
107
-
108
- override func viewDidLayoutSubviews( ) {
109
- let origin_x = self . tableView. tableHeaderView!. frame. origin. x
110
- let origin_y = self . tableView. tableHeaderView!. frame. origin. y
111
- let size = self . tableView. tableHeaderView!. sizeThatFits ( CGSize ( width: self . view. bounds. width, height: CGFloat . greatestFiniteMagnitude) )
112
-
113
- let adjustedWidth = ( size. width > CGFloat ( 375 ) ) ? CGFloat ( 375.0 ) : size. width
114
- let padding = CGFloat ( 30.0 )
115
- self . headerLabel. frame = CGRect ( x: origin_x, y: origin_y, width: adjustedWidth, height: size. height + padding)
116
-
117
- self . tableView. tableHeaderView = self . headerLabel
118
117
}
119
118
120
119
override func viewDidAppear( _ animated: Bool ) {
121
120
super. viewWillAppear ( animated)
122
121
self . configuration. completionHandler ( self . username, self . pin, false )
122
+ self . activityView. isHidden = false
123
123
}
124
124
125
125
fileprivate func prepareTableViewCells( ) {
126
126
for cell in self . cells {
127
127
cell. backgroundColor = UIColor . clear
128
128
}
129
129
}
130
+
131
+ @objc fileprivate func signInFinished( ) {
132
+ self . navigationItem. titleView = nil
133
+ }
130
134
131
135
// MARK: UITableViewDataSource
132
136
@@ -142,8 +146,33 @@ final class UserCredentialsViewController: TableViewController {
142
146
return self . cells [ indexPath. section]
143
147
}
144
148
149
+ func tableView( _ tableView: UITableView , estimatedHeightForHeaderInSection section: Int ) -> CGFloat {
150
+ if section == 0 {
151
+ return 44
152
+ } else {
153
+ return 0
154
+ }
155
+ }
156
+
145
157
func tableView( _ tableView: UITableView , heightForHeaderInSection section: Int ) -> CGFloat {
146
- return 0
158
+ if section == 0 {
159
+ return UITableViewAutomaticDimension
160
+ } else {
161
+ return 0
162
+ }
163
+ }
164
+
165
+ func tableView( _ tableView: UITableView , viewForHeaderInSection section: Int ) -> UIView ? {
166
+ let containerView = UIView ( )
167
+ containerView. addSubview ( self . headerLabel)
168
+ containerView. addSubview ( self . activityView)
169
+ self . activityView. autoAlignAxis ( toSuperviewAxis: . vertical)
170
+ self . activityView. autoPinEdge ( toSuperviewEdge: . top, withInset: 16 )
171
+ self . headerLabel. autoPinEdge ( toSuperviewMargin: . left)
172
+ self . headerLabel. autoPinEdge ( toSuperviewMargin: . right)
173
+ self . headerLabel. autoPinEdge ( . top, to: . bottom, of: self . activityView, withOffset: 16 )
174
+ self . headerLabel. autoPinEdge ( toSuperviewEdge: . bottom, withInset: 20 )
175
+ return containerView
147
176
}
148
177
149
178
func tableView( _ tableView: UITableView , heightForFooterInSection section: Int ) -> CGFloat {
0 commit comments