OfTheWolf / UBottomSheet

iPhone Maps App bottom sheet - A Protocol Oriented Approach
MIT License
653 stars 68 forks source link

SwiftUI integration #62

Open philipholler opened 3 years ago

philipholler commented 3 years ago

Hi OfTheWolf,

This package looks great!

Is there any way to integrate it into an app with SwiftUI?

Maybe using UIViewControllerRepresentable?

I can't seem to find any package delivering the same functionality as this for SwiftUI

philipholler commented 3 years ago

The problem with all the SwiftUI solutions is, that they cannot contain a scrollview and still be able to move the sheet when dragging.

OfTheWolf commented 3 years ago

@philipholler SwiftUI has a ".sheet" extension which works great. You don't need to rely on any 3rd party sheet lib in SwiftUI.

Please see the official doc: https://developer.apple.com/documentation/SwiftUI/AnyView/sheet(isPresented:onDismiss:content:)

philipholler commented 3 years ago

Yes, the SwiftUI sheet works great in situations where you only need two state, that is cover the entire screen og dismissed. In case one needs 3 States, however, (for example like in apple maps), it is not usable. Additionally the SwiftUI sheet pushes back the rest of the views like a modal. This can also not be disabled

OfTheWolf commented 3 years ago

Ah ok. I will look into this thoroughly.

philipholler commented 3 years ago

That sounds great. Please let me know, if there’s anything i can help with :-)

tomsun3 commented 2 years ago

Hi! Any updates on that? Do you (@OfTheWolf @philipholler) know newer/current alternatives for SwiftUI? Thanks a lot in advance :)

OfTheWolf commented 2 years ago

Hi @thomasmo3 @philipholler,

I couldn't have a chance to look at this. I can recommend https://github.com/applidium/OverlayContainer for Swift UI support.

Thanks

GerdC commented 1 year ago

If you want SwiftUI content inside of UBottomSheet with scrolling: I did that. So far it works fine.

The main trick is to use a a UIKit UIScrollView.

The UIScrollView contains a UIView that contains a UIHostingController that contains SwiftUI.

This way, UBottomSheet has its UIScrollView to work with and does not know that it handles SwiftUI content. The SwiftUI code must not come with a ScrollView or anything else that scrolls.

There are still good reasons to use UBottomSheet. My main reason is that both UISheetPresentationController and SwiftUI .sheet do not work together with UITabBarController