mirror of https://github.com/oxen-io/session-ios
Implement modal redesign
parent
13d79096aa
commit
c279eb1be4
@ -0,0 +1,79 @@
|
||||
|
||||
@objc(LKModal)
|
||||
internal class Modal : UIViewController {
|
||||
private(set) var verticalCenteringConstraint: NSLayoutConstraint!
|
||||
|
||||
// MARK: Settings
|
||||
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
|
||||
|
||||
// MARK: Components
|
||||
lazy var contentView: UIView = {
|
||||
let result = UIView()
|
||||
result.backgroundColor = Colors.modalBackground
|
||||
result.layer.cornerRadius = Values.modalCornerRadius
|
||||
result.layer.masksToBounds = false
|
||||
result.layer.borderColor = Colors.modalBorder.cgColor
|
||||
result.layer.borderWidth = Values.borderThickness
|
||||
result.layer.shadowColor = UIColor.black.cgColor
|
||||
result.layer.shadowRadius = 8
|
||||
result.layer.shadowOpacity = 0.64
|
||||
return result
|
||||
}()
|
||||
|
||||
lazy var cancelButton: UIButton = {
|
||||
let result = UIButton()
|
||||
result.set(.height, to: Values.mediumButtonHeight)
|
||||
result.layer.cornerRadius = Values.modalButtonCornerRadius
|
||||
result.backgroundColor = Colors.buttonBackground
|
||||
result.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
result.setTitleColor(Colors.text, for: UIControl.State.normal)
|
||||
result.setTitle(NSLocalizedString("Cancel", comment: ""), for: UIControl.State.normal)
|
||||
return result
|
||||
}()
|
||||
|
||||
// MARK: Lifecycle
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = UIColor(hex: 0x000000).withAlphaComponent(Values.modalBackgroundOpacity)
|
||||
cancelButton.addTarget(self, action: #selector(cancel), for: UIControl.Event.touchUpInside)
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
private func setUpViewHierarchy() {
|
||||
view.addSubview(contentView)
|
||||
contentView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: Values.veryLargeSpacing).isActive = true
|
||||
view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: Values.veryLargeSpacing).isActive = true
|
||||
verticalCenteringConstraint = contentView.center(.vertical, in: view)
|
||||
populateContentView()
|
||||
}
|
||||
|
||||
/// To be overridden by subclasses.
|
||||
func populateContentView() {
|
||||
preconditionFailure("populateContentView() is abstract and must be overridden.")
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
verticalCenteringConstraint.constant = contentView.height() / 2 + view.height() / 2
|
||||
view.layoutIfNeeded()
|
||||
verticalCenteringConstraint.constant = 0
|
||||
UIView.animate(withDuration: 0.25) {
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
let touch = touches.first!
|
||||
let location = touch.location(in: view)
|
||||
if contentView.frame.contains(location) {
|
||||
super.touchesBegan(touches, with: event)
|
||||
} else {
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func cancel() {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
|
||||
@objc(LKNukeDataModal)
|
||||
final class NukeDataModal : Modal {
|
||||
|
||||
// MARK: Lifecycle
|
||||
override func populateContentView() {
|
||||
// Set up title label
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.textColor = Colors.text
|
||||
titleLabel.font = .boldSystemFont(ofSize: Values.mediumFontSize)
|
||||
titleLabel.text = NSLocalizedString("Clear All Data", comment: "")
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.lineBreakMode = .byWordWrapping
|
||||
titleLabel.textAlignment = .center
|
||||
// Set up explanation label
|
||||
let explanationLabel = UILabel()
|
||||
explanationLabel.textColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity)
|
||||
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
explanationLabel.text = NSLocalizedString("This will delete your entire account, including all data, any messages currently linked to your public key, as well as your personal key pair.", comment: "")
|
||||
explanationLabel.numberOfLines = 0
|
||||
explanationLabel.textAlignment = .center
|
||||
explanationLabel.lineBreakMode = .byWordWrapping
|
||||
// Set up nuke data button
|
||||
let nukeDataButton = UIButton()
|
||||
nukeDataButton.set(.height, to: Values.mediumButtonHeight)
|
||||
nukeDataButton.layer.cornerRadius = Values.modalButtonCornerRadius
|
||||
nukeDataButton.backgroundColor = Colors.destructive
|
||||
nukeDataButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
nukeDataButton.setTitleColor(Colors.text, for: UIControl.State.normal)
|
||||
nukeDataButton.setTitle(NSLocalizedString("Delete", comment: ""), for: UIControl.State.normal)
|
||||
nukeDataButton.addTarget(self, action: #selector(nuke), for: UIControl.Event.touchUpInside)
|
||||
// Set up button stack view
|
||||
let buttonStackView = UIStackView(arrangedSubviews: [ cancelButton, nukeDataButton ])
|
||||
buttonStackView.axis = .horizontal
|
||||
buttonStackView.spacing = Values.mediumSpacing
|
||||
buttonStackView.distribution = .fillEqually
|
||||
// Set up stack view
|
||||
let stackView = UIStackView(arrangedSubviews: [ titleLabel, explanationLabel, buttonStackView ])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = Values.largeSpacing
|
||||
contentView.addSubview(stackView)
|
||||
stackView.pin(.leading, to: .leading, of: contentView, withInset: Values.largeSpacing)
|
||||
stackView.pin(.top, to: .top, of: contentView, withInset: Values.largeSpacing)
|
||||
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: Values.largeSpacing)
|
||||
contentView.pin(.bottom, to: .bottom, of: stackView, withInset: Values.largeSpacing)
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
@objc private func nuke() {
|
||||
UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later
|
||||
NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
|
||||
@objc(LKSeedModal)
|
||||
final class SeedModal : Modal {
|
||||
|
||||
private let mnemonic: String = {
|
||||
let identityManager = OWSIdentityManager.shared()
|
||||
let databaseConnection = identityManager.value(forKey: "dbConnection") as! YapDatabaseConnection
|
||||
var hexEncodedSeed: String! = databaseConnection.object(forKey: "LKLokiSeed", inCollection: OWSPrimaryStorageIdentityKeyStoreCollection) as! String?
|
||||
if hexEncodedSeed == nil {
|
||||
hexEncodedSeed = identityManager.identityKeyPair()!.hexEncodedPrivateKey // Legacy account
|
||||
}
|
||||
return Mnemonic.encode(hexEncodedString: hexEncodedSeed)
|
||||
}()
|
||||
|
||||
// MARK: Lifecycle
|
||||
override func populateContentView() {
|
||||
// Set up title label
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.textColor = Colors.text
|
||||
titleLabel.font = .boldSystemFont(ofSize: Values.mediumFontSize)
|
||||
titleLabel.text = NSLocalizedString("Your Seed", comment: "")
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.lineBreakMode = .byWordWrapping
|
||||
titleLabel.textAlignment = .center
|
||||
// Set up mnemonic label
|
||||
let mnemonicLabel = UILabel()
|
||||
mnemonicLabel.textColor = Colors.text
|
||||
mnemonicLabel.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
mnemonicLabel.text = mnemonic
|
||||
mnemonicLabel.numberOfLines = 0
|
||||
mnemonicLabel.lineBreakMode = .byWordWrapping
|
||||
mnemonicLabel.textAlignment = .center
|
||||
// Set up explanation label
|
||||
let explanationLabel = UILabel()
|
||||
explanationLabel.textColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity)
|
||||
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
explanationLabel.text = NSLocalizedString("This is your personal password. It can be used to restore your account or migrate your account to a new device.", comment: "")
|
||||
explanationLabel.numberOfLines = 0
|
||||
explanationLabel.lineBreakMode = .byWordWrapping
|
||||
explanationLabel.textAlignment = .center
|
||||
// Set up copy button
|
||||
let copyButton = UIButton()
|
||||
copyButton.set(.height, to: Values.mediumButtonHeight)
|
||||
copyButton.layer.cornerRadius = Values.modalButtonCornerRadius
|
||||
copyButton.backgroundColor = Colors.buttonBackground
|
||||
copyButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
copyButton.setTitleColor(Colors.text, for: UIControl.State.normal)
|
||||
copyButton.setTitle(NSLocalizedString("Copy", comment: ""), for: UIControl.State.normal)
|
||||
copyButton.addTarget(self, action: #selector(copySeed), for: UIControl.Event.touchUpInside)
|
||||
// Set up button stack view
|
||||
let buttonStackView = UIStackView(arrangedSubviews: [ cancelButton, copyButton ])
|
||||
buttonStackView.axis = .horizontal
|
||||
buttonStackView.spacing = Values.mediumSpacing
|
||||
buttonStackView.distribution = .fillEqually
|
||||
// Set up stack view
|
||||
let stackView = UIStackView(arrangedSubviews: [ titleLabel, mnemonicLabel, explanationLabel, buttonStackView ])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = Values.largeSpacing
|
||||
contentView.addSubview(stackView)
|
||||
stackView.pin(.leading, to: .leading, of: contentView, withInset: Values.largeSpacing)
|
||||
stackView.pin(.top, to: .top, of: contentView, withInset: Values.largeSpacing)
|
||||
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: Values.largeSpacing)
|
||||
contentView.pin(.bottom, to: .bottom, of: stackView, withInset: Values.largeSpacing)
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
@objc private func copySeed() {
|
||||
UIPasteboard.general.string = mnemonic
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
|
||||
@objc(LKNukeDataModal)
|
||||
final class NukeDataModal : Modal {
|
||||
|
||||
// MARK: Lifecycle
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
Analytics.shared.track("Nuke Data Modal Shown")
|
||||
}
|
||||
|
||||
override func populateContentView() {
|
||||
// Label
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.textColor = Theme.primaryColor
|
||||
titleLabel.font = UIFont.ows_dynamicTypeHeadlineClamped
|
||||
titleLabel.text = NSLocalizedString("Clear All Data", comment: "")
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.lineBreakMode = .byWordWrapping
|
||||
titleLabel.textAlignment = .center
|
||||
// Explanation label
|
||||
let explanationLabel = UILabel()
|
||||
explanationLabel.font = UIFont.ows_dynamicTypeCaption1Clamped
|
||||
explanationLabel.text = NSLocalizedString("Are you sure you want to clear all your data? This will delete your entire account, including all conversations and your personal key pair.", comment: "")
|
||||
explanationLabel.numberOfLines = 0
|
||||
explanationLabel.textAlignment = .center
|
||||
explanationLabel.lineBreakMode = .byWordWrapping
|
||||
explanationLabel.textColor = UIColor.ows_white
|
||||
// Button stack view
|
||||
let nukeButton = OWSFlatButton.button(title: NSLocalizedString("OK", comment: ""), font: .ows_dynamicTypeBodyClamped, titleColor: .white, backgroundColor: .clear, target: self, selector: #selector(nuke))
|
||||
nukeButton.setBackgroundColors(upColor: .clear, downColor: .clear)
|
||||
let buttonStackView = UIStackView(arrangedSubviews: [ nukeButton, cancelButton ])
|
||||
buttonStackView.axis = .horizontal
|
||||
buttonStackView.distribution = .fillEqually
|
||||
let buttonHeight = cancelButton.button.titleLabel!.font.pointSize * 48 / 17
|
||||
nukeButton.set(.height, to: buttonHeight)
|
||||
cancelButton.set(.height, to: buttonHeight)
|
||||
// Stack view
|
||||
let stackView = UIStackView(arrangedSubviews: [ UIView.spacer(withHeight: 2), titleLabel, explanationLabel, buttonStackView ])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = 16
|
||||
contentView.addSubview(stackView)
|
||||
stackView.pin(.leading, to: .leading, of: contentView, withInset: 16)
|
||||
stackView.pin(.top, to: .top, of: contentView, withInset: 16)
|
||||
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: 16)
|
||||
contentView.pin(.bottom, to: .bottom, of: stackView, withInset: 16)
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
@objc private func nuke() {
|
||||
Analytics.shared.track("Data Nuked")
|
||||
UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later
|
||||
NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
|
||||
@objc(LKSeedModal)
|
||||
final class SeedModal : Modal {
|
||||
|
||||
private let mnemonic: String = {
|
||||
let identityManager = OWSIdentityManager.shared()
|
||||
let databaseConnection = identityManager.value(forKey: "dbConnection") as! YapDatabaseConnection
|
||||
var hexEncodedSeed: String! = databaseConnection.object(forKey: "LKLokiSeed", inCollection: OWSPrimaryStorageIdentityKeyStoreCollection) as! String?
|
||||
if hexEncodedSeed == nil {
|
||||
hexEncodedSeed = identityManager.identityKeyPair()!.hexEncodedPrivateKey // Legacy account
|
||||
}
|
||||
return Mnemonic.encode(hexEncodedString: hexEncodedSeed)
|
||||
}()
|
||||
|
||||
// MARK: Lifecycle
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
Analytics.shared.track("Seed Modal Shown")
|
||||
}
|
||||
|
||||
override func populateContentView() {
|
||||
// Label
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.textColor = Theme.primaryColor
|
||||
titleLabel.font = UIFont.ows_dynamicTypeHeadlineClamped
|
||||
titleLabel.text = NSLocalizedString("Your Seed", comment: "")
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.lineBreakMode = .byWordWrapping
|
||||
titleLabel.textAlignment = .center
|
||||
// Subtitle label
|
||||
let subtitleLabel = UILabel()
|
||||
subtitleLabel.textColor = Theme.primaryColor
|
||||
subtitleLabel.font = UIFont.ows_dynamicTypeCaption1Clamped
|
||||
subtitleLabel.text = NSLocalizedString("This is your personal secret. It can be used to restore your account if you lose access, or to migrate your account to a new device.", comment: "")
|
||||
subtitleLabel.numberOfLines = 0
|
||||
subtitleLabel.lineBreakMode = .byWordWrapping
|
||||
subtitleLabel.textAlignment = .center
|
||||
// Mnemonic label
|
||||
let mnemonicLabel = UILabel()
|
||||
let font = UIFont.ows_dynamicTypeCaption1Clamped
|
||||
mnemonicLabel.font = UIFont(descriptor: font.fontDescriptor.withSymbolicTraits(.traitItalic)!, size: font.pointSize)
|
||||
mnemonicLabel.text = mnemonic
|
||||
mnemonicLabel.numberOfLines = 0
|
||||
mnemonicLabel.textAlignment = .center
|
||||
mnemonicLabel.lineBreakMode = .byWordWrapping
|
||||
mnemonicLabel.textColor = UIColor.ows_white
|
||||
mnemonicLabel.alpha = 0.8
|
||||
// Button stack view
|
||||
let copyButton = OWSFlatButton.button(title: NSLocalizedString("Copy", comment: ""), font: .ows_dynamicTypeBodyClamped, titleColor: .white, backgroundColor: .clear, target: self, selector: #selector(copySeed))
|
||||
copyButton.setBackgroundColors(upColor: .clear, downColor: .clear)
|
||||
let buttonStackView = UIStackView(arrangedSubviews: [ copyButton, cancelButton ])
|
||||
buttonStackView.axis = .horizontal
|
||||
buttonStackView.distribution = .fillEqually
|
||||
let buttonHeight = cancelButton.button.titleLabel!.font.pointSize * 48 / 17
|
||||
copyButton.set(.height, to: buttonHeight)
|
||||
cancelButton.set(.height, to: buttonHeight)
|
||||
// Stack view
|
||||
let stackView = UIStackView(arrangedSubviews: [ UIView.spacer(withHeight: 2), titleLabel, subtitleLabel, mnemonicLabel, buttonStackView ])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = 16
|
||||
contentView.addSubview(stackView)
|
||||
stackView.pin(.leading, to: .leading, of: contentView, withInset: 16)
|
||||
stackView.pin(.top, to: .top, of: contentView, withInset: 16)
|
||||
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: 16)
|
||||
contentView.pin(.bottom, to: .bottom, of: stackView, withInset: 16)
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
@objc private func copySeed() {
|
||||
UIPasteboard.general.string = mnemonic
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
|
||||
@objc(LKModal)
|
||||
internal class Modal : UIViewController {
|
||||
private(set) var verticalCenteringConstraint: NSLayoutConstraint!
|
||||
|
||||
// MARK: Components
|
||||
lazy var contentView: UIView = {
|
||||
let result = UIView()
|
||||
result.backgroundColor = .lokiDarkGray()
|
||||
result.layer.cornerRadius = 4
|
||||
result.layer.masksToBounds = false
|
||||
result.layer.shadowColor = UIColor.black.cgColor
|
||||
result.layer.shadowRadius = 8
|
||||
result.layer.shadowOpacity = 0.64
|
||||
return result
|
||||
}()
|
||||
|
||||
lazy var cancelButton: OWSFlatButton = {
|
||||
let result = OWSFlatButton.button(title: NSLocalizedString("Cancel", comment: ""), font: .ows_dynamicTypeBodyClamped, titleColor: .white, backgroundColor: .clear, target: self, selector: #selector(cancel))
|
||||
result.setBackgroundColors(upColor: .clear, downColor: .clear)
|
||||
return result
|
||||
}()
|
||||
|
||||
// MARK: Lifecycle
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
private func setUpViewHierarchy() {
|
||||
view.backgroundColor = .clear
|
||||
view.addSubview(contentView)
|
||||
contentView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 32).isActive = true
|
||||
view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 32).isActive = true
|
||||
verticalCenteringConstraint = contentView.center(.vertical, in: view)
|
||||
populateContentView()
|
||||
}
|
||||
|
||||
/// To be overridden by subclasses.
|
||||
func populateContentView() {
|
||||
preconditionFailure("populateContentView() is abstract and must be overridden.")
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
let touch = touches.first!
|
||||
let location = touch.location(in: view)
|
||||
if contentView.frame.contains(location) {
|
||||
super.touchesBegan(touches, with: event)
|
||||
} else {
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func cancel() {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue