Skip to content

v5.0-beta (multi-screen support)

Pre-release
Pre-release
Compare
Choose a tag to compare
@SwiftfulThinking SwiftfulThinking released this 04 Sep 21:14
· 57 commits to main since this release
7de396a

This update brings multi-screen support to the framework. Previously, we could only manage one screen at a time. Now, we can create and set of screens (or a flow) from a single call.

let screen1 = { router in
     MyView(router: router, count: 369)
}
let screen2 = { router in
     MyView(router: router, count: 444)
}
let screen3 = { router in
     MyView(router: router, count: 1000000)
}
let screen4 = { router in
     MyView(router: router, count: 123)
}
                
router.showScreens([
     AnyRoute(.fullScreenCover, destination: screen1),
     AnyRoute(.push, destination: screen2),
     AnyRoute(.push, destination: screen3),
     AnyRoute(.push, destination: screen4),
])

Once projects move towards this "flow" setup, the routing logic in each child view can be simplified to a simple "go to next screen". The "next screens" are set from a previous call to showScreens where the next screen is the next screen in the array.

try router.showNextScreen()

This update also introduces the ability to dismiss an environment. This will dismiss the top-most Sheet or FullScreenCover.

router.dismissEnvironment()

In the example above, there are 4 screens, the first one shows a fullScreenCover and then the following 3 screens are shown via push. From any of those screens, I can call dismissEnvironment and it will dismiss the fullScreenCover, which effectively dismisses the entire flow.

This is perfect for peripheral flows in your app, such as Onboarding, where you could present a FullScreenCover and then push to as many screens as needed. At the end of the flow, dismiss the environment!

A combination of these will simplify the routing logic in your flows. In the above example, I would build each of the screens with a generic call to action button, that would first attempt to go to the next screen in the flow, but otherwise fallback to dismissing the environment.

router.showNextScreenOrDismissEnvironment()