Skip to content

Instantly share code, notes, and snippets.

@iAmVishal16
Created April 9, 2025 08:53
Show Gist options
  • Select an option

  • Save iAmVishal16/7c9d409b08affc6f0fae5ab830bd08a7 to your computer and use it in GitHub Desktop.

Select an option

Save iAmVishal16/7c9d409b08affc6f0fae5ab830bd08a7 to your computer and use it in GitHub Desktop.
Sheet is always visible and not dismissible. Background buttons & text field remain interactive. Works with dynamic sheet sizing (small & medium heights).
import SwiftUI
struct HomeView: View {
@State private var isSheetPresented = true
@State private var textInput: String = ""
@State private var tapCount = 0
var body: some View {
ZStack {
Color.purple
.edgesIgnoringSafeArea(.all)
// Interactive background elements
VStack(spacing: 20) {
Text("Background Content")
.font(.title)
.foregroundColor(.white)
Text("Tap count: \(tapCount)")
.foregroundColor(.white)
Button(action: {
tapCount += 1
}) {
Text("Tap Me!")
.padding()
.background(Color.white)
.foregroundColor(.purple)
.cornerRadius(10)
}
TextField("Type something...", text: $textInput)
.textFieldStyle(.roundedBorder)
.padding()
}
.padding()
}
.sheet(isPresented: $isSheetPresented) {
Text("Half screen content here")
.presentationDetents([.fraction(0.35), .medium])
.interactiveDismissDisabled(true)
.presentationBackgroundInteraction(.enabled(upThrough: .medium))
}
}
}
#Preview {
HomeView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment