Skip to content

Instantly share code, notes, and snippets.

@byJeevan
Last active April 22, 2024 07:45
Show Gist options
  • Save byJeevan/f67485bf380e86d4f87a723ac383827c to your computer and use it in GitHub Desktop.
Save byJeevan/f67485bf380e86d4f87a723ac383827c to your computer and use it in GitHub Desktop.
SwiftUI Components & Extension that saves iOSDev time.
### UIKit is **EVENT-Driven** framework - We could reference each view in the hierarchy, update its appearance when the view is loaded or as a reaction on an event.
### SwiftUI is **Declarative, State Driven** framework - We cannot reference any view in the hierarchy, neither can we directly mutate a view as a reaction to an event.
Instead, we mutate the state bound to the view. Delegates, target-actions, responder chain, KVO .. replaced with Closures & bindings.
@byJeevan
Copy link
Author

List without separator (from iOS 15.0+)

          List {
            ForEach(items, id: \.self) { item in
              Text("item here")
                .listRowSeparator(.hidden)

            }
          }
          .listStyle(.plain)

@byJeevan
Copy link
Author

☢️ A workaround calculated the height of ScrollView

  @State var heightCalculated = 0.0

  var body: some View {

    ScrollView {
      ForEach(0..<10) { i in
        Text("\(i)")
      }
      .background(
        GeometryReader { proxy in
          Color.clear.onAppear { 
            heightCalculated = proxy.size.height
            debugPrint(proxy.size.height)
          }
        }
      )

    }
    .frame(height: heightCalculated)
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment