0

Working on a project where view are aligned like this

  1. HeaderView
  2. TabView
  3. Views with each tab
  4. List and other items in each view

Relevant code is

struct Home: View {
@StateObject var manageScrollPosition = ManageScrollPosition()

var body: some View {
    GeometryReader { gReader in
        ScrollView {
            VStack {
                EntityHeaderView(bottomViewPopupData: $bottomViewPopupData)
                EntityTabView(manageScrollPosition: manageScrollPosition)
                    .frame(height: gReader.size.height)
                
            }
            .background(GeometryReader {
                Color.clear.preference(key: ViewOffsetKey.self,
                                       value: -$0.frame(in: .named("scroll")).origin.y)
            })
            .onPreferenceChange(ViewOffsetKey.self) {
                if $0 == 238.0 {
                    manageScrollPosition.isScrollEnable = false
                }
            }
        }
        .coordinateSpace(name: "scroll")
        .introspectScrollView { scrollView in
            scrollView.bounces = manageScrollPosition.isScrollEnable
            scrollView.isScrollEnabled = manageScrollPosition.isScrollEnable
        }
    }
}

I have to disable the scrolling of main scrollview once tab is reaches to top and enable the scrolling of list from child View.

Right now I'm able to achive this with static height of header View

if $0 == 238.0 {
  manageScrollPosition.isScrollEnable = false
}

want to replace this static value with actual height of header or some other solution. I'm new in SwiftUI, Very thank full for your solutiuon in advance.

  • 2
    In the same way as you have origin of frame you can get entire frame or its height. Don't just copy-paste found code - try to understand what it does. – Asperi Aug 15 '22 at 19:06
  • Hey @Asperi, as I mentioned I'm bit new in SwiftUI, could you please explain what I'm doing wrong, because I have to get the height of headerView and I don't think this method gives me height of the same. – Vikash Kumar Chaubey Aug 16 '22 at 05:56

0 Answers0