Skip to content

Commit 1d6023e

Browse files
authoredMar 13, 2025
Refactor FXIOS-7301 - Remove 2 closure_body_length violations from ImageButtonWithLabel.swift and DefaultBrowserOnboardingView.swift, and decrease threshold (#25188)
* Decrease warning and error threshold * Extract the label view * Use the new property to show label * Extract the logo view * Extract the background view * Use the new property to show background * Extract the title view * Use the new property to show title * Extract the subtitle view * Use the new property to show subtitle * Extract the top button view * Use the new property to show top button * Extract the bottom button view * Use the new property to show bottom button * Extract the close button view * Use the new property to show close button * Add access modifier * Rename property
1 parent c911f31 commit 1d6023e

File tree

3 files changed

+114
-78
lines changed

3 files changed

+114
-78
lines changed
 

‎.swiftlint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ line_length:
103103
ignores_interpolated_strings: true
104104

105105
closure_body_length:
106-
warning: 50
107-
error: 50
106+
warning: 49
107+
error: 49
108108

109109
file_header:
110110
required_string: |

‎firefox-ios/WidgetKit/ImageButtonWithLabel.swift

+53-37
Original file line numberDiff line numberDiff line change
@@ -64,56 +64,72 @@ struct ImageButtonWithLabel: View {
6464
Link(destination: isSmall ? link.smallWidgetUrl : link.mediumWidgetUrl) {
6565
ZStack(alignment: .leading) {
6666
if !isSmall {
67-
ContainerRelativeShape()
68-
.fill(
69-
LinearGradient(
70-
gradient: Gradient(colors: link.backgroundColors),
71-
startPoint: .bottomLeading,
72-
endPoint: .topTrailing
73-
)
74-
)
75-
.widgetAccentableCompat()
67+
background
7668
}
7769

7870
VStack(alignment: .center, spacing: 50.0) {
7971
HStack(alignment: .top) {
80-
VStack(alignment: .leading) {
81-
if isSmall {
82-
Text(link.label)
83-
.font(.headline)
84-
.minimumScaleFactor(0.75)
85-
.layoutPriority(1000)
86-
} else {
87-
Text(link.label)
88-
.font(.footnote)
89-
.minimumScaleFactor(0.75)
90-
.layoutPriority(1000)
91-
}
92-
}
72+
label
9373
Spacer()
94-
if link == .search && isSmall {
95-
Image(decorative: StandardImageIdentifiers.Large.search)
96-
.scaledToFit()
97-
.frame(height: 24.0)
98-
} else {
99-
Image(decorative: link.imageName)
100-
.scaledToFit()
101-
.frame(height: 24.0)
102-
}
74+
logo
10375
}
10476
if isSmall {
105-
HStack(alignment: .bottom) {
106-
Spacer()
107-
Image(decorative: "faviconFox")
108-
.scaledToFit()
109-
.frame(height: 24.0)
110-
}
77+
icon
11178
}
11279
}
11380
.foregroundColor(Color("widgetLabelColors"))
11481
.padding([.horizontal, .vertical], paddingValue)
11582
}
11683
}
11784
}
85+
86+
private var background: some View {
87+
return ContainerRelativeShape()
88+
.fill(
89+
LinearGradient(
90+
gradient: Gradient(colors: link.backgroundColors),
91+
startPoint: .bottomLeading,
92+
endPoint: .topTrailing
93+
)
94+
)
95+
.widgetAccentableCompat()
96+
}
97+
98+
private var label: some View {
99+
return VStack(alignment: .leading) {
100+
if isSmall {
101+
Text(link.label)
102+
.font(.headline)
103+
.minimumScaleFactor(0.75)
104+
.layoutPriority(1000)
105+
} else {
106+
Text(link.label)
107+
.font(.footnote)
108+
.minimumScaleFactor(0.75)
109+
.layoutPriority(1000)
110+
}
111+
}
112+
}
113+
114+
private var logo: some View {
115+
if link == .search && isSmall {
116+
return Image(decorative: StandardImageIdentifiers.Large.search)
117+
.scaledToFit()
118+
.frame(height: 24.0)
119+
} else {
120+
return Image(decorative: link.imageName)
121+
.scaledToFit()
122+
.frame(height: 24.0)
123+
}
124+
}
125+
126+
private var icon: some View {
127+
return HStack(alignment: .bottom) {
128+
Spacer()
129+
Image(decorative: "faviconFox")
130+
.scaledToFit()
131+
.frame(height: 24.0)
132+
}
133+
}
118134
}
119135
#endif

‎focus-ios/BlockzillaPackage/Sources/Onboarding/SwiftUI Onboarding/DefaultBrowserOnboardingView.swift

