Skip to content

Commit

Permalink
Improves navigation (#21)
Browse files Browse the repository at this point in the history
* Reduces the delay time when a sheet is going to be presented

* Updates example

* Updates readme
  • Loading branch information
felilo authored Jun 14, 2024
1 parent 374b2e6 commit e4c8fe7
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.felilo.SUICoordinatorExample;
PRODUCT_BUNDLE_IDENTIFIER = afl.SUICoordinatorExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MainCoordinator: Coordinator<MainRoute> {
override init() {
super.init()
Task {
let _ = await startFlow(route: .splash, animated: false)
await startFlow(route: .splash, animated: false)
}
}

Expand All @@ -39,6 +39,6 @@ class MainCoordinator: Coordinator<MainRoute> {

override func start(animated: Bool = true) async {
let coordinator = HomeCoordinator()
await navigate(to: coordinator, presentationStyle: .fullScreenCover)
await navigate(to: coordinator, presentationStyle: .fullScreenCover, animated: animated)
}
}
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,13 @@ class MainCoordinator: Coordinator<MainRoute> {

override init() {
super.init()
Task {
await startFlow(route: .splash, animated: false)
}
}

override func start(animated: Bool = false) async {
override func start(animated: Bool = true) async {
let coordinator = HomeCoordinator()
async let _ = await startFlow(route: .splash, animated: false)
await navigate(to: coordinator, presentationStyle: .fullScreenCover, animated: animated)
}
}
Expand Down Expand Up @@ -516,7 +518,3 @@ _____
## Contributing

Contributions to the SUICoordinator library are welcome! To contribute, simply fork this repository and make your changes in a new branch. When your changes are ready, submit a pull request to this repository for review.

License

The SUICoordinator library is released under the MIT license. See the LICENSE file for more information.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,4 @@ public extension CoordinatorType {
await router.restart(animated: animated)
router.mainView = route
}


@MainActor func restart(animated: Bool = true) async -> Void {
guard let mainView = router.mainView else {
return
}

await finishFlow(animated: animated)
await startFlow(route: mainView)
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public extension View {
onDidLoad: ((Int) -> Void)? = nil
) -> some View {
modifier(
SheetCoordinating(
SheetCoordinatorView(
coordinator: coordinator,
index: index,
isLast: isLast,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ final public class SheetCoordinator<T>: ObservableObject {

if animated {
items.append(nil)
await makeDelay(animated: animated, duration: .seconds(0.08))
await makeDelay(animated: animated, duration: .seconds(0))
}

items.append(sheet)
removeAllNilItems()
}

/// Removes the last presented sheet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import SwiftUI
import Combine

struct SheetCoordinating: ViewModifier {
struct SheetCoordinatorView: ViewModifier {

// ---------------------------------------------------------
// MARK: typealias
Expand Down Expand Up @@ -83,7 +83,10 @@ struct SheetCoordinating: ViewModifier {
coordinator.removeAllNilItems()
onDissmis?($0)
},
onDidLoad: onDidLoad
onDidLoad: {
coordinator.removeAllNilItems()
onDidLoad?($0)
}
)
}
}
Expand Down
18 changes: 0 additions & 18 deletions Tests/SUICoordinatorTests/CoordinatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,6 @@ import Combine

final class CoordinatorTests: XCTestCase {

func test_restartMainCoordinator() async throws {
let sut = makeSUT()
let coordinator1 = OtherCoordinator()
let coordinator2 = AnyCoordinator()

await sut.start(animated: false)
await sut.router.navigate(to: .pushStep, animated: false )
await navigateToCoordinator(coordinator1, in: sut)
await navigateToCoordinator(coordinator2, in: coordinator1)

await sut.restart(animated: false )

XCTAssertEqual(sut.router.items.count, 0)
XCTAssertTrue(sut.children.isEmpty)
XCTAssertNotNil(sut.router.mainView)
XCTAssertEqual(sut.router.sheetCoordinator.items.count, 0)
}

func test_finshFlow() async throws {
let sut = makeSUT()

Expand Down
1 change: 0 additions & 1 deletion Tests/SUICoordinatorTests/RouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ final class RouterTests: XCTestCase {
let view = PushStepView.self
sut.mainView = RouteBase(presentationStyle: .push, content: PushStepView())


await sut.navigate(to: .init(presentationStyle: .push, content: PushStepView()), animated: false)
await sut.navigate(to: .init(presentationStyle: .push, content: PushStep2View()), animated: false)
await sut.navigate(to: .init(presentationStyle: .push, content: PushStep3View()), animated: false)
Expand Down
21 changes: 13 additions & 8 deletions Tests/SUICoordinatorTests/SheetCoordinatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class SheetCoordinatorTests: XCTestCase {
let sut = makeSUT()
let finalRoute = makeSheetItem("Final Item")

await sut.presentSheet(makeSheetItem("First Item"))
await presentSheet(makeSheetItem("First Item"), with: sut)
await sut.presentSheet(finalRoute)

XCTAssertEqual(sut.items.count, 2)
Expand All @@ -52,7 +52,7 @@ final class SheetCoordinatorTests: XCTestCase {
let sut = makeSUT()
let item = makeSheetItem("Custom Item")

await sut.presentSheet(item)
await presentSheet(item, with: sut)
XCTAssertEqual(sut.items.count, 1)

sut.removeLastSheet()
Expand All @@ -64,9 +64,9 @@ final class SheetCoordinatorTests: XCTestCase {
func test_dismiss_route_atPositon() async throws {
let sut = makeSUT()

await sut.presentSheet(makeSheetItem("First Item"))
await sut.presentSheet(makeSheetItem("Second Item"))
await sut.presentSheet(makeSheetItem("Third Item"))
await presentSheet(makeSheetItem("First Item"), with: sut)
await presentSheet(makeSheetItem("Second Item"), with: sut)
await presentSheet(makeSheetItem("Third Item"), with: sut)

await sut.remove(at: 1)

Expand All @@ -77,9 +77,9 @@ final class SheetCoordinatorTests: XCTestCase {
func test_cleanCoordinator() async throws {
let sut = makeSUT()

await sut.presentSheet(makeSheetItem("First Item"))
await sut.presentSheet(makeSheetItem("Second Item"))
await sut.presentSheet(makeSheetItem("Third Item"))
await presentSheet(makeSheetItem("First Item"), with: sut)
await presentSheet(makeSheetItem("Second Item"), with: sut)
await presentSheet(makeSheetItem("Third Item"), with: sut)
XCTAssertEqual(sut.items.count, 3)

sut.clean(animated: false)
Expand All @@ -103,4 +103,9 @@ final class SheetCoordinatorTests: XCTestCase {
) -> SheetItem<String> {
.init(view: item, animated: animated, presentationStyle: presentationStyle)
}

private func presentSheet( _ item: SheetItem<String>, with sut: SheetCoordinator<String>) async {
await sut.presentSheet(item)
sut.removeAllNilItems()
}
}

0 comments on commit e4c8fe7

Please sign in to comment.