Skip to content

[fix-nav-links] - Use new navigation destination API with iOS 16+ - TT #221

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions .github/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ platform :ios do
destination: [
'platform=iOS Simulator,name=iPhone 8',
'platform=tvOS Simulator,name=Apple TV',
'platform=watchOS Simulator,name=Apple Watch Series 5 - 44mm',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (4th generation)',
'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (5th generation)',
'platform=macOS',
'platform=macOS,variant=Mac Catalyst',
]
Expand All @@ -44,8 +44,8 @@ platform :ios do
destination: [
'platform=iOS Simulator,name=iPhone 8',
'platform=tvOS Simulator,name=Apple TV',
'platform=watchOS Simulator,name=Apple Watch Series 5 - 44mm',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (4th generation)',
'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (5th generation)',
'platform=macOS',
'platform=macOS,variant=Mac Catalyst',
]
Expand All @@ -55,7 +55,7 @@ platform :ios do
destination: [
'platform=iOS Simulator,name=iPhone 8',
'platform=tvOS Simulator,name=Apple TV',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (4th generation)',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (5th generation)',
'platform=macOS,variant=Mac Catalyst',
]
)
Expand All @@ -64,8 +64,8 @@ platform :ios do
destination: [
'platform=iOS Simulator,name=iPhone 8',
'platform=tvOS Simulator,name=Apple TV',
'platform=watchOS Simulator,name=Apple Watch Series 5 - 44mm',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (4th generation)',
'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (5th generation)',
'platform=macOS',
'platform=macOS,variant=Mac Catalyst',
]
Expand All @@ -75,10 +75,10 @@ platform :ios do
destination: [
'platform=iOS Simulator,name=iPhone 8',
'platform=tvOS Simulator,name=Apple TV',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (4th generation)',
'platform=iOS Simulator,name=iPad Pro (12.9-inch) (5th generation)',
'platform=macOS',
'platform=macOS,variant=Mac Catalyst',
'platform=watchOS Simulator,name=Apple Watch Series 5 - 44mm',
'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)',
]
)
end
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ on:

jobs:
test:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Run TESTS
Expand All @@ -31,21 +31,21 @@ jobs:
retention-days: 90

platform_test:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Run Multiplatform TESTS
run: bundle exec fastlane platform_test
working-directory: ${{ env.working-directory }}

cli_test:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
steps:
- uses: actions/checkout@v2
Expand All @@ -55,32 +55,32 @@ jobs:
working-directory: ${{ env.working-directory }}

build_for_swift_package_manager:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Validate SwiftPM BUILDs
run: bundle exec fastlane build_swiftpm
working-directory: ${{ env.working-directory }}

build_for_cocoapods:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Validate Cocoapods Can Deploy (lib lint)
run: bundle exec fastlane cocoapods_liblint
working-directory: ${{ env.working-directory }}

lint:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Swiftlint
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/PR_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on: [ pull_request, workflow_dispatch ]

jobs:
test:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Run TESTS
Expand All @@ -28,21 +28,21 @@ jobs:
retention-days: 90

platform_test:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Run Multiplatform TESTS
run: bundle exec fastlane platform_test
working-directory: ${{ env.working-directory }}

cli_test:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
steps:
- uses: actions/checkout@v2
Expand All @@ -52,32 +52,32 @@ jobs:
working-directory: ${{ env.working-directory }}

build_for_swift_package_manager:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Validate SwiftPM BUILDs
run: bundle exec fastlane build_swiftpm
working-directory: ${{ env.working-directory }}

build_for_cocoapods:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Validate Cocoapods Can Deploy (lib lint)
run: bundle exec fastlane cocoapods_liblint
working-directory: ${{ env.working-directory }}

