Skip to content

Commit

Permalink
Deprecate split view modifiers (#29)
Browse files Browse the repository at this point in the history
After some experimentation I came to the conclusion that split view
"transitions" are not meant to be modified directly. They're not even a
thing in itself, really.

Instead, it should be the stack navigation view *within* the split view
that can and should have their transition modified directly.

So I deprecated all the split view modifiers and flattened the 2 stack
modifiers into one: `.navigationTransition`. In addition to this, a
useful runtime warning will let you know when you're holding it wrong.

This drastically simplifies the API surface to a single entry point and
is, I believe, a step in the right direction to easing the entry barrier
for this library.
  • Loading branch information
davdroman authored Nov 10, 2022
1 parent 0ac3c1a commit ace502a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 252 deletions.
10 changes: 5 additions & 5 deletions Demo/Demo/Pages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ struct PageOne: View {
struct PageTwo: View {
var body: some View {
let content = Group {
Text("The library is fully compatible with **NavigationView** in iOS 13+, and the new **NavigationStack** and **NavigationSplitView** in iOS 16.")
Text("The library is fully compatible with **NavigationView** in iOS 13+, and the new **NavigationStack** in iOS 16.")
Text("In fact, that entire transition you just saw can be implemented in **one line** of SwiftUI code:")
Code("""
NavigationView {
NavigationStack {
...
}
.navigationViewStackTransition(.slide)
.navigationTransition(.slide)
"""
)
}
Expand All @@ -62,7 +62,7 @@ struct PageThree: View {
Text("The API is designed to resemble that of built-in SwiftUI Transitions for maximum **familiarity** and **ease of use**.")
Text("You can apply **custom animations** just like with standard SwiftUI transitions:")
Code("""
.navigationViewStackTransition(
.navigationTransition(
.fade(.in).animation(
.easeInOut(duration: 0.3)
)
Expand All @@ -71,7 +71,7 @@ struct PageThree: View {
)
Text("... and you can even **combine** them too:")
Code("""
.navigationViewStackTransition(
.navigationTransition(
.slide.combined(with: .fade(.in))
)
"""
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct RootView: View {
.navigationViewStyle(.stack)
}
}
.navigationViewStackTransition(
.navigationTransition(
appState.transition().animation(appState.animation()),
interactivity: appState.interactivity()
)
Expand Down
36 changes: 10 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
<p align="center">
<img width="320" src="https://user-images.githubusercontent.com/2538074/199754334-7f2f801d-1d9e-4cc4-a7a0-bb22c9835007.gif">
</p>

**NavigationTransitions** is a library that integrates seamlessly with SwiftUI's **Navigation** views, allowing complete customization over **push and pop transitions**!

The library is fully compatible with:

- **`NavigationView`** (iOS 13+)
- **`NavigationStack`** & **`NavigationSplitView`** (iOS 16)
- **`NavigationView`** (iOS 13, 14, 15)
- **`NavigationStack`** (iOS 16)

## Overview

Instead of reinventing entire navigation components in order to customize its transitions, `NavigationTransitions` ships as a simple set of 2 modifiers that can be applied directly to SwiftUI's very own first-party navigation components.
Instead of reinventing entire navigation components in order to customize its transitions, `NavigationTransitions` ships with a simple modifier that can be applied directly to SwiftUI's very own first-party navigation component.

### The Basics

Expand All @@ -28,15 +27,7 @@ NavigationView {
// ...
}
.navigationViewStyle(.stack)
.navigationViewStackTransition(.slide)
```

```swift
NavigationView {
// ...
}
.navigationViewStyle(.columns)
.navigationViewColumnTransition(.slide, forColumns: .all)
.navigationTransition(.slide)
```

#### iOS 16
Expand All @@ -45,14 +36,7 @@ NavigationView {
NavigationStack {
// ...
}
.navigationStackTransition(.slide)
```

```swift
NavigationSplitView {
// ...
}
.navigationSplitViewTransition(.slide, forColumns: .all)
.navigationTransition(.slide)
```

---
Expand All @@ -62,23 +46,23 @@ The API is designed to resemble that of built-in SwiftUI Transitions for maximum
You can apply **custom animations** just like with standard SwiftUI transitions:

```swift
.navigationViewStackTransition(
.navigationTransition(
.fade(.in).animation(.easeInOut(duration: 0.3))
)
```

You can **combine** them:

```swift
.navigationViewStackTransition(
.navigationTransition(
.slide.combined(with: .fade(.in))
)
```

And you can **dynamically** choose between transitions based on logic:

```swift
.navigationViewStackTransition(
.navigationTransition(
reduceMotion ? .fade(.in).animation(.linear) : .slide(.vertical)
)
```
Expand Down Expand Up @@ -129,13 +113,13 @@ The [**Demo**](Demo) app showcases some of these transitions in action.
A sweet additional feature is the ability to override the behavior of the **pop gesture** on the navigation view:

```swift
.navigationViewStackTransition(.slide, interactivity: .pan) // full-pan screen gestures!
.navigationTransition(.slide, interactivity: .pan) // full-pan screen gestures!
```

This even works to override its behavior while maintaining the **default system transition** in iOS:

```swift
.navigationViewStackTransition(.default, interactivity: .pan) //
.navigationTransition(.default, interactivity: .pan) //
```

## Documentation
Expand Down
Loading

0 comments on commit ace502a

Please sign in to comment.