Swiftpack.co -  NuPlay/FitScrollView as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
NuPlay/FitScrollView
Scrollview that fits the size of the child view
.package(url: "https://github.com/NuPlay/FitScrollView.git", from: "1.0")

FitScrollView

Swift: 5.1+ iOS: 13.0+

githubFit scrollview
FitScrollView ScrollView(SwiftUI)

It is the same as SwiftUI's ScrollView, but for ScrollView, the height (vertical) or width (horizontal) is maximized.
Prevent it and create a ScrollView that fits the size of the internal view.
However, if the size of the internal view is large enough to require scrolling, it will be the same as the normal Scroll View.

Code

import SwiftUI
import FitScrollView

struct FitScrollView_Test: View {
    @State var  html = ""
    
    var body: some View {
       FitScrollView{
            Text("")
        }
    }
}

import SwiftUI
import FitScrollView

struct FitScrollView_Test: View {
    @State var  html = ""
    
    var body: some View {
        FitScrollView(.vertical, showsIndicators: false, content: {
            Text("")
        }
    }
}

SampleCode

import SwiftUI
import FitScrollView

struct FitScrollViewTest: View {
    @State var randomText : [String] = ["Cat","Apple", "pepper", "zero"]
    
    var body: some View {
        ZStack(alignment: .topTrailing){
            ZStack(alignment: .bottom){
                Color.black.opacity(0.4)
                    .ignoresSafeArea()
                
                FitScrollView(.vertical, showsIndicators: false, content: {
                    VStack(alignment: .leading,spacing: 12){
                        ForEach(0 ..< randomText.count , id:\.self) { index in
                            HStack{
                                Text(randomText[index])
                                    .font(.body)
                                    .padding(.horizontal, 12)
                                
                                Spacer()
                            }
                        }
                    }
                })
                .padding(.all, 12)
                .background(
                    Color.white
                        .cornerRadius(16)
                        .ignoresSafeArea()
                )
            }
            
            Button(action: {
                self.randomText.append(contentsOf: ["Cat","Apple", "pepper", "zero"])
            }, label: {
                Text("Add")
            })
            .padding(.horizontal, 12)
            .padding(.vertical, 4)
            .background(
                Capsule()
                    .foregroundColor(.white)
                    .opacity(0.7)
            )
            .padding(.trailing, 16)
        }
        .animation(.spring())
    }
}

struct FitScrollViewTest_Previews: PreviewProvider {
    static var previews: some View {
        FitScrollViewTest()
    }
}

GitHub

link
Stars: 0
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

V1.0
3 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics