diff --git a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportViewController.swift b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportViewController.swift index 20b29e336425..19751e8ed78c 100644 --- a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportViewController.swift +++ b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportViewController.swift @@ -227,19 +227,8 @@ final class ProblemReportViewController: UIViewController, UITextFieldDelegate { messageTextView.setContentHuggingPriority(.defaultLow, for: .vertical) messageTextView.setContentCompressionResistancePriority(.defaultLow, for: .vertical) - textFieldsHolder.addSubview(emailTextField) - textFieldsHolder.addSubview(messagePlaceholder) - textFieldsHolder.addSubview(messageTextView) - - view.addSubview(scrollView) - scrollView.addSubview(containerView) - containerView.addSubview(subheaderLabel) - containerView.addSubview(textFieldsHolder) - containerView.addSubview(buttonsStackView) - addConstraints() registerForNotifications() - loadPersistentViewModel() } @@ -345,88 +334,55 @@ final class ProblemReportViewController: UIViewController, UITextFieldDelegate { } private func addConstraints() { - activeMessageTextViewConstraints = [ - messageTextView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), - messageTextView.leadingAnchor.constraint(equalTo: view.leadingAnchor), - messageTextView.trailingAnchor.constraint(equalTo: view.trailingAnchor), - messageTextView.bottomAnchor.constraint(equalTo: view.bottomAnchor), - ] - - inactiveMessageTextViewConstraints = [ - messageTextView.topAnchor.constraint( - equalTo: emailTextField.bottomAnchor, - constant: 12 - ), - messageTextView.leadingAnchor.constraint(equalTo: textFieldsHolder.leadingAnchor), - messageTextView.trailingAnchor.constraint(equalTo: textFieldsHolder.trailingAnchor), - messageTextView.bottomAnchor.constraint(equalTo: textFieldsHolder.bottomAnchor), - ] - - var constraints = [ - subheaderLabel.topAnchor - .constraint(equalTo: containerView.layoutMarginsGuide.topAnchor), - subheaderLabel.leadingAnchor - .constraint(equalTo: containerView.layoutMarginsGuide.leadingAnchor), - subheaderLabel.trailingAnchor - .constraint(equalTo: containerView.layoutMarginsGuide.trailingAnchor), - - textFieldsHolder.topAnchor.constraint( - equalTo: subheaderLabel.bottomAnchor, - constant: 24 - ), - textFieldsHolder.leadingAnchor - .constraint(equalTo: containerView.layoutMarginsGuide.leadingAnchor), - textFieldsHolder.trailingAnchor - .constraint(equalTo: containerView.layoutMarginsGuide.trailingAnchor), - - buttonsStackView.topAnchor.constraint( - equalTo: textFieldsHolder.bottomAnchor, - constant: 18 - ), - buttonsStackView.leadingAnchor - .constraint(equalTo: containerView.layoutMarginsGuide.leadingAnchor), - buttonsStackView.trailingAnchor - .constraint(equalTo: containerView.layoutMarginsGuide.trailingAnchor), - buttonsStackView.bottomAnchor - .constraint(equalTo: containerView.layoutMarginsGuide.bottomAnchor), - - emailTextField.topAnchor.constraint(equalTo: textFieldsHolder.topAnchor), - emailTextField.leadingAnchor.constraint(equalTo: textFieldsHolder.leadingAnchor), - emailTextField.trailingAnchor.constraint(equalTo: textFieldsHolder.trailingAnchor), - - messagePlaceholder.topAnchor.constraint( - equalTo: emailTextField.bottomAnchor, - constant: 12 - ), - messagePlaceholder.leadingAnchor.constraint(equalTo: textFieldsHolder.leadingAnchor), - messagePlaceholder.trailingAnchor.constraint(equalTo: textFieldsHolder.trailingAnchor), - messagePlaceholder.bottomAnchor.constraint(equalTo: textFieldsHolder.bottomAnchor), - messagePlaceholder.heightAnchor.constraint(equalTo: messageTextView.heightAnchor), - - scrollView.frameLayoutGuide.topAnchor.constraint(equalTo: view.topAnchor), - scrollView.frameLayoutGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor), - scrollView.frameLayoutGuide.leadingAnchor.constraint(equalTo: view.leadingAnchor), - scrollView.frameLayoutGuide.trailingAnchor.constraint(equalTo: view.trailingAnchor), - - scrollView.contentLayoutGuide.topAnchor.constraint(equalTo: containerView.topAnchor), - scrollView.contentLayoutGuide.bottomAnchor - .constraint(equalTo: containerView.bottomAnchor), - scrollView.contentLayoutGuide.leadingAnchor - .constraint(equalTo: containerView.leadingAnchor), - scrollView.contentLayoutGuide.trailingAnchor - .constraint(equalTo: containerView.trailingAnchor), - - scrollView.contentLayoutGuide.widthAnchor - .constraint(equalTo: scrollView.frameLayoutGuide.widthAnchor), - scrollView.contentLayoutGuide.heightAnchor - .constraint(greaterThanOrEqualTo: scrollView.safeAreaLayoutGuide.heightAnchor), + activeMessageTextViewConstraints = + messageTextView.pinEdges(.all().excluding(.top), to: view) + + messageTextView.pinEdges(PinnableEdges([.top(0)]), to: view.safeAreaLayoutGuide) - messageTextView.heightAnchor.constraint(greaterThanOrEqualToConstant: 150), - ] + inactiveMessageTextViewConstraints = + messageTextView.pinEdges(.all().excluding(.top), to: textFieldsHolder) + + [messageTextView.topAnchor.constraint(equalTo: emailTextField.bottomAnchor, constant: 12)] - constraints.append(contentsOf: inactiveMessageTextViewConstraints) + textFieldsHolder.addSubview(emailTextField) + textFieldsHolder.addSubview(messagePlaceholder) + textFieldsHolder.addSubview(messageTextView) + + scrollView.addSubview(containerView) + containerView.addSubview(subheaderLabel) + containerView.addSubview(textFieldsHolder) + containerView.addSubview(buttonsStackView) + + view.addConstrainedSubviews([scrollView]) { + inactiveMessageTextViewConstraints + + subheaderLabel.pinEdges(.all().excluding(.bottom), to: containerView.layoutMarginsGuide) - NSLayoutConstraint.activate(constraints) + textFieldsHolder.pinEdges(PinnableEdges([.leading(0), .trailing(0)]), to: containerView.layoutMarginsGuide) + textFieldsHolder.topAnchor.constraint(equalTo: subheaderLabel.bottomAnchor, constant: 24) + + buttonsStackView.pinEdges(.all().excluding(.top), to: containerView.layoutMarginsGuide) + buttonsStackView.topAnchor.constraint(equalTo: textFieldsHolder.bottomAnchor, constant: 18) + + emailTextField.pinEdges(.all().excluding(.bottom), to: textFieldsHolder) + + messagePlaceholder.pinEdges(.all().excluding(.top), to: textFieldsHolder) + messagePlaceholder.topAnchor.constraint(equalTo: emailTextField.bottomAnchor, constant: 12) + messagePlaceholder.heightAnchor.constraint(equalTo: messageTextView.heightAnchor) + + scrollView.frameLayoutGuide.topAnchor.constraint(equalTo: view.topAnchor) + scrollView.frameLayoutGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor) + scrollView.frameLayoutGuide.leadingAnchor.constraint(equalTo: view.leadingAnchor) + scrollView.frameLayoutGuide.trailingAnchor.constraint(equalTo: view.trailingAnchor) + + scrollView.contentLayoutGuide.topAnchor.constraint(equalTo: containerView.topAnchor) + scrollView.contentLayoutGuide.bottomAnchor.constraint(equalTo: containerView.bottomAnchor) + scrollView.contentLayoutGuide.leadingAnchor.constraint(equalTo: containerView.leadingAnchor) + scrollView.contentLayoutGuide.trailingAnchor.constraint(equalTo: containerView.trailingAnchor) + scrollView.contentLayoutGuide.widthAnchor.constraint(equalTo: scrollView.frameLayoutGuide.widthAnchor) + scrollView.contentLayoutGuide.heightAnchor + .constraint(greaterThanOrEqualTo: scrollView.safeAreaLayoutGuide.heightAnchor) + + messageTextView.heightAnchor.constraint(greaterThanOrEqualToConstant: 150) + } } private func setDescriptionFieldExpanded(_ isExpanded: Bool) {