session-ios/Session/Onboarding/LandingVC.swift

127 lines
5.4 KiB
Swift
Raw Normal View History

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
2019-12-06 04:42:43 +01:00
import UIKit
import SessionUIKit
final class LandingVC: BaseVC {
2019-12-06 04:42:43 +01:00
// MARK: - Components
2019-12-09 00:01:10 +01:00
private lazy var fakeChatView: FakeChatView = {
let result = FakeChatView()
2021-02-22 04:47:40 +01:00
result.set(.height, to: LandingVC.fakeChatViewHeight)
2019-12-09 00:01:10 +01:00
return result
}()
private lazy var registerButton: SessionButton = {
let result = SessionButton(style: .filled, size: .large)
result.accessibilityLabel = "Create session ID"
result.setTitle("vc_landing_register_button_title".localized(), for: .normal)
result.addTarget(self, action: #selector(register), for: .touchUpInside)
2019-12-12 06:07:08 +01:00
return result
}()
private lazy var restoreButton: SessionButton = {
let result = SessionButton(style: .bordered, size: .large)
result.setTitle("vc_landing_restore_button_title".localized(), for: .normal)
result.addTarget(self, action: #selector(restore), for: .touchUpInside)
2019-12-12 06:07:08 +01:00
return result
}()
// MARK: - Settings
2021-02-22 04:47:40 +01:00
private static let fakeChatViewHeight = isIPhone5OrSmaller ? CGFloat(234) : CGFloat(260)
// MARK: - Lifecycle
2019-12-06 04:42:43 +01:00
override func viewDidLoad() {
2020-02-20 04:37:17 +01:00
super.viewDidLoad()
setUpNavBarSessionIcon()
2021-02-18 05:32:56 +01:00
// Title label
2019-12-06 04:42:43 +01:00
let titleLabel = UILabel()
2020-06-18 06:41:02 +02:00
titleLabel.font = .boldSystemFont(ofSize: isIPhone5OrSmaller ? Values.largeFontSize : Values.veryLargeFontSize)
titleLabel.text = "vc_landing_title_2".localized()
titleLabel.themeTextColor = .textPrimary
2019-12-06 04:42:43 +01:00
titleLabel.lineBreakMode = .byWordWrapping
titleLabel.numberOfLines = 0
2021-02-18 05:32:56 +01:00
// Title label container
2019-12-06 04:42:43 +01:00
let titleLabelContainer = UIView()
titleLabelContainer.addSubview(titleLabel)
titleLabel.pin(.leading, to: .leading, of: titleLabelContainer, withInset: Values.veryLargeSpacing)
titleLabel.pin(.top, to: .top, of: titleLabelContainer)
titleLabelContainer.pin(.trailing, to: .trailing, of: titleLabel, withInset: Values.veryLargeSpacing)
titleLabelContainer.pin(.bottom, to: .bottom, of: titleLabel)
2021-02-18 05:32:56 +01:00
// Spacers
2019-12-09 00:01:10 +01:00
let topSpacer = UIView.vStretchingSpacer()
let bottomSpacer = UIView.vStretchingSpacer()
2021-02-18 05:32:56 +01:00
// Link button
let linkButton = UIButton()
linkButton.accessibilityLabel = "Link a device"
linkButton.titleLabel?.font = .boldSystemFont(ofSize: Values.smallFontSize)
linkButton.setTitle("vc_landing_link_button_title".localized(), for: .normal)
linkButton.setThemeTitleColor(.textPrimary, for: .normal)
linkButton.addTarget(self, action: #selector(link), for: .touchUpInside)
2021-02-18 05:32:56 +01:00
// Link button container
2019-12-12 06:07:08 +01:00
let linkButtonContainer = UIView()
linkButtonContainer.set(.height, to: Values.onboardingButtonBottomOffset)
2021-03-01 06:17:08 +01:00
linkButtonContainer.addSubview(linkButton)
linkButton.center(.horizontal, in: linkButtonContainer)
let isIPhoneX = ((UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0) > 0)
2021-03-01 06:17:08 +01:00
linkButton.centerYAnchor.constraint(equalTo: linkButtonContainer.centerYAnchor, constant: isIPhoneX ? -4 : 0).isActive = true
2021-02-18 05:32:56 +01:00
// Button stack view
2019-12-06 04:42:43 +01:00
let buttonStackView = UIStackView(arrangedSubviews: [ registerButton, restoreButton ])
buttonStackView.axis = .vertical
2020-06-18 06:41:02 +02:00
buttonStackView.spacing = isIPhone5OrSmaller ? Values.smallSpacing : Values.mediumSpacing
2019-12-06 04:42:43 +01:00
buttonStackView.alignment = .fill
if UIDevice.current.isIPad {
registerButton.set(.width, to: Values.iPadButtonWidth)
restoreButton.set(.width, to: Values.iPadButtonWidth)
buttonStackView.alignment = .center
}
2021-02-18 05:32:56 +01:00
// Button stack view container
2019-12-09 00:01:10 +01:00
let buttonStackViewContainer = UIView()
buttonStackViewContainer.addSubview(buttonStackView)
2020-07-29 03:33:43 +02:00
buttonStackView.pin(.leading, to: .leading, of: buttonStackViewContainer, withInset: isIPhone5OrSmaller ? CGFloat(52) : Values.massiveSpacing)
2019-12-09 00:01:10 +01:00
buttonStackView.pin(.top, to: .top, of: buttonStackViewContainer)
2020-07-29 03:33:43 +02:00
buttonStackViewContainer.pin(.trailing, to: .trailing, of: buttonStackView, withInset: isIPhone5OrSmaller ? CGFloat(52) : Values.massiveSpacing)
2019-12-09 00:01:10 +01:00
buttonStackViewContainer.pin(.bottom, to: .bottom, of: buttonStackView)
2021-02-18 05:32:56 +01:00
// Main stack view
2020-06-18 06:41:02 +02:00
let mainStackView = UIStackView(arrangedSubviews: [ topSpacer, titleLabelContainer, UIView.spacer(withHeight: isIPhone5OrSmaller ? Values.smallSpacing : Values.mediumSpacing), fakeChatView, bottomSpacer, buttonStackViewContainer, linkButtonContainer ])
2019-12-09 00:01:10 +01:00
mainStackView.axis = .vertical
mainStackView.alignment = .fill
view.addSubview(mainStackView)
mainStackView.pin(to: view)
topSpacer.heightAnchor.constraint(equalTo: bottomSpacer.heightAnchor, multiplier: 1).isActive = true
2019-12-06 06:42:28 +01:00
}
// MARK: - Interaction
2019-12-06 06:42:28 +01:00
@objc private func register() {
2019-12-09 02:33:40 +01:00
let registerVC = RegisterVC()
navigationController!.pushViewController(registerVC, animated: true)
}
@objc private func restore() {
let restoreVC = RestoreVC()
navigationController!.pushViewController(restoreVC, animated: true)
2019-12-06 04:42:43 +01:00
}
2021-02-18 05:32:56 +01:00
@objc private func link() {
let linkVC = LinkDeviceVC()
navigationController!.pushViewController(linkVC, animated: true)
}
2019-12-06 04:42:43 +01:00
}