danielsaidi / SwiftUIKit

SwiftUIKit is a Swift SDK that adds extra functionality to Swift & SwiftUI.
MIT License
1.42k stars 56 forks source link

Unreliable UndimmedPresentationDetentsViewModifier behavior #20

Closed stephensilber closed 1 year ago

stephensilber commented 1 year ago

Firstly, thanks for this great library. There's a lot of great stuff in here.

We have been experimenting with using SwiftUIKit for our bottom sheets so that we can allow background interactions while sheets are presented. This works in basic use cases but I find that ~30% of the time when my sheet is presented there is still a dimmed view covering the background. It seems to happen the most on the first appearance although I don't have any data to back that up.

Here's our ideal workflow:

  1. A PostDetailView sheet is presented with: .presentationDetents(undimmed: [.fraction(0.6)], largestUndimmed: .fraction(0.6))

  2. If a user taps the edit button, a separate PostEditorView sheet is presented with: .presentationDetents(undimmed: [.fraction(0.6)], largestUndimmed: .fraction(0.6))

(Note: Even up until this point before we start changing the selected detent the behavior seems to be a bit hit or miss)

  1. There are multiple controls in the PostEditorView that each have their own heights. For example, we would love to be able to switch the selected state between .fraction(0.2) and .fraction(0.6) using the selection property:
            .presentationDetents(undimmed: viewStore.isUsingTools ? [.fraction(0.2)] : [.fraction(0.2), .fraction(0.6)],
                                 largestUndimmed: .fraction(0.6),
                                 selection: .constant(viewStore.isUsingTools ? .fraction(0.2) : .fraction(0.6)))

Unfortunately, whenever we change the selection programmatically to .fraction(0.2) it seems to add the dimmed view back which does not goes away if we set the selection back to .fraction(0.6).

danielsaidi commented 1 year ago

Hi @stephensilber

Happy to hear that you like it! :)

I haven't used this in a while, but I will try to find time to look at it once I'm done with my current project. If you or anyone else manage to find out more info in the meantime, let's keep the discussion going.

stephensilber commented 1 year ago

Unfortunately we ended up needing to go all in with UIKit because of some other restrictions in our navigation flow but when I was experimenting I noticed that moving the avoidDimmingParent and avoidDisablingControls to viewDidLayoutSubviews mostly fixed the issue. Not sure if its the best solution but might point you in the right direction.

danielsaidi commented 1 year ago

Ok, great thanks for letting me know! I will take a look 👍