exyte / ScalingHeaderScrollView

A scroll view with a sticky header which shrinks as you scroll. Written with SwiftUI.
MIT License
1.16k stars 82 forks source link

Not Working in VStack #51

Closed Ankooo12 closed 8 months ago

Ankooo12 commented 8 months ago

I have added a ScalingHeaderScrollView in VStack add added a customView with height 20 and ScalingHeader added spacing in content and crop the header. I have attached code and screen shot

Untitled

` struct SimpleScalingHeader: View {

@Environment(\.presentationMode) var presentationMode

@State private var selectedImage: String = "image_1"
@State private var isLoading: Bool = false

var body: some View {
    VStack {
        HStack{
            Text("MyCustom View")
        }
            .frame(height: 20)
        ZStack(alignment: .topLeading) {
            ScalingHeaderScrollView {
                Image(selectedImage)
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .clipped()
            } content: {
                Text(defaultDescription)
                    .padding()
            }
            .pullToRefresh(isLoading: $isLoading) {
                changeImage()
            }
            .allowsHeaderCollapse()
            .ignoresSafeArea()

            Button("", action: { self.presentationMode.wrappedValue.dismiss() })
                .buttonStyle(CircleButtonStyle(imageName: "arrow.backward"))
                .padding(.leading, 16)
        }
    }
}

// MARK: - Private

private func changeImage() {
    selectedImage = selectedImage == "image_1" ? "image_2" : "image_1"
    isLoading = false
}

} `

Changes are done in Example. So please check

Same issue happen with TabView(Page)

`

import SwiftUI import ScalingHeaderScrollView

struct SimpleScalingHeader: View {

@Environment(\.presentationMode) var presentationMode

@State private var selectedImage: String = "image_1"
@State private var isLoading: Bool = false

var body: some View {
    TabView {
        ZStack(alignment: .topLeading) {
            ScalingHeaderScrollView {
                Image(selectedImage)
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .clipped()
            } content: {
                Text(defaultDescription)
                    .padding()
            }
            .pullToRefresh(isLoading: $isLoading) {
                changeImage()
            }
            .allowsHeaderCollapse()
            .ignoresSafeArea()

            Button("", action: { self.presentationMode.wrappedValue.dismiss() })
                .buttonStyle(CircleButtonStyle(imageName: "arrow.backward"))
                .padding(.leading, 16)
        }
    }
    .tabViewStyle(.page)
}

// MARK: - Private

private func changeImage() {
    selectedImage = selectedImage == "image_1" ? "image_2" : "image_1"
    isLoading = false
}

} `

Please check it. ASAP

Ankooo12 commented 8 months ago

I solved the issue. It is for Pull Request #49

Working: getScrollOffset() - scrollGeometry.frame(in: .global).minY + globalGeometry.frame(in: .global).minY

No Working: getScrollOffset() - scrollGeometry.frame(in: .global).minY - globalGeometry.frame(in: .global).minY