lint:
runs-on: macos-11
runs-on: macos-12
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Swiftlint
Expand Down
2 changes: 1 addition & 1 deletion ExampleApps/SwiftUIExample/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct ContentView: View, FlowRepresentable {
@State var selectedTab: Tab = .map
weak var _workflowPointer: AnyFlowRepresentable?
var body: some View {
TabView(selection: $selectedTab) { // swiftlint:disable:this closure_body_length
TabView(selection: $selectedTab) {
// NOTE: Using constant here guarantees the workflow cannot abandon, it stays launched forever.
WorkflowView {
WorkflowItem(MapFeatureOnboardingView.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

// swiftlint:disable:next missing_docs
public protocol _PassthroughIdentifiable { }
public protocol _PassthroughIdentifiable { } // swiftlint:disable:this type_name

/// A `FlowRepresentable` that automatically captures data from the `Workflow` and passes it forward.
public protocol PassthroughFlowRepresentable: FlowRepresentable, _PassthroughIdentifiable where WorkflowInput == AnyWorkflow.PassedArgs, WorkflowOutput == AnyWorkflow.PassedArgs { }
Expand Down
5 changes: 4 additions & 1 deletion Sources/SwiftCurrent_SwiftUI/Models/WorkflowViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ final class WorkflowViewModel: ObservableObject {
extension WorkflowViewModel: OrchestrationResponder {
func launch(to destination: AnyWorkflow.Element) {
onFinishPublisher.send(nil) // We launched, so make sure nobody thinks we finished yet.
body = destination
DispatchQueue.main.async { [weak self] in
// Probably makes previews require running, but it's better than publishing during the view lifecycle
self?.body = destination
}
}

func proceed(to destination: AnyWorkflow.Element, from source: AnyWorkflow.Element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftCurrent

/// :nodoc: Protocol is forced to be public, but it is an internal protocol.
@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
public protocol _WorkflowItemProtocol: View where FlowRepresentableType: FlowRepresentable & View {
public protocol _WorkflowItemProtocol: View where FlowRepresentableType: FlowRepresentable & View { // swiftlint:disable:this type_name
associatedtype FlowRepresentableType

var workflowLaunchStyle: LaunchStyle.SwiftUI.PresentationType { get }
Expand Down
16 changes: 10 additions & 6 deletions Sources/SwiftCurrent_SwiftUI/ViewModifiers/NavigationWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ extension View {
// PROBLEM: SwiftUI has a bug if isActive is defaulted to true on NavLinks.
// See details here: https://stackoverflow.com/questions/68365774/nested-navigationlinks-with-isactive-true-are-not-displaying-correctly
func navLink<D: View>(to destination: D, isActive: Binding<Bool>) -> some View {
background(
List {
NavigationLink(destination: destination,
isActive: isActive) { EmptyView() }
}.opacity(0.01)
)
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
return navigationDestination(isPresented: isActive) { destination }
} else {
return background(
List {
NavigationLink(destination: destination,
isActive: isActive) { EmptyView() }
}.opacity(0.01)
)
}
}
}
12 changes: 9 additions & 3 deletions Sources/SwiftCurrent_SwiftUI/Views/WorkflowLauncher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ public struct WorkflowLauncher<Content: _WorkflowItemProtocol>: View {
ViewBuilder {
if isLaunched {
if shouldEmbedInNavView {
NavigationView {
workflowContent
}.preferredNavigationStyle()
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
NavigationStack {
workflowContent
}
} else {
NavigationView {
workflowContent
}.preferredNavigationStyle()
}
} else {
workflowContent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class MockOrchestrationResponder: OrchestrationResponder {

open var abandonCalled = 0
open var lastWorkflow: AnyWorkflow?
open var lastOnFinish:(() -> Void)?
open var lastOnFinish: (() -> Void)?
open func abandon(_ workflow: AnyWorkflow, onFinish: (() -> Void)?) {
lastWorkflow = workflow
lastOnFinish = onFinish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension FlowRepresentable where Self: UIViewController {
- Parameter onFinish: a callback after the workflow has been abandoned.
- Note: In order to dismiss UIKit views, the workflow must have an `OrchestrationResponder` that is a `UIKitPresenter`.
*/
public func abandonWorkflow(animated: Bool = true, onFinish:(() -> Void)? = nil) {
public func abandonWorkflow(animated: Bool = true, onFinish: (() -> Void)? = nil) {
workflow?.abandon(animated: animated, onFinish: onFinish)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension Workflow {
- Parameter onFinish: a callback after the workflow has been abandoned.
- Important: In order to dismiss UIKit views the workflow must have an `OrchestrationResponder` that is a `UIKitPresenter`.
*/
public func abandon(animated: Bool = true, onFinish:(() -> Void)? = nil) {
public func abandon(animated: Bool = true, onFinish: (() -> Void)? = nil) {
AnyWorkflow(self).abandon(animated: animated, onFinish: onFinish)
}
}
Expand All @@ -30,7 +30,7 @@ extension AnyWorkflow {
- Parameter onFinish: a callback after the workflow has been abandoned.
- Important: In order to dismiss UIKit views the workflow must have an `OrchestrationResponder` that is a `UIKitPresenter`.
*/
public func abandon(animated: Bool = true, onFinish:(() -> Void)? = nil) {
public func abandon(animated: Bool = true, onFinish: (() -> Void)? = nil) {
if let presenter = orchestrationResponder as? UIKitPresenter {
presenter.abandon(self, animated: animated) { [self] in
self._abandon()
Expand Down