-
-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SwiftUI Support/Example? #281
Comments
Thank you for your attempt for Swift UI! |
Hi @scenee, |
@sipersso Yes it is. But now I’m focusing to fix some issue on v1.x and I would like to release v2 on March. |
@sipersso I've tried multiple ways, such as embedding SwiftUI views into auto-resizing If you really want to use SwiftUI today, my suggestion is to implement this floating panel yourself (I haven't done it): with a geometry reader and a gesture recogniser you should be able to accomplish everything you need. Thank you @scenee for all your support ❤️ |
I agree with, it is a great library @scenee. @zntfdr I did get scroll tracking to work with SwiftUI. The trick, which is missing from your example is to set the content size of the scrollView to the size of the hostingController view.
The downside is that if you the swiftui view is resized you would have to reset the contentsize and I am not sure how to get notified to do that. Other than that it seems to work pretty great and it does allow for interaction in SwiftUI as well as track scrolling. I also did try to recreate the Panel in SwiftUI, but none of my attempts where nearly as good as the component that @scenee has built. Using the hybrid approach, UIKit panel, but SwiftUI content, makes it really easy to use from a UIKit UIViewController ;) |
Very cool! Many thanks @sipersso, I will experiment some more as soon as possible 😃
That's why I didn't try to reimplement the whole thing myself: I want to keep the feeling of a normal scroll view (with the iOS default pull elasticity, etc) 👍 |
@sipersso I haven't managed to get the scroll tracking to work with SwiftUI, can you please share your code? |
I got ideas from this But had to adapt it a little by setting the content size of the scrollview.
In my floatingpanelcontroller subclass I create an instance of my UIScrollViewViewController and then use this in ViewDidLoad
Note that this won't work if your swiftui view changes height. You would have to ajust the contentsize of the scrollview every time this happens. |
Thank you @sipersso, I still can't get the scroll tracking even with your code snippets: Might try again in a few days 👍 A full working example similar to the one I posted on the first post would be greatly appreciated 🚀 |
Hi @zntfdr! Unfortunately I can't share much more than I already have. The rest of my code is non-generic and would be quite an effort for me to provide a more detailed/standalone example |
No worries @sipersso, many thanks for the support! 🤗 |
@zntfdr Here is working example:
|
Many thanks @ramunasjurgilas 😃 |
@ramunasjurgilas I'm afraid that your example doesn't work. As you can see from the video below, scrolling is tracked only when the scroll is outside of the Thank you for trying! 😊 |
@zntfdr just checked the example you provided. You are using List and this has it's own scrollview, which explains why the scrolltracking isn't working. Try using a VStack instead in SwiftUI. |
Update: I've added a SwiftUI implementation in #481. While the example shows a mix of UIKit and SwiftUI, if you use something like ContentView()
.floatingPanel { proxy in
ScrollView {
// .. your content here.
}
.introspectScrollView { scrollView in
proxy.track(scrollView: scrollView)
}
} If you'd like to try it out in your app, copy the Please try it out and let me know how it goes 😃 |
Partially solves #281. This adds a new example app which mimics the Maps.app, written in SwiftUI. The code works for iOS 13+, however: * the project has been created with Xcode 13 * the project uses the SwiftUI lifecycle (iOS 14+) The source code in Examples/Maps-SwiftUI/Maps/FloatingPanel is ready to move into the library, but there is an issue on SwiftUI’s environment propagation into FloatingPanel. SwiftUI’s environment is propagated to all subviews. However FloatingPanel is not a subview, but a new view controller in the screen (and not a child view controller). It’s possible to lead behaviors unexpected by SwiftUI users so that this is merged as a sample code until it will be resolved.
For me, this does not work if the content height is dynamic. Anyone else has the same problem? |
I'm trying to make the library work with SwiftUI, and was wondering if you have had any success so far.
You can find my attempt here:
Steps:
FloatingPanel
projectViewController.swift
ViewController.swift
content with:Click here to see the source code
Current working example:
Thank you in advance!
Federico
The text was updated successfully, but these errors were encountered: