session-ios/Session/Onboarding/LandingVC.swift

103 lines
5.2 KiB
Swift
Raw Permalink Normal View History

2019-12-06 04:42:43 +01:00
2020-11-16 00:34:47 +01:00
final class LandingVC : BaseVC {
2019-12-06 04:42:43 +01:00
2019-12-09 00:01:10 +01:00
// MARK: Components
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
}()
2019-12-12 06:07:08 +01:00
private lazy var registerButton: Button = {
let result = Button(style: .prominentFilled, size: .large)
result.setTitle(NSLocalizedString("vc_landing_register_button_title", comment: ""), for: UIControl.State.normal)
2019-12-12 06:07:08 +01:00
result.titleLabel!.font = .boldSystemFont(ofSize: Values.mediumFontSize)
result.addTarget(self, action: #selector(register), for: UIControl.Event.touchUpInside)
return result
}()
private lazy var restoreButton: Button = {
let result = Button(style: .prominentOutline, size: .large)
result.setTitle(NSLocalizedString("vc_landing_restore_button_title", comment: ""), for: UIControl.State.normal)
2019-12-12 06:07:08 +01:00
result.titleLabel!.font = .boldSystemFont(ofSize: Values.mediumFontSize)
result.addTarget(self, action: #selector(restore), for: UIControl.Event.touchUpInside)
return result
}()
2021-02-22 04:47:40 +01:00
// MARK: Settings
private static let fakeChatViewHeight = isIPhone5OrSmaller ? CGFloat(234) : CGFloat(260)
2019-12-06 04:42:43 +01:00
// MARK: Lifecycle
override func viewDidLoad() {
2020-02-20 04:37:17 +01:00
super.viewDidLoad()
setUpGradientBackground()
setUpNavBarStyle()
setUpNavBarSessionIcon()
2021-02-18 05:32:56 +01:00
// Title label
2019-12-06 04:42:43 +01:00
let titleLabel = UILabel()
titleLabel.textColor = Colors.text
2020-06-18 06:41:02 +02:00
titleLabel.font = .boldSystemFont(ofSize: isIPhone5OrSmaller ? Values.largeFontSize : Values.veryLargeFontSize)
titleLabel.text = NSLocalizedString("vc_landing_title_2", comment: "")
2019-12-06 04:42:43 +01:00
titleLabel.numberOfLines = 0
titleLabel.lineBreakMode = .byWordWrapping
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()
2021-04-29 05:56:49 +02:00
linkButton.setTitle(NSLocalizedString("vc_landing_link_button_title", comment: ""), for: UIControl.State.normal)
2021-02-18 05:32:56 +01:00
linkButton.setTitleColor(Colors.text, for: UIControl.State.normal)
linkButton.titleLabel!.font = .boldSystemFont(ofSize: Values.smallFontSize)
linkButton.addTarget(self, action: #selector(link), for: UIControl.Event.touchUpInside)
// 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)
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
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
@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
}