Skip to content

Commit a317f83

Browse files
committed
Fix SwiftLint and SwiftFormat violations
Refactored setupConstraints() to fix function body length violation and applied SwiftFormat auto-formatting.
1 parent ad78d19 commit a317f83

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
lines changed

Cryptomator/VaultDetail/ShareVault/ShareVaultViewController.swift

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,16 @@ class ShareVaultViewController: UIViewController {
223223
let contentLayoutGuide = scrollView.contentLayoutGuide
224224
let frameLayoutGuide = scrollView.frameLayoutGuide
225225

226-
var constraints: [NSLayoutConstraint] = [
226+
var constraints = createBaseConstraints(contentLayoutGuide: contentLayoutGuide, frameLayoutGuide: frameLayoutGuide)
227+
let topAnchor = addOptionalSubtitleConstraints(to: &constraints)
228+
let lastContentView = addContentConstraints(to: &constraints, topAnchor: topAnchor)
229+
addFooterConstraints(to: &constraints, lastContentView: lastContentView)
230+
231+
NSLayoutConstraint.activate(constraints)
232+
}
233+
234+
private func createBaseConstraints(contentLayoutGuide: UILayoutGuide, frameLayoutGuide: UILayoutGuide) -> [NSLayoutConstraint] {
235+
return [
227236
scrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
228237
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
229238
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
@@ -255,39 +264,40 @@ class ShareVaultViewController: UIViewController {
255264
visitHubButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -LayoutConstants.standardSpacing),
256265
visitHubButton.heightAnchor.constraint(equalToConstant: LayoutConstants.buttonHeight)
257266
]
267+
}
258268

259-
// Add subtitle constraints if it exists
260-
let topAnchorForContent: NSLayoutYAxisAnchor
261-
if viewModel.headerSubtitle != nil {
262-
constraints.append(contentsOf: [
263-
subtitleLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: LayoutConstants.titleToSubtitleSpacing),
264-
subtitleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: LayoutConstants.horizontalPadding),
265-
subtitleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -LayoutConstants.horizontalPadding)
266-
])
267-
topAnchorForContent = subtitleLabel.bottomAnchor
268-
} else {
269-
topAnchorForContent = titleLabel.bottomAnchor
269+
private func addOptionalSubtitleConstraints(to constraints: inout [NSLayoutConstraint]) -> NSLayoutYAxisAnchor {
270+
guard viewModel.headerSubtitle != nil else {
271+
return titleLabel.bottomAnchor
270272
}
271273

272-
// Determine the last content view (features or hub steps)
273-
let lastContentView: UIView
274+
constraints.append(contentsOf: [
275+
subtitleLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: LayoutConstants.titleToSubtitleSpacing),
276+
subtitleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: LayoutConstants.horizontalPadding),
277+
subtitleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -LayoutConstants.horizontalPadding)
278+
])
279+
return subtitleLabel.bottomAnchor
280+
}
281+
282+
private func addContentConstraints(to constraints: inout [NSLayoutConstraint], topAnchor: NSLayoutYAxisAnchor) -> UIView {
274283
if viewModel.hubSteps != nil {
275284
constraints.append(contentsOf: [
276-
hubStepsStackView.topAnchor.constraint(equalTo: topAnchorForContent, constant: LayoutConstants.subtitleToStepsSpacing),
285+
hubStepsStackView.topAnchor.constraint(equalTo: topAnchor, constant: LayoutConstants.subtitleToStepsSpacing),
277286
hubStepsStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: LayoutConstants.horizontalPadding),
278287
hubStepsStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -LayoutConstants.horizontalPadding)
279288
])
280-
lastContentView = hubStepsStackView
289+
return hubStepsStackView
281290
} else {
282291
constraints.append(contentsOf: [
283-
featuresLabel.topAnchor.constraint(equalTo: topAnchorForContent, constant: LayoutConstants.titleToFeaturesSpacing),
292+
featuresLabel.topAnchor.constraint(equalTo: topAnchor, constant: LayoutConstants.titleToFeaturesSpacing),
284293
featuresLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: LayoutConstants.horizontalPadding),
285294
featuresLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -LayoutConstants.horizontalPadding)
286295
])
287-
lastContentView = featuresLabel
296+
return featuresLabel
288297
}
298+
}
289299

