Created
July 30, 2022 18:06
-
-
Save alexdremov/9af6325010106332950a530a0a2c2180 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let data = [ | |
(text: "Nice", subtext: "Onborading sequence of screens"), | |
(text: "OK", subtext: "But how to do it with SwiftUI?"), | |
(text: "So that", subtext: "it is nice and shiny"), | |
] | |
let typeCommon: PathPresenter.PathType = | |
.animated( | |
transition: .asymmetric( | |
insertion: .move(edge: .trailing), | |
removal: .move(edge: .leading)), | |
animation: .easeInOut | |
) | |
path.append( | |
data: data, | |
type: typeCommon | |
) { (text, subtext) in | |
boldText( | |
text: text, | |
subtext: subtext | |
) | |
} | |
path.append( | |
boldText( | |
text: "And also", | |
subtext: "flexible enough to cover all your needs" | |
), type: .sheet(onDismiss: {})) | |
path.append( | |
boldText( | |
text: "Read the post", | |
subtext: "to find the solution" | |
), type: typeCommon) | |
path.reverse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum PathType { | |
/** | |
* Just show a view. No animation, no transition. | |
* Show view above all other views | |
*/ | |
case plain | |
/** | |
* Show view with in and out transitions. | |
* Transition animation also can be specified. | |
*/ | |
case animated(transition: AnyTransition, animation: Animation) | |
/** | |
* Show view in .sheet() | |
*/ | |
case sheet(onDismiss: Action) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZStack(alignment: .topLeading) { | |
Color.clear | |
if let rootView = rootView, !sheet { | |
rootView.zIndex(-1) | |
} | |
ForEach(content, id: \.hashValue) { elem in | |
switch elem { | |
case .plain(let view, hash: _, zIndex: let zIndex): | |
view.zIndex(zIndex) | |
case .animated( | |
let view, | |
transition: let transition, | |
animation: _, | |
hash: _, | |
zIndex: let zIndex): | |
view.zIndex(zIndex).transition(transition) | |
case .sheet(let view, _, _): | |
view | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment