exyte / ScalingHeaderScrollView

A scroll view with a sticky header which shrinks as you scroll. Written with SwiftUI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using tabview inside content block

Sharrykhan01 opened this issue · comments

Hi
I am using tabiew with three views inside the ScallingHeaderScrollview content block, there is a height issue for the TabView views. The data is getting cut. Can't we provide dynamic height for the Tabview so that the complete data get scrolled and be visible.

Hey @Sharrykhan01, you'll have to fix your table's height from your end - there is no way for me to get the height for your table from the ViewBuilder the library gets. There is an example of such a behaviour in the example project - search for 'AutosizingList'

@f3dm76 hey bro ! This is the code if you find something, please let me know.

                            ScalingHeaderScrollView {
                                ZStack {
                                    Color.white.opacity(1.0)
                                    self.setTopHeader(size: geo.size)
                                }
                            } content: {
                                TabView(selection: $tabIndexSelected) {
                                    VStack(spacing: 0) {
                                        LOCBussinesProfileAbout(size: geo.size,
                                                                businessResult: [data],
                                                                height: $pageHeights[0],
                                                                shouldScroll: $shouldScroll,
                                                                showOpeningHours  : $showOperatingHours,
                                                                isEventEdited : $isEventEdited,
                                                                askForSignIn : $askForSignIn,
                                                                detailListObj : self.detailListObj, isforUserProfile : isforUserProfile)
                                        .frame(height: pageHeights[tabIndexSelected] > geo.size.height - 170 ? nil :  (geo.size.height - 170),alignment : .top)
                                    }
                                    .tag(0)
                                    
                                    VStack(spacing: 0) {
                                        self.commentsTabView(size: geo.size)
                                        Spacer()
                                    }
                                    .frame(height: pageHeights[tabIndexSelected] > geo.size.height - 220 ? nil :  (geo.size.height - 220),alignment : .top)
                                    .tag(1)
                                    VStack(spacing: 0) {
                                        LOCBusinessMedia(businessId: self.businessID,
                                                         height: $pageHeights[2],
                                                         shouldScroll: $shouldScroll,
                                                         isShowBackBtn: isShowBackBtn ?? false,
                                                         askForSignIn: $askForSignIn,
                                                         loadMorePhotos: $loadMorePhotos,
                                                         size: geo.size,
                                                         progress: self.progress,
                                                         isFromBusinessProfile: true,
                                                         businessName : data.businessName ?? "",
                                                         businessImage : data.imageIDS?.first?.file ?? "")
                                        .padding(.bottom, 0)
                                        Spacer()
                                    }
                                    .frame(height: pageHeights[tabIndexSelected] > geo.size.height - 170 ? nil :  (geo.size.height - 170),alignment : .top)
                                    .tag(2)
                                }
                                .tabViewStyle(PageTabViewStyle())
                                .frame(height: pageHeights[tabIndexSelected])
                                .animation(.none)
                                .transition(.slide)
                                .background(Color.listBackground)
                            }
                            .collapseProgress($progress)
                            .height(min: 150, max: self.headerHeight)
                            .allowsHeaderGrowth()

@Sharrykhan01 Oh, TabView - not TableView, I do apologize. Does it work in a regular ScrollView?

@f3dm76 Yup, but for this it is not taking right height as the views taking due to which data is getting cut after pagination. This is how I am getting individual views height and passing to tabview. Still after 2nd pagination, the data height couldn't be taken by TabView inside ScallingScrollview. If you get the point, please help with the solution.

     VStack{
           // content
        }
        .background(
            GeometryReader { geo in
                Color.clear
                    .preference(
                        key: HeightPreferenceKey.self,
                        value: geo.size.height
                    )
            }
                .onPreferenceChange(HeightPreferenceKey.self) { height in
                    DispatchQueue.main.async {
                        self.height = height 
                    }
                }
        )

@Sharrykhan01 I didn't get it - so does it work as expected in ScrollView? What I am trying to say is that ScalingScrollview is just a ScrollView, so it works similar to it. Also if you fix content's height but it changes in between tabs inside the scroll view, there is no way to keep scroll position nice and stable.
Here is another discussion about this
#13

@f3dm76 Got it man! sounds cool, it is for certain devices to which tabview showing irregular behaviour. But fine ihave to search for other pager view. If you find better please have a ping for me.
Thanks bro!