Post

Replies

Boosts

Views

Activity

Reply to SwiftUI binding dynamic array problem
One thing I noticed here is that this seems wrong: ForEach(self.checks.indices, id: \.self) { i in CheckView(check: self.$checks[i]) } You already have the individual check captured in the i parameter when you do { i in }. So you don't need to do $checks[i] You cans simply do: ForEach(checks, id: \.self) { check in CheckView(check: check) } You also don't need the indices, you have access to the complete object inside your array within the closure. Furthermore, if you make your check model conform to Identifiable and Hashable (easily done with let id = UUID()) then you don't need the , id: \.self bit either.
Jul ’23
Reply to Change Modality of Sheets in SwiftUI
Playground code here for that. import SwiftUI import PlaygroundSupport struct Donut: View { var body: some View { VStack { Button("Tap me", action: { debugPrint("button tapped") }) .offset(y: 30) .foregroundColor(.white) Circle() .frame(width: 200, height: 200) .foregroundColor(.yellow) .padding(.top, 72) .padding(.bottom, 200) } } } struct NavBar: View { var body: some View { Rectangle() .frame(maxWidth: .infinity) .frame(height: 30) .background(.white) } } struct Feed: View { var body: some View { ScrollView { VStack(spacing: 20) { ForEach(0..<14) { _ in Text("Feed view") } } } .padding(.top, 20) } } struct Main: View { var body: some View { ZStack(alignment: .top) { NavBar() Donut() } .sheet(isPresented: .constant(true)) { Feed() .interactiveDismissDisabled(true) .presentationDetents([.fraction(0.4), .large]) .presentationDragIndicator(.visible) // will always be true when you have 2 detents .presentationBackgroundInteraction(.enabled(upThrough: .medium)) // <- this is the magic property } .background(.green) } } PlaygroundPage.current.setLiveView(Main())
Apr ’23
Reply to Change Modality of Sheets in SwiftUI
Yes there is a way but only iOS 16.4 with Xcode 14.3 you want .presentationBackgroundInteraction(.enabled()) You can use it based on the detents like this: .presentationBackgroundInteraction(.enabled(upThrough: .medium)) This will allow you to interact with the content behind the sheet.
Apr ’23