@@ -46,16 +46,25 @@ public extension PathPresenter {
4646 PathPresenter views will try to occupy as much space as possible
4747 */
4848 private let enforceFullScreen : Bool
49+
50+
51+ /**
52+ PathPresenter shows all views in path, this may lead to inapropriate .onAppear fire.
53+ This option asks it to show only the last view
54+ */
55+ private let showOnlyLast : Bool
4956
5057 /**
5158 Init with external path state
5259 */
5360 public init (
5461 path: Binding < Path > ,
55- enforceFullScreen: Bool = true
62+ enforceFullScreen: Bool = true ,
63+ showOnlyLast: Bool = false
5664 ) {
5765 self . _path = path
5866 self . enforceFullScreen = enforceFullScreen
67+ self . showOnlyLast = showOnlyLast
5968 }
6069
6170 /**
@@ -64,9 +73,10 @@ public extension PathPresenter {
6473 public init < RootView: View > (
6574 path: Binding < Path > ,
6675 enforceFullScreen: Bool = true ,
76+ showOnlyLast: Bool = false ,
6777 @ViewBuilder rootView: ( ) -> RootView
6878 ) {
69- self . init ( path: path, enforceFullScreen: enforceFullScreen)
79+ self . init ( path: path, enforceFullScreen: enforceFullScreen, showOnlyLast : showOnlyLast )
7080 self . rootView = AnyView ( rootView ( ) )
7181 }
7282
@@ -76,6 +86,29 @@ public extension PathPresenter {
7686 public var pathBinding : Binding < Path > {
7787 $path
7888 }
89+
90+ @ViewBuilder
91+ private func getElementView( element elem: PathTypeView ) -> some View {
92+ switch elem {
93+ case . plain( let view, hash: _, zIndex: let zIndex) :
94+ view
95+ . zIndex ( zIndex)
96+ case . animated( let view,
97+ transition: let transition,
98+ animation: _,
99+ hash: _,
100+ zIndex: let zIndex) :
101+ view
102+ . zIndex ( zIndex)
103+ . transition ( transition)
104+ case . sheet( let view, _, _) :
105+ view
106+ }
107+ }
108+
109+ private func getLastNotSheet( content: [ PathTypeView ] ) -> PathTypeView ? {
110+ content. last { !$0. isSheet}
111+ }
79112
80113 /**
81114 Constructs intrnal view structure
@@ -89,21 +122,13 @@ public extension PathPresenter {
89122 rootView
90123 . zIndex ( - 1 )
91124 }
92- ForEach ( content, id: \. hashValue) { elem in
93- switch elem {
94- case . plain( let view, hash: _, zIndex: let zIndex) :
95- view
96- . zIndex ( zIndex)
97- case . animated( let view,
98- transition: let transition,
99- animation: _,
100- hash: _,
101- zIndex: let zIndex) :
102- view
103- . zIndex ( zIndex)
104- . transition ( transition)
105- case . sheet( let view, _, _) :
106- view
125+ if showOnlyLast {
126+ if let elem = getLastNotSheet ( content: content) {
127+ getElementView ( element: elem)
128+ }
129+ } else {
130+ ForEach ( content, id: \. hashValue) { elem in
131+ getElementView ( element: elem)
107132 }
108133 }
109134 }
0 commit comments