Skip to content

Instantly share code, notes, and snippets.

@drewmccormack
Created June 21, 2019 13:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewmccormack/8202687caa133684d58a9db342e34564 to your computer and use it in GitHub Desktop.
Save drewmccormack/8202687caa133684d58a9db342e34564 to your computer and use it in GitHub Desktop.
Here is some SwiftUI code I have.
------
NavigationView {
List(translations) { translation in
Button(action: {
self.dataSource.selectedTranslationId = translation.id
}) {
TranslationCell(translation: translation)
}
}
.navigationBarTitle(Text("Translations"))
.navigationBarItems(
leading:
Button(action: {
self.sceneDelegate?.signOut()
}, label: { Text("Sign Out") }),
trailing:
Group {
if dataSource.showingAdminInterface {
Button(action: {
self.sceneDelegate?.showImportView()
}, label: {
Image(systemName: "plus.circle.fill")
.imageScale(.large)
.foregroundColor(.green)
})
}
}
)
}
.frame(minWidth: 300, idealWidth: 320)
I find it very difficult to read. Difficult to follow indentation. Difficult to see what modifiers apply,
because modifiers for children appear under the definition of the children.
Here is a stab at a data format that represents the same info in a more sane way:
NavigationView (
[[
frame: (
minWidth: 300
idealWidth: 320
)
]]
views: [
List (
[[
navigationBarTitle: [Text("Translations")]
navigationBarItems: (
leading: [
Button (
action: { self.sceneDelegate?.signOut() }
label: [Text("Sign Out")]
)
]
trailing: [
Group (
if dataSource.showingAdminInterface {
Button (
action: { self.sceneDelegate?.showImportView() }
label: [
Image (
[[
imageScale: .large
foregroundColor: .green
]]
systemName: "plus.circle.fill"
)
]
)
}
)
]
)
]]
items: translations
views: [ translation in
Button (
action: {
self.dataSource.selectedTranslationId = translation.id
}
views: [
TranslationCell(translation: translation)
]
)
]
)
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment