Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

custom navigation swiftui navigation link swiftui routing

NotificationsYou must be signed in to change notification settings

swiftuiux/d3-custom-navigation-swiftui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Experimenting with navigation link. if you find this idea interesting you can take and expend it into a more powerful solution.Live youtube

The result navigation

@Statevarroute:Router=.emptyvarbody:someView{NavigationView{VStack{Button("go1"){ route=.go1}Button("go2"){ route=.go2}Button("go3"){ route=.go3}}.navigation(route: $route)}.navigationViewStyle(.stack)}

1. Define sub view

structSubView:View{lettext:Stringvarbody:someView{Text("\(text)")}}

2. Define routes

enumRouter{case go1case go2case go3case empty@ViewBuildervarbuilder:someView{switch(self){case.go1:SubView(text:"go1")case.go2:SubView(text:"go2")case.go3:SubView(text:"go3")default:EmptyView()}}}

3. Define view modifier

structNavigationModifire:ViewModifier{@StatevarisActive:Bool=true@Bindingvarroute:Routerfunc body(content:Content)->someView{        content.background{NavigationLink(destination: route.builder, isActive: $isActive){EmptyView()}.hidden()}.onChange(of: isActive){if $0==false{ route=.empty}}}}extensionView{@ViewBuilderfunc navigation(route:Binding<Router>)->someView{if route.wrappedValue!=.empty{modifier(NavigationModifire(route: route))}else{self}}}

[8]ページ先頭

©2009-2025 Movatter.jp