Skip to content

Commit

Permalink
Merge pull request #27 from ivpn/task/IOS-701-use-snapkit-for-auto-la…
Browse files Browse the repository at this point in the history
…yout

Task/IOS-701 Use SnapKit for auto layout
  • Loading branch information
jurajhilje authored Nov 4, 2020
2 parents d263065 + 212ca11 commit 4a70b06
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: docker://github/super-linter:v3.13.1
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_MD: false
VALIDATE_MARKDOWN: false
VALIDATE_GO: false
VALIDATE_POWERSHELL: false
DEFAULT_BRANCH: develop
Expand Down
2 changes: 0 additions & 2 deletions IVPNClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,6 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-IVPNClient/Pods-IVPNClient-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/ActiveLabel/ActiveLabel.framework",
"${BUILT_PRODUCTS_DIR}/Bamboo/Bamboo.framework",
"${BUILT_PRODUCTS_DIR}/FloatingPanel/FloatingPanel.framework",
"${BUILT_PRODUCTS_DIR}/JGProgressHUD/JGProgressHUD.framework",
"${BUILT_PRODUCTS_DIR}/KeychainAccess/KeychainAccess.framework",
Expand All @@ -1908,7 +1907,6 @@
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ActiveLabel.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Bamboo.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FloatingPanel.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/JGProgressHUD.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KeychainAccess.framework",
Expand Down
3 changes: 2 additions & 1 deletion IVPNClient/Scenes/MainScreen/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class MainViewController: UIViewController {
// MARK: - Interface Orientations -

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
refreshUI()
floatingPanel.updateLayout()
mainView.updateLayout()
}

// MARK: - Methods -
Expand Down
53 changes: 45 additions & 8 deletions IVPNClient/Scenes/MainScreen/Map/ConnectionInfoPopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//

import UIKit
import Bamboo
import SnapKit

class ConnectionInfoPopupView: UIView {

Expand Down Expand Up @@ -139,7 +139,12 @@ class ConnectionInfoPopupView: UIView {
// MARK: - Private methods -

private func setupConstraints() {
bb.size(width: 270, height: 69).centerX().centerY(52)
snp.makeConstraints { make in
make.width.equalTo(270)
make.height.equalTo(69)
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().offset(52)
}
}

private func setupView() {
Expand All @@ -163,12 +168,44 @@ class ConnectionInfoPopupView: UIView {
}

private func setupLayout() {
container.bb.fill()
arrow.bb.size(width: 14, height: 14).centerX().top(-7)
statusLabel.bb.left(18).top(15).right(-18).height(14)
locationLabel.bb.left(18).bottom(-15).right(-48).height(19)
actionButton.bb.size(width: 20, height: 20).bottom(-15).right(-18)
errorLabel.bb.top(10).right(-20).bottom(-10).left(20)
container.snp.makeConstraints { make in
make.edges.equalToSuperview()
}

arrow.snp.makeConstraints { make in
make.width.equalTo(14)
make.height.equalTo(14)
make.centerX.equalToSuperview()
make.top.equalTo(-7)
}

statusLabel.snp.makeConstraints { make in
make.left.equalTo(18)
make.top.equalTo(15)
make.right.equalTo(-18)
make.height.equalTo(14)
}

locationLabel.snp.makeConstraints { make in
make.left.equalTo(18)
make.bottom.equalTo(-15)
make.right.equalTo(-48)
make.height.equalTo(19)
}

actionButton.snp.makeConstraints { make in
make.width.equalTo(20)
make.height.equalTo(20)
make.bottom.equalTo(-15)
make.right.equalTo(-18)
}

errorLabel.snp.makeConstraints { make in
make.top.equalTo(10)
make.right.equalTo(-20)
make.bottom.equalTo(-10)
make.left.equalTo(20)
}
}

@objc private func infoAction() {
Expand Down
16 changes: 14 additions & 2 deletions IVPNClient/Scenes/MainScreen/Map/MapMarkerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ class MapMarkerView: UIView {

private func initCircle(_ circle: UIView, radius: CGFloat) {
addSubview(circle)
circle.bb.center().size(width: radius, height: radius)

circle.snp.makeConstraints { make in
make.center.equalToSuperview()
make.width.equalTo(radius)
make.height.equalTo(radius)
}

circle.layer.cornerRadius = radius / 2
circle.clipsToBounds = true
}
Expand All @@ -192,7 +198,13 @@ class MapMarkerView: UIView {
circle1.addSubview(animatedCircle)
circle1.isUserInteractionEnabled = false
animatedCircle.isUserInteractionEnabled = false
animatedCircle.bb.center().size(width: radius1, height: radius1)

animatedCircle.snp.makeConstraints { make in
make.center.equalToSuperview()
make.width.equalTo(radius1)
make.height.equalTo(radius1)
}

animatedCircle.layer.addSublayer(animatedCircleLayer)
}

Expand Down
18 changes: 14 additions & 4 deletions IVPNClient/Scenes/MainScreen/Map/MapScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import UIKit
import NetworkExtension
import Bamboo
import SnapKit

class MapScrollView: UIScrollView {
Expand Down Expand Up @@ -55,8 +54,8 @@ class MapScrollView: UIScrollView {
let markerLocalView = MapMarkerView(type: .local)
let markerGatewayView = MapMarkerView(type: .gateway)
var localCoordinates: (Double, Double)?
var currentCoordinates: (Double, Double)?

private lazy var iPadConstraints = bb.left(MapConstants.Container.iPadLandscapeLeftAnchor).top(MapConstants.Container.iPadLandscapeTopAnchor).constraints.deactivate()
private var markers: [UIButton] = []
private var connectToServerPopup = ConnectToServerPopupView()

Expand All @@ -76,9 +75,12 @@ class MapScrollView: UIScrollView {

func setupConstraints() {
if UIDevice.current.userInterfaceIdiom == .pad && UIApplication.shared.statusBarOrientation.isLandscape {
iPadConstraints.activate()
snp.remakeConstraints { make in
make.top.equalTo(MapConstants.Container.iPadLandscapeTopAnchor)
make.left.equalTo(MapConstants.Container.iPadLandscapeLeftAnchor)
}
} else {
iPadConstraints.deactivate()
snp.removeConstraints()
}
}

Expand Down Expand Up @@ -107,6 +109,12 @@ class MapScrollView: UIScrollView {
updateMapPosition(latitude: viewModel.model.latitude, longitude: viewModel.model.longitude, animated: animated, isLocalPosition: true)
}

func updateMapPositionToCurrentCoordinates() {
if let currentCoordinates = currentCoordinates {
updateMapPosition(latitude: currentCoordinates.0, longitude: currentCoordinates.1, isLocalPosition: false, updateMarkers: false)
}
}

func updateMapPosition(latitude: Double, longitude: Double, animated: Bool = false, isLocalPosition: Bool, updateMarkers: Bool = true) {
let halfWidth = Double(UIScreen.main.bounds.width / 2)
let halfHeight = Double(UIScreen.main.bounds.height / 2)
Expand All @@ -125,6 +133,8 @@ class MapScrollView: UIScrollView {
if updateMarkers {
updateMarkerPosition(x: point.0 - 49, y: point.1 - 49, isLocalPosition: isLocalPosition)
}

currentCoordinates = (latitude, longitude)
}

// MARK: - Private methods -
Expand Down
30 changes: 27 additions & 3 deletions IVPNClient/Scenes/MainScreen/View/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class MainView: UIView {
updateMapPosition(animated: animated)
}

func updateLayout() {
setupConstraints()
updateInfoAlert()
updateActionButtons()
mapScrollView.updateMapPositionToCurrentCoordinates()
}

func updateStatus(vpnStatus: NEVPNStatus) {
updateMapPosition(vpnStatus: vpnStatus)
mapScrollView.updateStatus(vpnStatus: vpnStatus)
Expand All @@ -98,17 +105,34 @@ class MainView: UIView {
private func initSettingsAction() {
let settingsButton = UIButton()
addSubview(settingsButton)
settingsButton.bb.size(width: 42, height: 42).top(55).right(-30)

settingsButton.snp.makeConstraints { make in
make.width.equalTo(42)
make.height.equalTo(42)
make.top.equalTo(55)
make.right.equalTo(-30)
}

settingsButton.setupIcon(imageName: "icon-settings")
settingsButton.accessibilityLabel = "Settings"
settingsButton.addTarget(self, action: #selector(openSettings), for: .touchUpInside)

let accountButton = UIButton()
addSubview(accountButton)
if UIDevice.current.userInterfaceIdiom == .pad {
accountButton.bb.size(width: 42, height: 42).top(55).right(-100)
accountButton.snp.makeConstraints { make in
make.width.equalTo(42)
make.height.equalTo(42)
make.top.equalTo(55)
make.right.equalTo(-100)
}
} else {
accountButton.bb.size(width: 42, height: 42).top(55).left(30)
accountButton.snp.makeConstraints { make in
make.width.equalTo(42)
make.height.equalTo(42)
make.top.equalTo(55)
make.left.equalTo(30)
}
}
accountButton.setupIcon(imageName: "icon-user")
accountButton.accessibilityLabel = "Account"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//

import UIKit
import Bamboo
import SnapKit

class CreateAccountView: UIView {

Expand All @@ -46,7 +46,10 @@ class CreateAccountView: UIView {

private func setupLayout() {
if UIDevice.current.userInterfaceIdiom == .pad {
accountView.bb.left(21).right(-21)
accountView.snp.makeConstraints { make in
make.left.equalTo(21)
make.right.equalTo(-21)
}
}

}
Expand Down
15 changes: 12 additions & 3 deletions IVPNClient/Scenes/Signup/Payment/PaymentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import UIKit
import SwiftyStoreKit
import Bamboo
import SnapKit
import JGProgressHUD

class PaymentViewController: UITableViewController {
Expand Down Expand Up @@ -162,8 +162,17 @@ class PaymentViewController: UITableViewController {
tableView.separatorStyle = .none
view.addSubview(spinner)
view.addSubview(retryButton)
spinner.bb.centerX().centerY(-80)
retryButton.bb.centerX().centerY(-80)

spinner.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().offset(-80)
}

retryButton.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().offset(-80)
}

descriptionLabel?.text = "Add more time to your IVPN account"
payButton?.set(title: "Pay", subtitle: "(Will be active until \(service.willBeActiveUntil))")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
//

import UIKit
import Bamboo
import SnapKit

class PaymentComponentView: UIView {

// MARK: - View lifecycle -

override func awakeFromNib() {
if UIDevice.current.userInterfaceIdiom == .pad {
bb.left(4)
snp.makeConstraints { make in
make.left.equalTo(4)
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions IVPNClient/Scenes/Signup/SelectPlan/SelectPlanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//

import UIKit
import Bamboo
import SnapKit
import JGProgressHUD

class SelectPlanViewController: UITableViewController {
Expand Down Expand Up @@ -177,8 +177,16 @@ class SelectPlanViewController: UITableViewController {
tableView.separatorStyle = .none
view.addSubview(spinner)
view.addSubview(retryButton)
spinner.bb.centerX().centerY(-80)
retryButton.bb.centerX().centerY(-80)

spinner.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().offset(-80)
}

retryButton.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().offset(-80)
}

if changingPlan {
selectPlanView?.setupView(service: service)
Expand Down
19 changes: 15 additions & 4 deletions IVPNClient/Scenes/Signup/SelectPlan/View/SelectPlanView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//

import UIKit
import Bamboo
import SnapKit

class SelectPlanView: UITableView {

Expand Down Expand Up @@ -75,9 +75,20 @@ class SelectPlanView: UITableView {
messageLabel.sizeToFit()

if UIDevice.current.userInterfaceIdiom == .pad {
messageLabel.bb.left(21).right(-21)
standardView.bb.left(21).right(-21)
proView.bb.left(21).right(-21)
messageLabel.snp.makeConstraints { make in
make.left.equalTo(21)
make.right.equalTo(-21)
}

standardView.snp.makeConstraints { make in
make.left.equalTo(21)
make.right.equalTo(-21)
}

proView.snp.makeConstraints { make in
make.left.equalTo(21)
make.right.equalTo(-21)
}
}

}
Expand Down
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use_frameworks!

target 'IVPNClient' do
pod 'TunnelKit', '~> 2.2.7'
pod 'Bamboo', '~> 1.2.0'
pod 'KeychainAccess', '~> 3.2.0'
pod 'SwiftyStoreKit', '~> 0.15.0'
pod 'JGProgressHUD', '~> 2.0.3'
Expand Down
Loading

0 comments on commit 4a70b06

Please sign in to comment.