Skip to content

Commit

Permalink
Add privacy button and fix alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag committed May 15, 2024
1 parent ae8ed5e commit c674a96
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class InstantOnboardingView: UIView {

let nameTextField: UITextField
let hintLabel: UILabel
private let hintLabelWrapper: UIView
let privacyButton: UIButton
private let privacyButtonWrapper: UIView
let agreeButton: UIButton

private let contentStackView: UIStackView
Expand All @@ -30,24 +33,39 @@ class InstantOnboardingView: UIView {
nameTextField.borderStyle = .roundedRect

hintLabel = UILabel()
hintLabel.translatesAutoresizingMaskIntoConstraints = false
hintLabel.numberOfLines = 0
hintLabel.text = String.localized("set_name_and_avatar_explain")

hintLabelWrapper = UIView()
hintLabelWrapper.translatesAutoresizingMaskIntoConstraints = false
hintLabelWrapper.addSubview(hintLabel)

agreeButton = UIButton()
agreeButton.setTitle(String.localized("instant_onboarding_create"), for: .normal)
agreeButton.translatesAutoresizingMaskIntoConstraints = false
agreeButton.layer.cornerRadius = 8
agreeButton.backgroundColor = UIColor.systemBlue.withAlphaComponent(0.6)
agreeButton.contentEdgeInsets.top = 8
agreeButton.contentEdgeInsets.bottom = 8
agreeButton.isEnabled = false

privacyButton = UIButton(type: .system)
privacyButton.translatesAutoresizingMaskIntoConstraints = false
privacyButton.setTitle(String.localized("instant_onboarding_agree_default"), for: .normal)

contentStackView = UIStackView(arrangedSubviews: [imageButton, nameTextField, hintLabel, agreeButton])
privacyButtonWrapper = UIView()
privacyButtonWrapper.translatesAutoresizingMaskIntoConstraints = false
privacyButtonWrapper.addSubview(privacyButton)

contentStackView = UIStackView(arrangedSubviews: [imageButton, nameTextField, hintLabelWrapper, privacyButtonWrapper, agreeButton])
contentStackView.translatesAutoresizingMaskIntoConstraints = false
contentStackView.axis = .vertical
contentStackView.alignment = .center
contentStackView.setCustomSpacing(32, after: imageButton)
contentStackView.setCustomSpacing(16, after: nameTextField)
contentStackView.setCustomSpacing(16, after: hintLabel)
contentStackView.setCustomSpacing(8, after: hintLabelWrapper)
contentStackView.setCustomSpacing(16, after: privacyButtonWrapper)

contentScrollView = UIScrollView()
contentScrollView.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -88,6 +106,18 @@ class InstantOnboardingView: UIView {

imageButton.widthAnchor.constraint(equalToConstant: 150),
imageButton.heightAnchor.constraint(equalToConstant: 150),

privacyButtonWrapper.widthAnchor.constraint(equalTo: contentStackView.widthAnchor),
privacyButton.topAnchor.constraint(equalTo: privacyButtonWrapper.topAnchor),
privacyButton.leadingAnchor.constraint(equalTo: privacyButtonWrapper.leadingAnchor),
privacyButtonWrapper.trailingAnchor.constraint(greaterThanOrEqualTo: privacyButton.trailingAnchor),
privacyButtonWrapper.bottomAnchor.constraint(equalTo: privacyButton.bottomAnchor),

hintLabelWrapper.widthAnchor.constraint(equalTo: contentStackView.widthAnchor),
hintLabel.topAnchor.constraint(equalTo: hintLabelWrapper.topAnchor),
hintLabel.leadingAnchor.constraint(equalTo: hintLabelWrapper.leadingAnchor),
hintLabelWrapper.trailingAnchor.constraint(greaterThanOrEqualTo: hintLabel.trailingAnchor),
hintLabelWrapper.bottomAnchor.constraint(equalTo: hintLabel.bottomAnchor),
]

NSLayoutConstraint.activate(constraints)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class InstantOnboardingViewController: UIViewController, ProgressAlertHandler {
let contentView = InstantOnboardingView(avatarImage: dcContext.getSelfAvatarImage())
contentView.agreeButton.addTarget(self, action: #selector(InstantOnboardingViewController.acceptAndCreateButtonPressed), for: .touchUpInside)
contentView.imageButton.addTarget(self, action: #selector(InstantOnboardingViewController.onAvatarTapped), for: .touchUpInside)
contentView.privacyButton.addTarget(self, action: #selector(InstantOnboardingViewController.showPrivacy(_:)), for: .touchUpInside)
NotificationCenter.default.addObserver(
self,
selector: #selector(InstantOnboardingViewController.textDidChangeNotification(notification:)),
Expand Down Expand Up @@ -84,6 +85,14 @@ class InstantOnboardingViewController: UIViewController, ProgressAlertHandler {
contentView.imageButton.setImage(UIImage(named: "person.crop.circle"), for: .normal)
}

@objc private func showPrivacy(_ sender: UIButton) {
guard let url = URL(string: "https://nine.testrun.org/privacy.html") else { return }

if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}

@objc
private func onAvatarTapped() {
let alert = UIAlertController(title: String.localized("pref_profile_photo"), message: nil, preferredStyle: .safeActionSheet)
Expand Down

0 comments on commit c674a96

Please sign in to comment.