diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-04-13 14:15:48 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-05-11 15:03:41 +0200 |
| commit | 15bb7d7f6003bc42f813e29bdb12090bb1c91317 (patch) | |
| tree | da016e0746efd078720c3205e5e6011e3d089d24 | |
| parent | b717a9f10793db2306be3d45b14629fcb3ae923e (diff) | |
| download | mullvadvpn-15bb7d7f6003bc42f813e29bdb12090bb1c91317.tar.xz mullvadvpn-15bb7d7f6003bc42f813e29bdb12090bb1c91317.zip | |
Connect: show "select location" button on iPad in compact mode
| -rw-r--r-- | ios/MullvadVPN/ConnectViewController.swift | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/ios/MullvadVPN/ConnectViewController.swift b/ios/MullvadVPN/ConnectViewController.swift index 8dd31f3346..51ced98e07 100644 --- a/ios/MullvadVPN/ConnectViewController.swift +++ b/ios/MullvadVPN/ConnectViewController.swift @@ -71,6 +71,27 @@ class ConnectViewController: UIViewController, RootContainment, TunnelObserver addSubviews() } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + if previousTraitCollection?.userInterfaceIdiom != traitCollection.userInterfaceIdiom || + previousTraitCollection?.horizontalSizeClass != traitCollection.horizontalSizeClass { + updateTraitDependentViews() + } + } + + func setMainContentHidden(_ isHidden: Bool, animated: Bool) { + let actions = { + self.mainContentView.containerView.alpha = isHidden ? 0 : 1 + } + + if animated { + UIView.animate(withDuration: 0.25, animations: actions) + } else { + actions() + } + } + private func addSubviews() { view.addSubview(mainContentView) NSLayoutConstraint.activate([ @@ -102,7 +123,12 @@ class ConnectViewController: UIViewController, RootContainment, TunnelObserver mainContentView.connectButton.setTitle(tunnelState.localizedTitleForConnectButton, for: .normal) mainContentView.selectLocationButton.setTitle(tunnelState.localizedTitleForSelectLocationButton, for: .normal) mainContentView.splitDisconnectButton.primaryButton.setTitle(tunnelState.localizedTitleForDisconnectButton, for: .normal) - mainContentView.setActionButtons(tunnelState.actionButtons) + + updateTraitDependentViews() + } + + private func updateTraitDependentViews() { + mainContentView.setActionButtons(tunnelState.actionButtons(traitCollection: self.traitCollection)) } private func attributedStringForLocation(string: String) -> NSAttributedString { @@ -210,9 +236,9 @@ private extension TunnelState { } } - var actionButtons: [ConnectMainContentView.ActionButton] { - switch UIDevice.current.userInterfaceIdiom { - case .phone: + func actionButtons(traitCollection: UITraitCollection) -> [ConnectMainContentView.ActionButton] { + switch (traitCollection.userInterfaceIdiom, traitCollection.horizontalSizeClass) { + case (.phone, _), (.pad, .compact): switch self { case .disconnected, .disconnecting: return [.selectLocation, .connect] @@ -221,7 +247,7 @@ private extension TunnelState { return [.selectLocation, .disconnect] } - case .pad: + case (.pad, .regular): switch self { case .disconnected, .disconnecting: return [.connect] |
