fix NewDMVC

pull/699/head
Ryan Zhao 2 years ago
parent 1865f90426
commit 27214e8478

@ -92,36 +92,41 @@ final class NewDMVC: BaseVC, UIPageViewControllerDataSource, UIPageViewControlle
navigationItem.leftBarButtonItem = closeButton navigationItem.leftBarButtonItem = closeButton
} }
// Set up tab bar // Page VC
view.addSubview(tabBar)
tabBar.pin(.top, to: .top, of: view)
tabBar.pin(.leading, to: .leading, of: view)
tabBar.pin(.trailing, to: .trailing, of: view)
// Set up page VC
let containerView: UIView = UIView()
view.addSubview(containerView)
containerView.pin(.top, to: .bottom, of: tabBar)
containerView.pin(.leading, to: .leading, of: view)
containerView.pin(.trailing, to: .trailing, of: view)
containerView.pin(.bottom, to: .bottom, of: view)
let hasCameraAccess = (AVCaptureDevice.authorizationStatus(for: .video) == .authorized) let hasCameraAccess = (AVCaptureDevice.authorizationStatus(for: .video) == .authorized)
pages = [ enterPublicKeyVC, (hasCameraAccess ? scanQRCodeWrapperVC : scanQRCodePlaceholderVC) ] pages = [ enterPublicKeyVC, (hasCameraAccess ? scanQRCodeWrapperVC : scanQRCodePlaceholderVC) ]
pageVC.dataSource = self pageVC.dataSource = self
pageVC.delegate = self pageVC.delegate = self
pageVC.setViewControllers([ enterPublicKeyVC ], direction: .forward, animated: false, completion: nil) pageVC.setViewControllers([ enterPublicKeyVC ], direction: .forward, animated: false, completion: nil)
addChild(pageVC)
containerView.addSubview(pageVC.view)
pageVC.view.pin(to: containerView) // Tab bar
pageVC.didMove(toParent: self) view.addSubview(tabBar)
tabBar.pin(.top, to: .top, of: view)
tabBar.pin(.leading, to: .leading, of: view)
tabBar.pin(.trailing, to: .trailing, of: view)
// Page VC constraints
let pageVCView = pageVC.view!
view.addSubview(pageVCView)
pageVCView.pin(.leading, to: .leading, of: view)
pageVCView.pin(.top, to: .bottom, of: tabBar)
pageVCView.pin(.trailing, to: .trailing, of: view)
pageVCView.pin(.bottom, to: .bottom, of: view)
let navBarHeight: CGFloat = (navigationController?.navigationBar.frame.size.height ?? 0)
let statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.size.height
let height: CGFloat = ((navigationController?.view.bounds.height ?? 0) - navBarHeight - TabBar.snHeight - statusBarHeight)
let size: CGSize = CGSize(width: UIScreen.main.bounds.width, height: height)
enterPublicKeyVC.constrainSize(to: size)
scanQRCodePlaceholderVC.constrainSize(to: size)
} }
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator) super.viewWillTransition(to: size, with: coordinator)
enterPublicKeyVC.viewWidth?.constant = size.width let height: CGFloat = (size.height - TabBar.snHeight)
scanQRCodePlaceholderVC.viewWidth?.constant = size.width let size: CGSize = CGSize(width: size.width, height: height)
enterPublicKeyVC.constrainSize(to: size)
scanQRCodePlaceholderVC.constrainSize(to: size)
} }
// MARK: - General // MARK: - General
@ -400,7 +405,8 @@ private final class EnterPublicKeyVC: UIViewController {
return result return result
}() }()
var viewWidth: NSLayoutConstraint? private var viewWidth: NSLayoutConstraint?
private var viewHeight: NSLayoutConstraint?
// MARK: - Lifecycle // MARK: - Lifecycle
@ -436,9 +442,7 @@ private final class EnterPublicKeyVC: UIViewController {
view.addSubview(mainStackView) view.addSubview(mainStackView)
mainStackView.pin([ UIView.HorizontalEdge.leading, UIView.HorizontalEdge.trailing, UIView.VerticalEdge.top ], to: view) mainStackView.pin([ UIView.HorizontalEdge.leading, UIView.HorizontalEdge.trailing, UIView.VerticalEdge.top ], to: view)
bottomConstraint = view.pin(.bottom, to: .bottom, of: mainStackView, withInset: bottomMargin) bottomConstraint = mainStackView.pin(.bottom, to: .bottom, of: view, withInset: bottomMargin)
// Width constraint
viewWidth = 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))
@ -456,6 +460,21 @@ private final class EnterPublicKeyVC: UIViewController {
// MARK: - General // MARK: - General
func constrainSize(to size: CGSize) {
if viewWidth == nil {
viewWidth = view.set(.width, to: size.width)
} else {
viewWidth?.constant = size.width
}
if viewHeight == nil {
viewHeight = view.set(.height, to: size.height)
} else {
viewHeight?.constant = size.height
}
}
func setSessionId(to sessionId: String) { func setSessionId(to sessionId: String) {
publicKeyTextView.insertText(sessionId) publicKeyTextView.insertText(sessionId)
} }
@ -615,7 +634,8 @@ private final class EnterPublicKeyVC: UIViewController {
private final class ScanQRCodePlaceholderVC: UIViewController { private final class ScanQRCodePlaceholderVC: UIViewController {
weak var newDMVC: NewDMVC! weak var newDMVC: NewDMVC!
var viewWidth: NSLayoutConstraint? private var viewWidth: NSLayoutConstraint?
private var viewHeight: NSLayoutConstraint?
override func viewDidLoad() { override func viewDidLoad() {
// Remove background color // Remove background color
@ -644,14 +664,29 @@ private final class ScanQRCodePlaceholderVC: UIViewController {
stackView.alignment = .center stackView.alignment = .center
// Set up constraints // Set up constraints
viewWidth = view.set(.width, to: UIScreen.main.bounds.width)
view.addSubview(stackView) view.addSubview(stackView)
stackView.pin(.leading, to: .leading, of: view, withInset: Values.massiveSpacing) stackView.pin(.leading, to: .leading, of: view, withInset: Values.massiveSpacing)
stackView.pin(.trailing, to: .trailing, of: view, withInset: -Values.massiveSpacing) view.pin(.trailing, to: .trailing, of: stackView, withInset: Values.massiveSpacing)
stackView.center(.vertical, in: view, withInset: -16) // Makes things appear centered visually
let verticalCenteringConstraint = stackView.center(.vertical, in: view)
verticalCenteringConstraint.constant = -16 // Makes things appear centered visually
} }
func constrainSize(to size: CGSize) {
if viewWidth == nil {
viewWidth = view.set(.width, to: size.width)
} else {
viewWidth?.constant = size.width
}
if viewHeight == nil {
viewHeight = view.set(.height, to: size.height)
} else {
viewHeight?.constant = size.height
}
}
@objc private func requestCameraAccess() { @objc private func requestCameraAccess() {
Permissions.requestCameraPermissionIfNeeded { [weak self] in Permissions.requestCameraPermissionIfNeeded { [weak self] in
self?.newDMVC.handleCameraAccessGranted() self?.newDMVC.handleCameraAccessGranted()

@ -84,17 +84,22 @@ final class JoinOpenGroupVC: BaseVC, UIPageViewControllerDataSource, UIPageViewC
pageVCView.pin(.top, to: .bottom, of: tabBar) pageVCView.pin(.top, to: .bottom, of: tabBar)
pageVCView.pin(.trailing, to: .trailing, of: view) pageVCView.pin(.trailing, to: .trailing, of: view)
pageVCView.pin(.bottom, to: .bottom, of: view) pageVCView.pin(.bottom, to: .bottom, of: view)
let navBarHeight: CGFloat = (navigationController?.navigationBar.frame.size.height ?? 0) let navBarHeight: CGFloat = (navigationController?.navigationBar.frame.size.height ?? 0)
let height: CGFloat = ((navigationController?.view.bounds.height ?? 0) - navBarHeight - TabBar.snHeight) let statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.size.height
enterURLVC.constrainHeight(to: height) let height: CGFloat = ((navigationController?.view.bounds.height ?? 0) - navBarHeight - TabBar.snHeight - statusBarHeight)
scanQRCodePlaceholderVC.constrainHeight(to: height) let size: CGSize = CGSize(width: UIScreen.main.bounds.width, height: height)
enterURLVC.constrainSize(to: size)
scanQRCodePlaceholderVC.constrainSize(to: size)
} }
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator) super.viewWillTransition(to: size, with: coordinator)
enterURLVC.viewWidth?.constant = size.width let height: CGFloat = (size.height - TabBar.snHeight)
let size: CGSize = CGSize(width: size.width, height: height)
enterURLVC.constrainSize(to: size)
scanQRCodePlaceholderVC.constrainSize(to: size)
enterURLVC.suggestionGrid.refreshLayout(with: size.width - 2 * Values.largeSpacing) enterURLVC.suggestionGrid.refreshLayout(with: size.width - 2 * Values.largeSpacing)
scanQRCodePlaceholderVC.viewWidth?.constant = size.width
} }
// MARK: - General // MARK: - General
@ -256,7 +261,8 @@ private final class EnterURLVC: UIViewController, UIGestureRecognizerDelegate, O
return result return result
}() }()
var viewWidth: NSLayoutConstraint? private var viewWidth: NSLayoutConstraint?
private var viewHeight: NSLayoutConstraint?
// MARK: - Lifecycle // MARK: - Lifecycle
@ -332,8 +338,18 @@ private final class EnterURLVC: UIViewController, UIGestureRecognizerDelegate, O
// MARK: - General // MARK: - General
func constrainHeight(to height: CGFloat) { func constrainSize(to size: CGSize) {
view.set(.height, to: height) if viewWidth == nil {
viewWidth = view.set(.width, to: size.width)
} else {
viewWidth?.constant = size.width
}
if viewHeight == nil {
viewHeight = view.set(.height, to: size.height)
} else {
viewHeight?.constant = size.height
}
} }
@objc private func dismissKeyboard() { @objc private func dismissKeyboard() {
@ -445,7 +461,8 @@ private final class EnterURLVC: UIViewController, UIGestureRecognizerDelegate, O
private final class ScanQRCodePlaceholderVC: UIViewController { private final class ScanQRCodePlaceholderVC: UIViewController {
weak var joinOpenGroupVC: JoinOpenGroupVC? weak var joinOpenGroupVC: JoinOpenGroupVC?
var viewWidth: NSLayoutConstraint? private var viewWidth: NSLayoutConstraint?
private var viewHeight: NSLayoutConstraint?
// MARK: - Lifecycle // MARK: - Lifecycle
@ -476,7 +493,6 @@ private final class ScanQRCodePlaceholderVC: UIViewController {
stackView.alignment = .center stackView.alignment = .center
// Constraints // Constraints
viewWidth = view.set(.width, to: UIScreen.main.bounds.width)
view.addSubview(stackView) view.addSubview(stackView)
stackView.pin(.leading, to: .leading, of: view, withInset: Values.massiveSpacing) stackView.pin(.leading, to: .leading, of: view, withInset: Values.massiveSpacing)
view.pin(.trailing, to: .trailing, of: stackView, withInset: Values.massiveSpacing) view.pin(.trailing, to: .trailing, of: stackView, withInset: Values.massiveSpacing)
@ -485,8 +501,18 @@ private final class ScanQRCodePlaceholderVC: UIViewController {
verticalCenteringConstraint.constant = -16 // Makes things appear centered visually verticalCenteringConstraint.constant = -16 // Makes things appear centered visually
} }
func constrainHeight(to height: CGFloat) { func constrainSize(to size: CGSize) {
view.set(.height, to: height) if viewWidth == nil {
viewWidth = view.set(.width, to: size.width)
} else {
viewWidth?.constant = size.width
}
if viewHeight == nil {
viewHeight = view.set(.height, to: size.height)
} else {
viewHeight?.constant = size.height
}
} }
@objc private func requestCameraAccess() { @objc private func requestCameraAccess() {

Loading…
Cancel
Save