290-
// Add footer constraints only if footer exists
300+
private func addFooterConstraints(to constraints: inout [NSLayoutConstraint], lastContentView: UIView) {
291301
if viewModel.footerText != nil {
292302
constraints.append(contentsOf: [
293303
footerTextView.topAnchor.constraint(equalTo: lastContentView.bottomAnchor, constant: LayoutConstants.largeSpacing),
@@ -300,8 +310,6 @@ class ShareVaultViewController: UIViewController {
300310
lastContentView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -LayoutConstants.titleSpacing)
301311
)
302312
}
303-
304-
NSLayoutConstraint.activate(constraints)
305313
}
306314

307315
private func createFooterAttributedText() -> NSAttributedString {

Cryptomator/VaultDetail/ShareVault/ShareVaultViewModel.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ class ShareVaultViewModel: ShareVaultViewModelProtocol {
4444
init(type: ShareVaultType) {
4545
switch type {
4646
case .normal:
47-
headerTitle = LocalizedString.getValue("shareVault.header.title")
48-
headerSubtitle = nil
49-
featuresText = LocalizedString.getValue("shareVault.header.features")
50-
hubSteps = nil
51-
footerText = LocalizedString.getValue("shareVault.footer.text")
52-
docsButtonTitle = LocalizedString.getValue("shareVault.footer.link")
53-
docsURL = URL(string: "https://docs.cryptomator.org/security/best-practices/#sharing-of-vaults")
54-
forTeamsButtonTitle = LocalizedString.getValue("shareVault.button.visitHub")
55-
forTeamsURL = URL(string: "https://cryptomator.org/for-teams/")
56-
case .hub(let hubURL):
57-
headerTitle = LocalizedString.getValue("shareVault.hub.header.title")
58-
headerSubtitle = LocalizedString.getValue("shareVault.hub.header.subtitle")
59-
featuresText = nil
60-
hubSteps = [
47+
self.headerTitle = LocalizedString.getValue("shareVault.header.title")
48+
self.headerSubtitle = nil
49+
self.featuresText = LocalizedString.getValue("shareVault.header.features")
50+
self.hubSteps = nil
51+
self.footerText = LocalizedString.getValue("shareVault.footer.text")
52+
self.docsButtonTitle = LocalizedString.getValue("shareVault.footer.link")
53+
self.docsURL = URL(string: "https://docs.cryptomator.org/security/best-practices/#sharing-of-vaults")
54+
self.forTeamsButtonTitle = LocalizedString.getValue("shareVault.button.visitHub")
55+
self.forTeamsURL = URL(string: "https://cryptomator.org/for-teams/")
56+
case let .hub(hubURL):
57+
self.headerTitle = LocalizedString.getValue("shareVault.hub.header.title")
58+
self.headerSubtitle = LocalizedString.getValue("shareVault.hub.header.subtitle")
59+
self.featuresText = nil
60+
self.hubSteps = [
6161
("1.circle.fill", LocalizedString.getValue("shareVault.hub.step1")),
6262
("2.circle.fill", LocalizedString.getValue("shareVault.hub.step2"))
6363
]
64-
footerText = nil
65-
docsButtonTitle = nil
66-
docsURL = nil
67-
forTeamsButtonTitle = LocalizedString.getValue("shareVault.hub.button.openHub")
68-
forTeamsURL = hubURL
64+
self.footerText = nil
65+
self.docsButtonTitle = nil
66+
self.docsURL = nil
67+
self.forTeamsButtonTitle = LocalizedString.getValue("shareVault.hub.button.openHub")
68+
self.forTeamsURL = hubURL
6969
}
7070
}
7171
}

0 commit comments

Comments
 (0)