Skip to content

Commit

Permalink
fix: Use constraints to center UIKit views
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed May 24, 2024
1 parent fcd5a4e commit 39dc98f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions MailNotificationContentExtension/NotificationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,30 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
ModelMigrator().migrateRealmIfNeeded()
SentryDebug.setUserId(accountManager.currentUserId)

activityIndicator.translatesAutoresizingMaskIntoConstraints = false
activityIndicator.hidesWhenStopped = true
activityIndicator.center = view.center
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
view.addSubview(activityIndicator)

errorLabel.isHidden = true
errorLabel.font = UIFont.preferredFont(forTextStyle: .body)
errorLabel.textAlignment = .center
errorLabel.textColor = .secondaryLabel
errorLabel.text = MailResourcesStrings.Localizable.errorMessageNotFound
errorLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(errorLabel)

NSLayoutConstraint.activate([
activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
activityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor),
errorLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
errorLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}

func stopAnimating(displayError: Bool) {
activityIndicator.stopAnimating()
if displayError {
errorLabel.sizeToFit()
errorLabel.center = view.center
view.addSubview(errorLabel)
}
errorLabel.isHidden = displayError
}

func didReceive(_ notification: UNNotification) {
Expand Down

0 comments on commit 39dc98f

Please sign in to comment.