|
|
|
@ -177,6 +177,7 @@ private final class EnterPublicKeyVC : UIViewController {
|
|
|
|
|
weak var NewDMVC: NewDMVC! |
|
|
|
|
private var isKeyboardShowing = false |
|
|
|
|
private var bottomConstraint: NSLayoutConstraint! |
|
|
|
|
private let bottomMargin: CGFloat = UIDevice.current.isIPad ? Values.largeSpacing : 0 |
|
|
|
|
|
|
|
|
|
// MARK: Components |
|
|
|
|
private lazy var publicKeyTextView: TextView = { |
|
|
|
@ -214,6 +215,10 @@ private final class EnterPublicKeyVC : UIViewController {
|
|
|
|
|
result.axis = .horizontal |
|
|
|
|
result.spacing = UIDevice.current.isIPad ? Values.iPadButtonSpacing : Values.mediumSpacing |
|
|
|
|
result.distribution = .fillEqually |
|
|
|
|
if (UIDevice.current.isIPad) { |
|
|
|
|
result.layoutMargins = UIEdgeInsets(top: 0, left: Values.iPadButtonContainerMargin, bottom: 0, right: Values.iPadButtonContainerMargin) |
|
|
|
|
result.isLayoutMarginsRelativeArrangement = true |
|
|
|
|
} |
|
|
|
|
return result |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
@ -221,6 +226,8 @@ private final class EnterPublicKeyVC : UIViewController {
|
|
|
|
|
override func viewDidLoad() { |
|
|
|
|
// Remove background color |
|
|
|
|
view.backgroundColor = .clear |
|
|
|
|
// User session id container |
|
|
|
|
let userPublicKeyContainer = UIView(wrapping: userPublicKeyLabel, withInsets: .zero, shouldAdaptForIPadWithWidth: Values.iPadUserSessionIdContainerWidth) |
|
|
|
|
// Explanation label |
|
|
|
|
let explanationLabel = UILabel() |
|
|
|
|
explanationLabel.textColor = Colors.text.withAlphaComponent(Values.mediumOpacity) |
|
|
|
@ -240,9 +247,9 @@ private final class EnterPublicKeyVC : UIViewController {
|
|
|
|
|
let nextButton = Button(style: .prominentOutline, size: .large) |
|
|
|
|
nextButton.setTitle(NSLocalizedString("next", comment: ""), for: UIControl.State.normal) |
|
|
|
|
nextButton.addTarget(self, action: #selector(startNewDMIfPossible), for: UIControl.Event.touchUpInside) |
|
|
|
|
let nextButtonContainer = UIView(wrapping: nextButton, withInsets: UIEdgeInsets(top: 0, leading: 80, bottom: 0, trailing: 80), shouldAdaptForIPad: true) |
|
|
|
|
let nextButtonContainer = UIView(wrapping: nextButton, withInsets: UIEdgeInsets(top: 0, leading: 80, bottom: 0, trailing: 80), shouldAdaptForIPadWithWidth: Values.iPadButtonWidth) |
|
|
|
|
// Main stack view |
|
|
|
|
let mainStackView = UIStackView(arrangedSubviews: [ publicKeyTextView, UIView.spacer(withHeight: Values.smallSpacing), explanationLabel, spacer1, separator, spacer2, userPublicKeyLabel, spacer3, buttonContainer, UIView.vStretchingSpacer(), nextButtonContainer ]) |
|
|
|
|
let mainStackView = UIStackView(arrangedSubviews: [ publicKeyTextView, UIView.spacer(withHeight: Values.smallSpacing), explanationLabel, spacer1, separator, spacer2, userPublicKeyContainer, spacer3, buttonContainer, UIView.vStretchingSpacer(), nextButtonContainer ]) |
|
|
|
|
mainStackView.axis = .vertical |
|
|
|
|
mainStackView.alignment = .fill |
|
|
|
|
mainStackView.layoutMargins = UIEdgeInsets(top: Values.largeSpacing, left: Values.largeSpacing, bottom: Values.largeSpacing, right: Values.largeSpacing) |
|
|
|
@ -251,7 +258,7 @@ private final class EnterPublicKeyVC : UIViewController {
|
|
|
|
|
mainStackView.pin(.leading, to: .leading, of: view) |
|
|
|
|
mainStackView.pin(.top, to: .top, of: view) |
|
|
|
|
view.pin(.trailing, to: .trailing, of: mainStackView) |
|
|
|
|
bottomConstraint = view.pin(.bottom, to: .bottom, of: mainStackView) |
|
|
|
|
bottomConstraint = view.pin(.bottom, to: .bottom, of: mainStackView, withInset: bottomMargin) |
|
|
|
|
// Width constraint |
|
|
|
|
view.set(.width, to: UIScreen.main.bounds.width) |
|
|
|
|
// Dismiss keyboard on tap |
|
|
|
@ -292,7 +299,7 @@ private final class EnterPublicKeyVC : UIViewController {
|
|
|
|
|
guard !isKeyboardShowing else { return } |
|
|
|
|
isKeyboardShowing = true |
|
|
|
|
guard let newHeight = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height else { return } |
|
|
|
|
bottomConstraint.constant = newHeight |
|
|
|
|
bottomConstraint.constant = newHeight + bottomMargin |
|
|
|
|
UIView.animate(withDuration: 0.25) { |
|
|
|
|
[ self.spacer1, self.separator, self.spacer2, self.userPublicKeyLabel, self.spacer3, self.buttonContainer ].forEach { |
|
|
|
|
$0.alpha = 0 |
|
|
|
@ -305,7 +312,7 @@ private final class EnterPublicKeyVC : UIViewController {
|
|
|
|
|
@objc private func handleKeyboardWillHideNotification(_ notification: Notification) { |
|
|
|
|
guard isKeyboardShowing else { return } |
|
|
|
|
isKeyboardShowing = false |
|
|
|
|
bottomConstraint.constant = 0 |
|
|
|
|
bottomConstraint.constant = bottomMargin |
|
|
|
|
UIView.animate(withDuration: 0.25) { |
|
|
|
|
[ self.spacer1, self.separator, self.spacer2, self.userPublicKeyLabel, self.spacer3, self.buttonContainer ].forEach { |
|
|
|
|
$0.alpha = 1 |
|
|
|
|