Skip to content

Instantly share code, notes, and snippets.

@libdx
Created October 24, 2019 10:13
Show Gist options
  • Save libdx/367ed710141548d0fe05f7e6059bb1d9 to your computer and use it in GitHub Desktop.
Save libdx/367ed710141548d0fe05f7e6059bb1d9 to your computer and use it in GitHub Desktop.
enum NavStyle {
case push
case modal
case back
}
struct Nav {
let navs: [Nav]
let style: NavStyle = .push
init(navs: [Nav] = []) {
self.navs = navs
}
func push(_ nav: Nav) -> Nav {
return Nav(navs: navs + [nav])
}
func pop() -> Nav {
var navs = self.navs
navs.removeLast()
return Nav(navs: navs)
}
}
struct NavAction {
}
func navigate(from nav: Nav, by action: NavAction) -> Nav {
return Nav()
}
func runNavigation(from current: Nav, to new: Nav) {
// perform actual navigation
}
func sample() {
let nav = Nav()
let action = NavAction()
let newNav = navigate(from: nav, by: action)
runNavigation(from: Nav(), to: newNav)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment