Wednesday, February 14, 2024
HomeiOS Developmentios - Record inside TabView inside NavigationView breaks animation for Navigation Title

ios – Record inside TabView inside NavigationView breaks animation for Navigation Title


I wish to have NavigationView beginning with Welcome scene + TabView on the followup scene with Record of things. I would like NavigationView bar to coordinate with Record scrolling in a “common” method:

  • if scrolling down the listing, Navigation Title ought to turn out to be smaller and centered + gray background ought to be used
  • if scrolling as much as the highest of the listing, Navigation Title ought to turn out to be larger and left-aligned + clear background

Thus far I reviewed all suggestions given in related posts: [1]StackOverflow, [2]Apple DevPortal. All suggestions fail to handle this concern.

Visible illustration of present concern:

enter image description here

Code beneath has the difficulty with Navigation Title when TestView is opened and Record is scrolled:

import SwiftUI

struct MainView: View {
  var physique: some View {
    NavigationView {
      NavigationLink(vacation spot: TestView()) {
        MainButton(title: "Press Me")
      }
      .navigationTitle("Welcome")
    }
    .navigationViewStyle(.stack)
  }
}

struct MainButton: View {
  var title: String
  var physique: some View {
    Textual content(title).font(.title)
  }
}

struct TestView: View {
  @State var selectedTab = 0
  var physique: some View {
    TabView(choice: $selectedTab) {
      Record { ForEach(0..<100) { i in Textual content("Take a look at Tab 0 row (i)") } }
        .listStyle(.plain)
        .tag(0)
        .navigationBarTitle("Web page 1 Tab 1")
        .tabItem {
          Picture(systemName: "face.smiling")
          Textual content("tab1")
        }
        .tag(0)
      Record { ForEach(0..<20) { i in Textual content("Take a look at Tab 1 row (i)") } }
        .listStyle(.plain)
        .tag(1)
        .navigationBarTitle("Web page 1 Tab 2")
        .tabItem {
          Picture(systemName: "face.smiling.inverse")
          Textual content("tab2")
        }
        .tag(1)
    }
    .navigationTitle("Tab Views")
    .background()
  }
}

struct TestView_Previews: PreviewProvider {
  static var previews: some View {
    MainView()
  }
}

If I take away TabView on second Scene, Navigation Title works as anticipated.

enter image description here



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments