Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Add What's new in SwiftUI [WWDC22] #231

Merged
merged 2 commits into from
Jun 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions content/notes/wwdc22/10052.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
contributors: Jeehut
---

- New SwiftUI app structure!?
- Apple is using SwiftUI more internally now

## Swift Charts

- `Chart` view that takes data, `BarMark`, `LineMark` and other views inside
- `.foregroundStyle(by: ...)` helps declaratively specify details
- `.symbol(by: ...)` to declaratively specify details in chart
- `.annotation` supported, e.g. for marks
- supports dark mode automatically (like any SwiftUI view)
- Smart defaults for legends etc.

## Navigation and windows

### Stacks

- `NavigationStack` a new container view for push/pop style navigation
- wraps a root content view
- works with `NavigationLink` and `.navigationTitle`
- New data-driven APIs: `.navigationDestination(for: ...)`
- `NavigationLink` can now take a value that represents a destination
- now also supported on macOS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


### Split Views

- `NavigationSplitView` for multi-column navigation
- can declare 2- or 3-column layouts
- accepts a `detail` view
- Split view adapts on resize automatically
- works with stack together for complex navigation structures

### Scene

- `Window` added for single unique windows of an app (not a group)
- appears automatically in `Windows` menu bar
- `.keyboardShortcut` to open the window easily
- new @Environment action openWindow available to call for navigation
- `.defaultPosition` and `defaultSize` for default positions of windows
- `.presentationDetents` modifier allows resizable sheets, e.g. with two different sizes
- Menu bar extras now entirely in SwiftUI via `MenuBarExtra`
- always shown in Menu Bar while app is running
- also possible to just provide a `MenuBarExtra` in an app as root scene

## Advanced controls

### Forms

- new settings app design in macOS uses new navigation SwiftUI views
- New `.formStyle(.grouped)` for forms to improve forms on macOS
- `LabeledContent` used to build new controls or just read-only information
- allows selection for simple data

- SwiftUI is now smarter in formatting text in Forms
- New popup menu pickers in iOS (macOS inspired dropdowns)

### Controls

- `TextField` can now have an expanding `axis` specified (e.g. `.vertical`
- `.lineLimit(5...10)` range helps expanding with min lines
- `MultiDatePicker` available now, too
- `DisclosureGroup` to combine multiple toggles in one toggle
- `Picker` also mixable with toggles … (didn’t understand)
- New button style
- `Stepper` with `format` parameter, now also available on watchOS
- `.accessibilityQuickAction` with button for easy accessibility

### Tables

- `Table` now supported on iPadOS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! Can close that feedback 💯

- Will render also on iPhone with a primary column
- new `.contextMenu` modifier with multiple selections possible
- allows to define advanced context menus
- new `.toolbar` in iPadOS, customizable by specifying explicit `id`
- placement: `.secondaryAction` to be used for toolbar items
- `.searchable` modifier now accepts `tokens:` for tokenized inputs
- it also supports `scope:` for search scopes (filters)

## Sharing

### Photos Picker

- `PhotosPicker` view anywhere in app, presents picker UI
- takes a binding to a selected `PhotosPickerItem`
- filtering type of content and more customizable

### Sharing

- watchOS supports `ShareLink` view, provide content and preview
- adapt to the `.contextMenu` they’re applied to

### Transferable

- Makes drag & drop easy
- `.dropDestination` with `payloadType`, comes with closure for received data
- many standard types conform to `Transferable`
- Implement in custom types by conforming to `representation: some TransferRepresentation`

## Graphics and layout

### Shape Styles

- new `.gradient` property on color
- new `.shadow` property on color, too
- Combined with SFSymbols, easy to make great custom icons
- soft glow via `.ellipticalGradient` for example
- Text and Image animatoins are taken to “the next level”, just use `withAnimation`

### Layout

- new `Grid` container view that arranges views in 2D grid
- enables automatic alignments across rows and colunns
- `Grid`, `GridRow` and `.gridCellColumns` APIs to specify
- new `Layout` protocol for even more customization
- new `AnyLayout` type to switch between layouts easily