Re-enable loading-indicator for server-picker (#690)

This commit is contained in:
Nathan Mattes 2022-12-18 12:20:49 +01:00
parent 62fe8d5881
commit bb4706d826
2 changed files with 37 additions and 2 deletions

View File

@ -174,7 +174,11 @@ extension MastodonPickServerViewController {
.receive(on: DispatchQueue.main)
.sink { [weak self] isAuthenticating in
guard let self = self else { return }
// isAuthenticating ? self.navigationActionView.nextButton.showLoading() : self.navigationActionView.nextButton.stopLoading()
if isAuthenticating {
self.onboardingNextView.showLoading()
} else {
self.onboardingNextView.stopLoading()
}
}
.store(in: &disposeBag)

View File

@ -13,7 +13,6 @@ import MastodonLocalization
final class OnboardingNextView: UIView {
static let buttonHeight: CGFloat = 50
static let minimumBackButtonWidth: CGFloat = 100
private var observations = Set<NSKeyValueObservation>()
@ -44,6 +43,14 @@ final class OnboardingNextView: UIView {
return label
}()
lazy var activityIndicator: UIActivityIndicatorView = {
let indicator = UIActivityIndicatorView(style: .medium)
indicator.color = .white
indicator.translatesAutoresizingMaskIntoConstraints = false
return indicator
}()
private var isLoading: Bool = false
override init(frame: CGRect) {
super.init(frame: frame)
_init()
@ -75,5 +82,29 @@ final class OnboardingNextView: UIView {
nextButton.heightAnchor.constraint(greaterThanOrEqualToConstant: NavigationActionView.buttonHeight)
])
}
func showLoading() {
guard isLoading == false else { return }
nextButton.isEnabled = false
isLoading = true
nextButton.setTitle("", for: .disabled)
nextButton.addSubview(activityIndicator)
NSLayoutConstraint.activate([
activityIndicator.centerXAnchor.constraint(equalTo: nextButton.centerXAnchor),
activityIndicator.centerYAnchor.constraint(equalTo: nextButton.centerYAnchor),
])
activityIndicator.startAnimating()
}
func stopLoading() {
guard isLoading else { return }
isLoading = false
if activityIndicator.superview == nextButton {
activityIndicator.removeFromSuperview()
}
nextButton.isEnabled = true
nextButton.setTitle(L10n.Common.Controls.Actions.next, for: .disabled)
}
}