Skip to content

Commit a25b659

Browse files
committed
Move views out of extension.
#564 (comment)
1 parent fe00e12 commit a25b659

File tree

1 file changed

+66
-68
lines changed

1 file changed

+66
-68
lines changed

Shared/Samples/Snap geometry edits with utility network rules/SnapGeometryEditsWithUtilityNetworkRulesView.swift

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -154,85 +154,83 @@ struct SnapGeometryEditsWithUtilityNetworkRulesView: View {
154154

155155
// MARK: - Helper Views
156156

157-
private extension SnapGeometryEditsWithUtilityNetworkRulesView {
158-
/// A list for enabling and disabling snap source settings.
159-
struct SnapSourcesList: View {
160-
/// The snap source settings to show in the list.
161-
let settings: [SnapSourceSettings]
162-
163-
/// The action to dismiss the view.
164-
@Environment(\.dismiss) private var dismiss
165-
166-
/// The display scale of this environment.
167-
@Environment(\.displayScale) private var displayScale
168-
169-
/// The images for the snap rule behavior legend.
170-
@State private var ruleBehaviorImages: [SnapRuleBehavior?: Image] = [:]
171-
172-
var body: some View {
173-
NavigationStack {
174-
Form {
175-
Section {
176-
ForEach(Array(settings.enumerated()), id: \.offset) { _, settings in
177-
SnapSourceSettingsToggle(
178-
settings: settings,
179-
image: ruleBehaviorImages[settings.ruleBehavior]
180-
)
181-
}
157+
/// A list for enabling and disabling snap source settings.
158+
private struct SnapSourcesList: View {
159+
/// The snap source settings to show in the list.
160+
let settings: [SnapSourceSettings]
161+
162+
/// The action to dismiss the view.
163+
@Environment(\.dismiss) private var dismiss
164+
165+
/// The display scale of this environment.
166+
@Environment(\.displayScale) private var displayScale
167+
168+
/// The images for the snap rule behavior legend.
169+
@State private var ruleBehaviorImages: [SnapRuleBehavior?: Image] = [:]
170+
171+
var body: some View {
172+
NavigationStack {
173+
Form {
174+
Section {
175+
ForEach(Array(settings.enumerated()), id: \.offset) { _, settings in
176+
SnapSourceSettingsToggle(
177+
settings: settings,
178+
image: ruleBehaviorImages[settings.ruleBehavior]
179+
)
182180
}
183-
184-
Section("Legend") {
185-
ForEach(SnapRuleBehavior?.allCases, id: \.self) { behavior in
186-
Label {
187-
Text(behavior.label)
188-
} icon: {
189-
ruleBehaviorImages[behavior]
190-
}
191-
.task(id: displayScale) {
192-
// Creates an image from the rule behavior's symbol.
193-
let swatch = try? await behavior.symbol.makeSwatch(scale: displayScale)
194-
ruleBehaviorImages[behavior] = Image(uiImage: swatch ?? UIImage())
195-
}
181+
}
182+
183+
Section("Legend") {
184+
ForEach(SnapRuleBehavior?.allCases, id: \.self) { behavior in
185+
Label {
186+
Text(behavior.label)
187+
} icon: {
188+
ruleBehaviorImages[behavior]
189+
}
190+
.task(id: displayScale) {
191+
// Creates an image from the rule behavior's symbol.
192+
let swatch = try? await behavior.symbol.makeSwatch(scale: displayScale)
193+
ruleBehaviorImages[behavior] = Image(uiImage: swatch ?? UIImage())
196194
}
197195
}
198196
}
199-
.navigationTitle("Snap Sources")
200-
.navigationBarTitleDisplayMode(.inline)
201-
.toolbar {
202-
ToolbarItem(placement: .confirmationAction) {
203-
Button("Done") { dismiss() }
204-
}
197+
}
198+
.navigationTitle("Snap Sources")
199+
.navigationBarTitleDisplayMode(.inline)
200+
.toolbar {
201+
ToolbarItem(placement: .confirmationAction) {
202+
Button("Done") { dismiss() }
205203
}
206204
}
207205
}
208206
}
207+
}
208+
209+
/// A toggle for enabling and disabling a given snap source settings.
210+
private struct SnapSourceSettingsToggle: View {
211+
/// The snap source settings to enable and disable.
212+
let settings: SnapSourceSettings
209213

210-
/// A toggle for enabling and disabling a given snap source settings.
211-
struct SnapSourceSettingsToggle: View {
212-
/// The snap source settings to enable and disable.
213-
let settings: SnapSourceSettings
214-
215-
/// The image to use in the toggle's label.
216-
let image: Image?
217-
218-
/// A Boolean value indicating whether the toggle is enabled.
219-
@State private var isEnabled = false
220-
221-
var body: some View {
222-
Toggle(isOn: $isEnabled) {
223-
Label {
224-
Text(settings.source.name)
225-
} icon: {
226-
image
227-
}
228-
}
229-
.onChange(of: isEnabled) { newValue in
230-
settings.isEnabled = newValue
231-
}
232-
.onAppear {
233-
isEnabled = settings.isEnabled
214+
/// The image to use in the toggle's label.
215+
let image: Image?
216+
217+
/// A Boolean value indicating whether the toggle is enabled.
218+
@State private var isEnabled = false
219+
220+
var body: some View {
221+
Toggle(isOn: $isEnabled) {
222+
Label {
223+
Text(settings.source.name)
224+
} icon: {
225+
image
234226
}
235227
}
228+
.onChange(of: isEnabled) { newValue in
229+
settings.isEnabled = newValue
230+
}
231+
.onAppear {
232+
isEnabled = settings.isEnabled
233+
}
236234
}
237235
}
238236

0 commit comments

Comments
 (0)