Post

Replies

Boosts

Views

Activity

The onAppear for the wrong tab is being executed
I was seeing some behavior I couldn't understand with onAppear and my tabs (Xcode 12 beta 3). I wrote a quick project with two tabs to test. Here's tab1 (tab2 is the same).    var body: some View {     NavigationView {     Text("Tab1")     }     .onAppear() {       let datefor = DateFormatter()       datefor.timeStyle = .medium       print("onAppear tab1 \(datefor.string(from: Date()))")     }     .onDisappear() {       print("onDisappear tab1")     }   } At app launch: onAppear tab1 10:29:18 AM onAppear tab2 10:29:18 AM Touch tab2: onDisappear tab1 onDisappear tab2 onAppear tab2 10:29:42 AM onAppear tab1 10:29:42 AM Now this is where it gets interesting. Touch tab1 and the wrong onAppear gets called: onDisappear tab2 onAppear tab2 10:30:10 AM Touch tab2 and the same thing happens: onDisappear tab1 onAppear tab1 10:30:46 AM
1
0
1.1k
Aug ’20
Unexpected behavior with Spacers in SwiftUI Toolbar
I'm seeing unexpected behavior with the SwiftUI Toolbar. This code works but the items are grouped together in the center of the toolbar (as expected). However, if I add the two Spacers everything disappears.              ToolbarItem(placement: .bottomBar) {               HStack {                 Button(Constants.Buttons.Location) {                   print("button")                 }                 //Spacer()                 Image(systemName: Constants.Icons.Share)                 //Spacer()                 Button(Constants.Buttons.Website) {                   print("button")                 }               }             } If I add them all individually (including the two Spacers) I get the result I was expecting.        ToolbarItem(placement: .bottomBar) {         Button(Constants.Buttons.Location) {           print("button")         }       }       ToolbarItem(placement: .bottomBar) {         Spacer()       }       ToolbarItem(placement: .bottomBar) {         Image(systemName: Constants.Icons.Share)       }       ToolbarItem(placement: .bottomBar) {         Spacer()       }       ToolbarItem(placement: .bottomBar) {         Button(Constants.Buttons.Website) {           print("button")         }       }
1
0
1k
Jul ’20