bigmountainstudio / What-is-new-in-SwiftUI

A list of everything new for SwiftUI after WWDC 2022.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What's New In SwiftUI for iOS Cheat Sheet - WWDC22

new

By Big Mountain Studio

A list of everything new in SwiftUI after WWDC 2022.

Working with Data

Environment Values

SwiftUI Views

New Controls

  • AnyLayout - A view that can represent a container view such as a VStack, HStack, grids, etc.
  • Chart - A SwiftUI view that displays a chart.
  • Gauge - A view that shows a value within a range. This can be circular or straight.
  • Grid - A container view that arranges other views in a two dimensional layout with the use of the GridRow.
  • LabeledContent - A container for attaching a label to a value-bearing view. This way it can layout appropriately depending on where it's used. For example, if in a Form, the label will be leading and the content portion will be trailing and gray.
  • Layout Protocol - A new protocol that you can conform to so you can create your own custom layout container control.
  • MultiDatePicker - A control for picking multiple dates.
  • NavigationStack - A view that displays a root view and enables you to present additional views over the root view. To navigate, use a NavigationLink in combination with the navigationDestination modifier. You can also specify a NavigationPath to create or manage your stack of views.
  • NavigationSplitView - A container that presents 2 or 3 views in columns. (sidebar, content, detail)
  • PhotosPicker - A view that displays a Photos picker for choosing assets from the photo library. A selected photo is represented by a PhotosPickerItem.
  • RenameButton - A button that triggers a standard rename action. Used with the renameAction modifier.
  • ShareLink - A view that controls a sharing presentation.
  • Table - A container that presents rows of data arranged in one or more columns, optionally providing the ability to select one or more members, sort data, and style it.
  • ViewThatFits - A container view that adapts to the available space by providing the first child view that fits.

Updated Controls

Color

  • Has a new fixed gradient modifier that seems to lighten the color at the top in a linear gradient.
  • You can apply a shadow directly to a color too.
  • Shadows can now be drop or inner shadows.

NavigationLink

  • You can still use a basic NavigationLink with a string and destination. (NavigationLink("Go here") { Text("Here") }
  • Also works in combination with the navigationDestination modifier. NavigationLinks have values and if there is a navigationDestination modifier that matches the NavigationLink's value type, then it is used and navigates to the view the navigationDestination specifies.

Stepper

  • You can provide a format parameter to handle conversions for number, percent, dateTime, iso8601 date format and now URL format.

Toggle

  • You can bind a Toggle to a collection of values.
  • Multiple Text views within will be arranged hierarchically. (Second line less prominent than first line.)

Accessibility Modifiers

Appearance Modifiers

  • backgroundStyle - Sets the specified style to render backgrounds within the view.
  • tint(ShapeStyle) - Sets the tint within this view using a ShapeStyle (which can be a color, gradient, blur, etc).
  • scrollDisabled - Disables or enables scrolling in scrollable views.
  • menuOrder - The preferred order of items for menus. (Fixed, Priority)
  • persistentSystemOverlays - Preferred visibility of the non-transient system views overlaying the app.
  • scrollIndicators(:axes:) - Sets the visibility of scroll indicators within this view.
  • widgetAccentable - Adds view and all subviews to the accented group.
  • widgetLabel - Returns a text label that displays additional content outside the accessory family widget’s main SwiftUI view.

Text and Symbol Modifiers

Many of the modifiers that were just for Text can now be applied to any view and all Text within will adopt the modifier.

Navigation Modifiers

Toolbar Modifiers

  • toolbar(:for:) - Specifies the visibility of a bar managed by SwiftUI. (Place it automatically, bottom, navigation bar, tab bar or window toolbar.)
  • toolbarBackground - Specify the visibility of the background for the specified bar.
  • toolbarColorScheme - Specifies the preferred color scheme (light or dark) for the specified bar.
  • toolbarRole - Configures the semantic role (automatic, browser, editor, navigationStack) for the content populating the toolbar.

Context Menu

Style Modifiers

Grid Modifiers

  • gridCellColumns - Tells a view that acts as a cell in a grid to span the specified number of rows.
  • gridCellAnchor - Custom alignment anchor for a view that acts as a grid cell. (top, topLeading, topTrailing, bottom, etc.)
  • gridCellUnsizedAxes - Asks grid layouts not to offer the view extra size in the specified axes (horizontal or vertical).
  • gridColumnAlignment - Overrides the default horizontal alignment of the grid column that the view appears in.

Input and Event Modifiers

  • SpatialTapGesture - A gesture that recognizes one or more taps and reports their location.
  • onTapGesture(count:coordinateSpace:perform:) - Adds a tap gesture within the specified coordinate space. The onTapGesture isn't new. But specifying the coordinate space is.
  • defersSystemGestures - Sets the screen edge from which you want your gesture to take precedence over the system gesture.
  • defaultFocus - Default focus is evaluated by assigning a value to a given focus state binding.

Searchable

There are over a dozen new searchable initializers that can be used now. Rather than go through them all, I think it would be better to just list out some of the new parameters:

  • scope: A binding for the active scope of the search field.
  • scopes: A view builder representing the scopes of the search field which will be used to populate a Picker.
  • token: A view builder that creates a view given an element in tokens.
  • tokens: A collection of tokens to display and edit in the search field.
  • suggestedTokens: A collection of tokens to display as suggestions.

SearchSuggestionsPlacement - A structure that defines ways in which search suggestions may be placed. (automatic, content, menu)

Presentation Modifiers

State Modifiers

  • backgroundPreferenceValue - Reads the specified preference value from the view, using it to produce a second view that is applied as the background of the original view.
  • overlayPreferenceValue - Reads the specified preference value from the view, using it to produce a second view that is applied as an overlay to the original view.

Text Input & Output

TextField

  • The TextField can now overflow horizontally or vertically by specifying an axis.
  • A lineLimit modifier with one or a range of values can be added to specify how much the TextField can grow. Beyond that a scroll indicator will appear.

TextEditor

  • findNavigator - Programmatically presents the find and replace interface for text editor views.
  • findDisabled - Prevents find and replace operations in a text editor.
  • replaceDisabled - Prevents replace operations in a text editor.

Font

Images

The Image initializer now has a new parameter called variableValue that the rendered image can use to customize its appearance. If the symbols does not support it, this has no effect.

  • ImageRenderer - An object that creates images from SwiftUI views. So you can compose a SwiftUI view and then generate an image or PDF from it.

Animations

  • contentTransition - Modifies the view to use a given transition as its method of animating changes to the contents of its views.

Charts

  • Chart - A SwiftUI view that displays a chart. You can customize many parts of the chart:
    • Background
    • Foreground
    • Style such as bar, point, area, rule, rectangle or line charts
    • Plot area
    • Legends
    • Overlays
    • Visibility of the X or Y axis
    • Scale of the X or Y axis
    • Scale and size of symbols used

Gold logo

About

A list of everything new for SwiftUI after WWDC 2022.