SwiftUI + NavigationBar + Detail's nav bar hidden on iOS 13.XX but not on iOS 14.YY

Is there a way to be selective about what entails .onDisappear? E.g. not involve scrolling?

// The navigation bar hiding is being done like so
struct UserProfileView: View {
  var body: some View {
    @Published var hideBar = true
    
    NavigationView {
      ZStack {
        List {
          Section(header: Text(NSLocalizedString("My Routes", comment: ""))) {
            MyRoutesSectionView(hideBar: self.$hideBar, selectedView: self.$selectedView)
          }
        }
        
        VStack {
          
        }
      }
      .navigationTitle("")
      .navigationBarHidden(self.hideBar)
    }
  }
}

struct MyRoutesSectionView: View {
  var body: some View {
    @Binding var hideBar = true
    
    NavigationLink(destination: modifiedView, tag: tag, selection: self.$selectedView) {
      MyRoutesNavigationLinkView(myRoutesObject: object)
    }.onDisappear {
      if #available(iOS 14, *) {
        // redundant --- just have it here to make it clear
        // the actual problem being --- navbar is hidden in detail on iOS 13.5
        self.hideBar = true
      } else {
        // this will not hide the navbar in the detail view but upon scrolling
        // the `UserProfileView` . . . when the section disappears . . . navbar would appear
        self.hideBar = false
      }
    }
  }
}

using a GeometryReader and anchors, let’s see how this goes

a geometry proxy is merging all the navigation links into one though I am not using it to set any entity’s size anywhere, WUT :confused:

struct MyRoutesSectionView: View {
 @Binding var hideBar: Bool
 @Binding var parentVerticalContentOffSet: CGFloat

 var body: some View {
  // This geometry proxy is merging all the navigation links into one though I am not using it to set any entity's size anywhere, WUT :/ 
  GeometryReader { proxy in
   ForEach(Destination.allCases, id: \.self) { destination in
    .
    .
    .
    NavigationLink(destination: modifiedView, tag: tag, selection: self.$selectedView) {
     MyRoutesNavigationLinkView(myRoutesObject: object)
    }.onDisappear {
     if #available(iOS 14, *) {
      self.hideBar = true
     } else {
      let selfHeight = proxy.frame(in: CoordinateSpace.local).size.height
      if parentVerticalContentOffSet >= selfHeight {
       self.hideBar = true
      } else {
       self.hideBar = false
      }
     }
    }
   }
  }
 }
}

// Parent View
struct UserProfileView: View {
  @ObservedObject private(set) var store = UserProfileStore()
  @State private var myRoutesSectionVerticalOffset: CGFloat = 0

  var body: some View {
    NavigationView {
      GeometryReader { proxy in
        ZStack {
          List {
            GeometryReader { geometry in
              Rectangle()
        
            }
            
            Section(header: Text(NSLocalizedString("My Routes", comment: ""))) {
              MyRoutesSectionView(hideBar: $store.hideBar,
                                  parentVerticalContentOffSet: self.$myRoutesSectionVerticalOffset,
                                  selectedView: self.$selectedView)
                .transformAnchorPreference(key: BMBoundsKey.self, value: .bounds) {
                  $0.append(BMBounds(id: "MyRoutesSectionView", bounds: proxy[$1]))
                }
                .onPreferenceChange(BMBoundsKey.self) { preference in
                  if let bmBounds = preference.last {
                    self.myRoutesSectionVerticalOffset = bmBounds.bounds.origin.y
                  }
                }
            }
          }
          .edgesIgnoringSafeArea(.all)
          .listStyle(GroupedListStyle())
          
          VStack {
            
          }
        }
        .edgesIgnoringSafeArea(.all)
        .navigationBarTitle("")
        .navigationBarHidden(store.hideBar)
        .onAppear {
          store.hideBar = true
        }
      }
    }
  }
}

This topic was automatically closed after 166 days. New replies are no longer allowed.