'Costum TabView renew the views
I have made a pretty simple costum TabView but when i enter the first view's navigation link and switch to other view using TabBar, then come back to the first view, it resets or destroy and come back as a new one. I have tried to use variable to store the views inise them but it works the same. If you need the code from the views, I will post it, because it is a big one linked to others structs/files.
import SwiftUI
struct APP:View{
@State var isShowingNavBar = false
@State var selected = 0
let iconsArray = ["house","safari","cart","person"]
let home = Home()
let explore = Explore()
let cart = Cart()
let account = Account()
var body: some View{
ZStack{
backgroundWhite.ignoresSafeArea()
VStack{
ZStack{
switch selected{
case 0:
home
case 1:
explore
case 2:
cart
case 3:
account
default:
Home()
}
}
Spacer()
// if !isShowingNavBar {
HStack(spacing:UIScreen.main.bounds.width/6){
ForEach(0..<4){num in
Button(action:{selected=num}){
Image(systemName: iconsArray[num])
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:selected==num ? 50 : 30)
.foregroundColor(selected==num ? blackJetColor : Color.init(red: 0.7, green: 0.7, blue: 0.7))
// .clipped()
.padding(0)
.animation(.easeInOut(duration: 0.2))
}
}
}
.padding(10)
.padding(.bottom,5)
.frame(height:55)
.transition(.move(edge: .bottom).combined(with: .opacity).animation(.easeInOut(duration: 0.05)))
.clipped()
.ignoresSafeArea(.keyboard, edges: .all)
// }
}
.ignoresSafeArea(.keyboard, edges: .bottom)
// .ignoresSafeArea()
}
}
}
Sorry, but i didn't know how to embed this video!
<blockquote class="imgur-embed-pub" lang="en" data-id="a/hVYVs4l" data-context="false" ><a href="//imgur.com/a/hVYVs4l"></a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|