Skip to content

Commit

Permalink
Add iOS 16-compatible navigationDestination(item:) to core (#148)
Browse files Browse the repository at this point in the history
* Add iOS 16-compatible `navigationDestination(item:)`

* wip
  • Loading branch information
stephencelis authored Apr 5, 2024
1 parent 35526c2 commit 2ec6c3a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
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:)``
25 changes: 25 additions & 0 deletions Sources/SwiftUINavigationCore/NavigationDestination.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if canImport(SwiftUI)
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)
}
}
}
}
#endif // canImport(SwiftUI)

0 comments on commit 2ec6c3a

Please sign in to comment.