Swiftpack.co - NuPlay/FitScrollView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by NuPlay.
NuPlay/FitScrollView 1.0
Scrollview that fits the size of the child view
⭐️ 7
🕓 2 years ago
iOS
.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: 7
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

V1.0
2 years ago

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