Skip to content

Commit

Permalink
Fix animation break on first present with fullScreenCover style
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest0-Production committed Jun 12, 2022
1 parent 2309b47 commit f08c951
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
21 changes: 21 additions & 0 deletions Sources/ScreenNavigatorKit/Internal/Helpers/Binding+when.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Binding+when.swift
//
//
// Created by Ernest Babayan on 12.06.2022.
//

import SwiftUI

extension Binding {
func when<Wrapped>(_ isTrue: Bool) -> Binding<Value> where Value == Wrapped? {
Binding(
get: {
isTrue ? self.wrappedValue : nil
},
set: { newValue, transaction in
self.transaction(transaction).wrappedValue = newValue
}
)
}
}
9 changes: 3 additions & 6 deletions Sources/ScreenNavigatorKit/ModalStack/PresentScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ struct PresentScreenView<Content: View>: View {
@ObservedObject var screen: PresentScreen

var body: some View {
switch screen.presentationStyle {
case .sheet, .none:
content.sheet($screen.presentedView)
case .fullScreenCover:
content.fullScreenCover($screen.presentedView)
}
content
.sheet($screen.presentedView.when(screen.presentationStyle == .sheet))
.fullScreenCover($screen.presentedView.when(screen.presentationStyle == .fullScreenCover))
}
}

0 comments on commit f08c951

Please sign in to comment.