AndreaMiotto / PartialSheet

A SwiftUI Partial Sheet fully customizable with dynamic height
https://github.com/AndreaMiotto/PartialSheet/wiki
MIT License
1.73k stars 194 forks source link

PartialSheet Crash when using multiple horizontal scroll views #157

Open jtressle opened 2 years ago

jtressle commented 2 years ago

Hi,

I've constructed a partial sheet that basically has 3 rows of ScrollViews (horizontal). Each has 2 to 4 items, and the contents are static.

Both PartialSheet 2.0 and 3.0 failed intermittently when opening up this view. They fail at self.isPresented = isPresented in the function below:

public func updatePartialSheet<T>(isPresented: Bool? = nil, content: (() -> T)? = nil, onDismiss: (() -> Void)? = nil) where T: View { if let content = content { self.content = AnyView(content()) } if let onDismiss = onDismiss { self.onDismiss = onDismiss } if let isPresented = isPresented { withAnimation(defaultAnimation) { self.isPresented = isPresented } } }

The error messages I'm seeing for both 2.0 and 3.0 are: [error] precondition failure: setting value during update: 94792 followed by: AttributeGraph precondition failure: setting value during update: 94792.

I'm calling my view using partialSheet<Content: View>(isPresented: Binding<Bool>, @ViewBuilder content: @escaping () -> Content) to present my view.

I do not get the failure when I call partialSheetManager.showPartialSheet(content). However, partial sheet does not always present the entire view.

Is there anything I can try?

Thanks

jtressle commented 2 years ago

I was able to solve this issue by placing everything in a vertical scrollview and then adding a fixed height constraint to the overall view.

So I think it was the complexity in calculating the view height that caused this crash.

Thanks,

jtressle commented 2 years ago

One more update. I spoke too soon. The crash still occurs even when setting a fixed height to the view.

Thanks,