-
The craft of SwiftUI API design: Progressive disclosure
Explore progressive disclosure — one of SwiftUI's core principles — and learn how it influences the design of our APIs. We'll show you how we use progressive disclosure, discuss how it can support quick iteration and exploration, and help you take advantage of it in your own code.
Recursos
-
Buscar neste vídeo...
-
-
1:59 - Declaration Site Example
struct BookView: View { let pageNumber: Int let book: Book init(book: Book, pageNumber: Int) { self.book = book self.pageNumber = pageNumber } var body: some View { ... } } -
2:13 - Call Site Example
VStack { BookView(book: favoriteBook, page: 1) BookView(book: savedBook, page: 234) } -
4:18 - Button Label
Button("Next Page") { currentPage += 1 } -
4:36 - Button label expanded
Button { currentPage += 1 } label: { Text("Next Page") } -
4:43 - Button label advanced case
Button { currentPage += 1 } label: { HStack { Text("Next Page") NextPagePreview() } } -
4:56 - Button label common case
Button("Next Page") { currentPage += 1 } -
5:30 - Text example
Text("Hello WWDC22!") -
6:12 - Stacks of Text
VStack { Text("Hello WWDC22!") Text("Call to Code.") } -
6:46 - Toolbar
.toolbar { Button { addItem() } label: { Label("Add", systemImage: "plus") } Button { sort() } label: { Label("Sort", systemImage: "arrow.up.arrow.down") } Button { openShareSheet() }: label: { Label("Share", systemImage: "square.and.arrow.up") } } -
7:20 - Toolbar with explicit placement
.toolbar { ToolbarItemGroup(placement: .navigationBarLeading) { Button { addItem() } label: { Label("Add", systemImage: "plus") } Button { sort() } label: { Label("Sort", systemImage: "arrow.up.arrow.down") } Button { openShareSheet() }: label: { Label("Share", systemImage: "square.and.arrow.up") } } } -
8:09 - Advanced use case table
@State var sortOrder = [KeyPathComparator(\Book.title)] var body: some View { Table(sortOrder: $sortOrder) { TableColumn("Title", value: \Book.title) { book in Text(book.title).bold() } TableColumn("Author", value: \Book.author) { book in Text(book.author).italic() } } rows: { Section("Favorites") { ForEach(favorites) { book in TableRow(book) } } Section("Currently Reading") { ForEach(currentlyReading) { book in TableRow(book) } } } .onChange(of: sortOrder) { newValue in favorites.sort(using: newValue) currentlyReading.sort(using: newValue) } } -
8:41 - Simpler table use case
@State var sortOrder = [KeyPathComparator(\Book.title)] var body: some View { Table(sortOrder: $sortOrder) { TableColumn("Title", value: \Book.title) { book in Text(book.title) } TableColumn("Author", value: \Book.author) { book in Text(book.author) } } rows: { ForEach(currentlyReading) { book in TableRow(book) } } .onChange(of: sortOrder) { newValue in currentlyReading.sort(using: newValue) } } -
9:58 - Table collection convenience
@State var sortOrder = [KeyPathComparator(\Book.title)] var body: some View { Table(currentlyReading, sortOrder: $sortOrder) { TableColumn("Title", value: \.title) { book in Text(book.title) } TableColumn("Author", value: \.author) { book in Text(book.author) } } .onChange(of: sortOrder) { newValue in currentlyReading.sort(using: newValue) } } -
10:23 - Table string key path convenience
@State var sortOrder = [KeyPathComparator(\Book.title)] var body: some View { Table(currentlyReading, sortOrder: $sortOrder) { TableColumn("Title", value: \.title) TableColumn("Author", value: \.author) } .onChange(of: sortOrder) { newValue in currentlyReading.sort(using: newValue) } } -
10:51 - Table without sorting
var body: some View { Table(currentlyReading) { TableColumn("Title", value: \.title) TableColumn("Author", value: \.author) } } -
13:37 - Stack example: leading
struct StackExample: View { var body: some View { HStack { // leading Box().tint(.red) Box().tint(.green) Box().tint(.blue) } } } -
13:40 - Stack example: centered
struct StackExample: View { var body: some View { HStack { // centered Spacer() Box().tint(.red) Box().tint(.green) Box().tint(.blue) Spacer() } } } -
13:42 - Stack example: evenly spaced
struct StackExample: View { var body: some View { HStack { // evenly spaced Spacer() Box().tint(.red) Spacer() Box().tint(.green) Spacer() Box().tint(.blue) Spacer() } } } -
13:43 - Stack example: space only between elements
struct StackExample: View { var body: some View { HStack { // space only between elements Box().tint(.red) Spacer() Box().tint(.green) Spacer() Box().tint(.blue) } } } -
13:46 - Stack example: space only before last element
struct StackExample: View { var body: some View { HStack { // space only before last element Box().tint(.red) Box().tint(.green) Spacer() Box().tint(.blue) } } } -
13:47 - Stack example: space only after first element
struct StackExample: View { var body: some View { HStack { // space only after first element Box().tint(.red) Spacer() Box().tint(.green) Box().tint(.blue) } } }
-