Skip to content

Commit

Permalink
adjustable full screen behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdremov committed May 2, 2023
1 parent 8b395b1 commit d961cd0
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions Sources/PathPresenter/RoutingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import SwiftUI
*/
public enum PathPresenter {}

private extension View {
func `if`<Content: View>(_ conditional: Bool, content: (Self) -> Content) -> TupleView<(Self?, Content?)> {
if conditional { return TupleView((nil, content(self))) } else { return TupleView((self, nil)) }
}
}

public extension PathPresenter {
typealias Action = () -> Void

Expand All @@ -35,20 +41,32 @@ public extension PathPresenter {
Root view is always presented. Can be nil if no view specified
*/
var rootView: AnyView?

/**
PathPresenter views will try to occupy as much space as possible
*/
private let enforceFullScreen: Bool

/**
Init with external path state
*/
public init(path: Binding<Path>) {
public init(
path: Binding<Path>,
enforceFullScreen: Bool = true
) {
self._path = path
self.enforceFullScreen = enforceFullScreen
}

/**
Init with external path state and provide `rootView`
*/
public init<RootView: View>(path: Binding<Path>,
@ViewBuilder rootView:() -> RootView) {
self.init(path: path)
public init<RootView: View>(
path: Binding<Path>,
enforceFullScreen: Bool = true,
@ViewBuilder rootView:() -> RootView
) {
self.init(path: path, enforceFullScreen: enforceFullScreen)
self.rootView = AnyView(rootView())
}

Expand All @@ -64,7 +82,9 @@ public extension PathPresenter {
*/
private func presenter(content: [PathTypeView], sheet: Bool = false) -> some View {
ZStack(alignment: .topLeading) {
Color.clear
if enforceFullScreen {
Color.clear
}
if let rootView = rootView, !sheet {
rootView
.zIndex(-1)
Expand All @@ -87,7 +107,9 @@ public extension PathPresenter {
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.if(enforceFullScreen) {
$0.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}

/**
Expand All @@ -100,7 +122,7 @@ public extension PathPresenter {
/**
Only sheet views
*/
@ViewBuilder var shitView: some View {
@ViewBuilder var sheetView: some View {
presenter(content: path.onlySheet, sheet: true)
}

Expand All @@ -114,7 +136,7 @@ public extension PathPresenter {
onDismiss: {
path.sheetDismissed()
}, content: {
shitView
sheetView
})
}
}
Expand Down

0 comments on commit d961cd0

Please sign in to comment.