fix bottom margin & copy/share button width

pull/565/head
Ryan Zhao 3 years ago
parent c08b1617c2
commit 23508fb936

@ -177,6 +177,7 @@ private final class EnterPublicKeyVC : UIViewController {
weak var NewDMVC: NewDMVC! weak var NewDMVC: NewDMVC!
private var isKeyboardShowing = false private var isKeyboardShowing = false
private var bottomConstraint: NSLayoutConstraint! private var bottomConstraint: NSLayoutConstraint!
private let bottomMargin: CGFloat = UIDevice.current.isIPad ? Values.largeSpacing : 0
// MARK: Components // MARK: Components
private lazy var publicKeyTextView: TextView = { private lazy var publicKeyTextView: TextView = {
@ -214,6 +215,11 @@ private final class EnterPublicKeyVC : UIViewController {
result.axis = .horizontal result.axis = .horizontal
result.spacing = UIDevice.current.isIPad ? Values.iPadButtonSpacing : Values.mediumSpacing result.spacing = UIDevice.current.isIPad ? Values.iPadButtonSpacing : Values.mediumSpacing
result.distribution = .fillEqually result.distribution = .fillEqually
if (UIDevice.current.isIPad) {
let margin = (UIScreen.main.bounds.width - result.spacing - Values.iPadButtonWidth * 2) / 2
result.layoutMargins = UIEdgeInsets(top: 0, left: margin, bottom: 0, right: margin)
result.isLayoutMarginsRelativeArrangement = true
}
return result return result
}() }()
@ -251,7 +257,7 @@ private final class EnterPublicKeyVC : UIViewController {
mainStackView.pin(.leading, to: .leading, of: view) mainStackView.pin(.leading, to: .leading, of: view)
mainStackView.pin(.top, to: .top, of: view) mainStackView.pin(.top, to: .top, of: view)
view.pin(.trailing, to: .trailing, of: mainStackView) 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 // Width constraint
view.set(.width, to: UIScreen.main.bounds.width) view.set(.width, to: UIScreen.main.bounds.width)
// Dismiss keyboard on tap // Dismiss keyboard on tap
@ -292,7 +298,7 @@ private final class EnterPublicKeyVC : UIViewController {
guard !isKeyboardShowing else { return } guard !isKeyboardShowing else { return }
isKeyboardShowing = true isKeyboardShowing = true
guard let newHeight = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height else { return } 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) { UIView.animate(withDuration: 0.25) {
[ self.spacer1, self.separator, self.spacer2, self.userPublicKeyLabel, self.spacer3, self.buttonContainer ].forEach { [ self.spacer1, self.separator, self.spacer2, self.userPublicKeyLabel, self.spacer3, self.buttonContainer ].forEach {
$0.alpha = 0 $0.alpha = 0
@ -305,7 +311,7 @@ private final class EnterPublicKeyVC : UIViewController {
@objc private func handleKeyboardWillHideNotification(_ notification: Notification) { @objc private func handleKeyboardWillHideNotification(_ notification: Notification) {
guard isKeyboardShowing else { return } guard isKeyboardShowing else { return }
isKeyboardShowing = false isKeyboardShowing = false
bottomConstraint.constant = 0 bottomConstraint.constant = bottomMargin
UIView.animate(withDuration: 0.25) { UIView.animate(withDuration: 0.25) {
[ self.spacer1, self.separator, self.spacer2, self.userPublicKeyLabel, self.spacer3, self.buttonContainer ].forEach { [ self.spacer1, self.separator, self.spacer2, self.userPublicKeyLabel, self.spacer3, self.buttonContainer ].forEach {
$0.alpha = 1 $0.alpha = 1

@ -168,6 +168,9 @@ final class JoinOpenGroupVC : BaseVC, UIPageViewControllerDataSource, UIPageView
private final class EnterURLVC : UIViewController, UIGestureRecognizerDelegate, OpenGroupSuggestionGridDelegate { private final class EnterURLVC : UIViewController, UIGestureRecognizerDelegate, OpenGroupSuggestionGridDelegate {
weak var joinOpenGroupVC: JoinOpenGroupVC! weak var joinOpenGroupVC: JoinOpenGroupVC!
private var isKeyboardShowing = false
private var bottomConstraint: NSLayoutConstraint!
private let bottomMargin: CGFloat = UIDevice.current.isIPad ? Values.largeSpacing : 0
// MARK: Components // MARK: Components
private lazy var urlTextView: TextView = { private lazy var urlTextView: TextView = {
@ -209,13 +212,24 @@ private final class EnterURLVC : UIViewController, UIGestureRecognizerDelegate,
stackView.layoutMargins = UIEdgeInsets(uniform: Values.largeSpacing) stackView.layoutMargins = UIEdgeInsets(uniform: Values.largeSpacing)
stackView.isLayoutMarginsRelativeArrangement = true stackView.isLayoutMarginsRelativeArrangement = true
view.addSubview(stackView) view.addSubview(stackView)
stackView.pin(to: view) stackView.pin(.leading, to: .leading, of: view)
stackView.pin(.top, to: .top, of: view)
view.pin(.trailing, to: .trailing, of: stackView)
bottomConstraint = view.pin(.bottom, to: .bottom, of: stackView, withInset: bottomMargin)
// Constraints // Constraints
view.set(.width, to: UIScreen.main.bounds.width) view.set(.width, to: UIScreen.main.bounds.width)
// Dismiss keyboard on tap // Dismiss keyboard on tap
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
tapGestureRecognizer.delegate = self tapGestureRecognizer.delegate = self
view.addGestureRecognizer(tapGestureRecognizer) view.addGestureRecognizer(tapGestureRecognizer)
// Listen to keyboard notifications
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(handleKeyboardWillChangeFrameNotification(_:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
notificationCenter.addObserver(self, selector: #selector(handleKeyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
} }
// MARK: General // MARK: General
@ -241,6 +255,26 @@ private final class EnterURLVC : UIViewController, UIGestureRecognizerDelegate,
let url = urlTextView.text?.trimmingCharacters(in: .whitespaces) ?? "" let url = urlTextView.text?.trimmingCharacters(in: .whitespaces) ?? ""
joinOpenGroupVC.joinOpenGroup(with: url) joinOpenGroupVC.joinOpenGroup(with: url)
} }
// MARK: Updating
@objc private func handleKeyboardWillChangeFrameNotification(_ notification: Notification) {
guard !isKeyboardShowing else { return }
isKeyboardShowing = true
guard let newHeight = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height else { return }
bottomConstraint.constant = newHeight + bottomMargin
UIView.animate(withDuration: 0.25) {
self.view.layoutIfNeeded()
}
}
@objc private func handleKeyboardWillHideNotification(_ notification: Notification) {
guard isKeyboardShowing else { return }
isKeyboardShowing = false
bottomConstraint.constant = bottomMargin
UIView.animate(withDuration: 0.25) {
self.view.layoutIfNeeded()
}
}
} }
private final class ScanQRCodePlaceholderVC : UIViewController { private final class ScanQRCodePlaceholderVC : UIViewController {

@ -175,6 +175,11 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
buttonContainer.axis = .horizontal buttonContainer.axis = .horizontal
buttonContainer.spacing = UIDevice.current.isIPad ? Values.iPadButtonSpacing : Values.mediumSpacing buttonContainer.spacing = UIDevice.current.isIPad ? Values.iPadButtonSpacing : Values.mediumSpacing
buttonContainer.distribution = .fillEqually buttonContainer.distribution = .fillEqually
if (UIDevice.current.isIPad) {
let margin = (UIScreen.main.bounds.width - buttonContainer.spacing - Values.iPadButtonWidth * 2) / 2
buttonContainer.layoutMargins = UIEdgeInsets(top: 0, left: margin, bottom: 0, right: margin)
buttonContainer.isLayoutMarginsRelativeArrangement = true
}
// Top stack view // Top stack view
let topStackView = UIStackView(arrangedSubviews: [ headerStackView, separator, publicKeyLabel, buttonContainer ]) let topStackView = UIStackView(arrangedSubviews: [ headerStackView, separator, publicKeyLabel, buttonContainer ])
topStackView.axis = .vertical topStackView.axis = .vertical

Loading…
Cancel
Save