Skip to content

Commit

Permalink
Merge branch 'dismiss_transition'
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarno-lucid committed Aug 22, 2024
2 parents 26810c0 + 09bf4aa commit bf0a8b4
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions Sources/SwiftfulRouting/Components/TransitionSupportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,23 @@ public struct TransitionSupportViewBuilder<Content: View>: View, TransitionSuppo
}

public func dismissTransition() {
if let index = screens.firstIndex(where: { $0.id == selectedScreen.id }), screens.indices.contains(index - 1) {
self.currentTransition = screens[index].transition.reversed
guard let index = screens.firstIndex(where: { $0.id == selectedScreen.id }), screens.indices.contains(index - 1) else { return }

let screenToDismiss = screens[index]
let newSelectedScreen = screens[index - 1]

self.currentTransition = screenToDismiss.transition.reversed

Task { @MainActor in
try? await Task.sleep(nanoseconds: 100_000_000)

Task { @MainActor in
try? await Task.sleep(nanoseconds: 100_000_000)

selectedScreen = screens[index - 1]

try? await Task.sleep(nanoseconds: 25_000)
screens.remove(at: index)
}
selectedScreen = newSelectedScreen

try? await Task.sleep(nanoseconds: 25_000)

// Due to delays above, there is edge case where dismissTransition is called multiple times and the screen could already be dismissed
guard let index = screens.firstIndex(where: { $0.id == screenToDismiss.id }) else { return }
screens.remove(at: index)
}
}

Expand Down

0 comments on commit bf0a8b4

Please sign in to comment.