Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iOS 16-compatible navigationDestination(item:) to core #148

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ struct SignInView: View {

### Binding transformations

- ``SwiftUI/Binding/isPresent()``
- ``SwiftUI/Binding/removeDuplicates()``
- ``SwiftUI/Binding/removeDuplicates(by:)``

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ``SwiftUINavigationCore``

A few core types included in SwiftUI Navigation.
A few core types and modifiers included in SwiftUI Navigation.

## Topics

Expand All @@ -10,3 +10,19 @@ A few core types included in SwiftUI Navigation.
- ``AlertState``
- ``ConfirmationDialogState``
- ``ButtonState``

### Alert and dialog modifiers

- ``SwiftUI/View/alert(item:title:actions:message:)``
- ``SwiftUI/View/alert(item:title:actions:)``
- ``SwiftUI/View/confirmationDialog(item:titleVisibility:title:actions:message:)``
- ``SwiftUI/View/confirmationDialog(item:titleVisibility:title:actions:)``

### Bindings

- ``SwiftUI/Binding/isPresent()``
- ``SwiftUI/View/bind(_:to:)``

### Navigation

- ``SwiftUI/View/navigationDestination(item:destination:)``
23 changes: 23 additions & 0 deletions Sources/SwiftUINavigationCore/NavigationDestination.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import SwiftUI

@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
extension View {
/// Associates a destination view with a bound value for use within a navigation stack or
/// navigation split view.
///
/// See `SwiftUI.View.navigationDestination(item:destination:)` for more information.
///
/// - Parameters:
/// - item: A binding to the data presented, or `nil` if nothing is currently presented.
/// - destination: A view builder that defines a view to display when `item` is not `nil`.
public func navigationDestination<D, C: View>(
item: Binding<D?>,
@ViewBuilder destination: @escaping (D) -> C
) -> some View {
navigationDestination(isPresented: item.isPresent()) {
if let item = item.wrappedValue {
destination(item)
}
}
}
}
Loading