+59-39
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,20 @@ struct DefaultBrowserOnboardingView: View {
1515
VStack {
1616
HStack {
1717
Spacer()
18-
Button(action: {
19-
viewModel.send(.defaultBrowserCloseTapped)
20-
}, label: {
21-
Image.close
22-
})
18+
closeOnboardingButton
2319
}
2420
Image.huggingFocus
2521
.resizable()
2622
.scaledToFit()
2723
.frame(maxHeight: .imageMaxHeight)
2824
VStack {
29-
Text(viewModel.defaultBrowserConfig.title)
30-
.bold()
31-
.font(.system(size: .titleSize))
32-
.multilineTextAlignment(.center)
33-
.padding(.bottom, .titleBottomPadding)
34-
VStack(alignment: .leading) {
35-
Text(viewModel.defaultBrowserConfig.firstSubtitle)
36-
.padding(.bottom, .firstSubtitleBottomPadding)
37-
Text(viewModel.defaultBrowserConfig.secondSubtitle)
38-
}
39-
.font(.body16)
25+
title
26+
subtitles
4027
}
4128
.foregroundColor(.secondOnboardingScreenText)
4229
Spacer()
43-
Button(action: {
44-
viewModel.send(.defaultBrowserSettingsTapped)
45-
}, label: {
46-
Text(viewModel.defaultBrowserConfig.topButtonTitle)
47-
.foregroundColor(.systemBackground)
48-
.font(.body16Bold)
49-
.frame(maxWidth: .infinity)
50-
.frame(height: .buttonHeight)
51-
.background(Color.actionButton)
52-
.cornerRadius(.radius)
53-
})
54-
Button(action: {
55-
viewModel.send(.defaultBrowserSkip)
56-
}, label: {
57-
Text(viewModel.defaultBrowserConfig.bottomButtonTitle)
58-
.foregroundColor(.black)
59-
.font(.body16Bold)
60-
.frame(maxWidth: .infinity)
61-
.frame(height: .buttonHeight)
62-
.background(Color.secondOnboardingScreenBottomButton)
63-
.cornerRadius(.radius)
64-
})
65-
.padding(.bottom, .skipButtonPadding)
30+
openSettingsButton
31+
skipOnboardingButton
6632
}
6733
.padding([.leading, .trailing], .viewPadding)
6834
.navigationBarHidden(true)
@@ -72,6 +38,60 @@ struct DefaultBrowserOnboardingView: View {
7238
viewModel.send(.defaultBrowserAppeared)
7339
}
7440
}
41+
42+
private var closeOnboardingButton: some View {
43+
return Button(action: {
44+
viewModel.send(.defaultBrowserCloseTapped)
45+
}, label: {
46+
Image.close
47+
})
48+
}
49+
50+
private var title: some View {
51+
return Text(viewModel.defaultBrowserConfig.title)
52+
.bold()
53+
.font(.system(size: .titleSize))
54+
.multilineTextAlignment(.center)
55+
.padding(.bottom, .titleBottomPadding)
56+
}
57+
58+
private var subtitles: some View {
59+
return VStack(alignment: .leading) {
60+
Text(viewModel.defaultBrowserConfig.firstSubtitle)
61+
.padding(.bottom, .firstSubtitleBottomPadding)
62+
Text(viewModel.defaultBrowserConfig.secondSubtitle)
63+
}
64+
.font(.body16)
65+
}
66+
67+
private var openSettingsButton: some View {
68+
return Button(action: {
69+
viewModel.send(.defaultBrowserSettingsTapped)
70+
}, label: {
71+
Text(viewModel.defaultBrowserConfig.topButtonTitle)
72+
.foregroundColor(.systemBackground)
73+
.font(.body16Bold)
74+
.frame(maxWidth: .infinity)
75+
.frame(height: .buttonHeight)
76+
.background(Color.actionButton)
77+
.cornerRadius(.radius)
78+
})
79+
}
80+
81+
private var skipOnboardingButton: some View {
82+
return Button(action: {
83+
viewModel.send(.defaultBrowserSkip)
84+
}, label: {
85+
Text(viewModel.defaultBrowserConfig.bottomButtonTitle)
86+
.foregroundColor(.black)
87+
.font(.body16Bold)
88+
.frame(maxWidth: .infinity)
89+
.frame(height: .buttonHeight)
90+
.background(Color.secondOnboardingScreenBottomButton)
91+
.cornerRadius(.radius)
92+
})
93+
.padding(.bottom, .skipButtonPadding)
94+
}
7595
}
7696

7797
fileprivate extension CGFloat {

0 commit comments

Comments
 (0)
Failed to load comments.