Reading time: 2 min

This recipe shows how to show multiple Alerts, ActionSheets or custom dialogs, without tying them to multiple views. The end result looks like this:

ezgif-3-31b97e7c1ad8

The usual way of using multiple views has its shortcomings, as it:

  • Forces you to have at least as many views as distinct modals you wish...

Continue Reading...

Reading time: 1 min

For whatever reason, stroking (i.e drawing a border) and filling a SwiftUI Shape at the same time is difficult and unintuitive. Shape has methods for both, stroke and fill, respectively, but they both return some View, meaning you can't chain them.

Say you want to do the following:

Screenshot%202021-07-21%20at%2021.02.45

T...

Continue Reading...

Reading time: 5 min

This recipe shows how to implement a custom Slider in SwiftUI. The default Slider view isn't particularly customisable, so any stepping outside the norm requires custom code.

Here's what the end result will look like:

  • On the top you have the default Slider.
  • In the middle there's our cust...

Continue Reading...

Reading time: 1 min

This quick recipe shows how to get size of a SwiftUI View at runtime. This is useful when your layout depends on a particular view's dimensions.

So the trick is to embed a GeometryReader in the view's background or overlay. The resulting GeometryProxy's size will the that of the view its...

Continue Reading...

Reading time: 1 min

This recipe shows how to implement shake gesture detection in SwiftUI. The result looks like this (you'll have to image the phone being shaken :)):

Preview

This component is available as a Swift Package in this repo.

The recipe is as follows:

  1. Override UIWindow's motionEnded for motion...

Continue Reading...