Question: Keeping UIView instances outside the closure #231
-
This is more a technical question than an issue, my approach worked really well so far, but I wanted to know if this would overstretch the purpose of this library, and see if there could be derived issues that I didn't foresee. I need to implement fairly complicated behaviours on a ScrollView and so far none of these are available in pure SwiftUI, so I kept an instance of the scrollView as in the example below, assigning its delegate and using KVO on it, so I can keep track/change the contentOffset, detect when the user did release the dragging gesture and more.
Note this code is a simplified version, I noticed that the actual scrollView instance provided sometimes changes and I keep always the latest version, and I maintain the delegate, KVO and all properties updated accordingly. Is this approach reliable enough? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@oriolpregona this is totally fine. I use an approach similar to yours for As a side note, note there's a newly released module that you should if possible prefer using, as follows: import SwiftUIIntrospect
ScrollView {
MyListView()
}
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16), .tvOS(.v13, .v14, .v15, .v16)) { scrollView in
self.myScrollView = scrollView
} |
Beta Was this translation helpful? Give feedback.
-
I happen to need such a feature as well, but I don't know how to implement it. Could you please teach me how to write the code for this solution? Thank you very much. |
Beta Was this translation helpful? Give feedback.
@oriolpregona this is totally fine. I use an approach similar to yours for
UINavigationController
in my https://github.com/davdroman/swiftui-navigation-transitions library.As a side note, note there's a newly released module that you should if possible prefer using, as follows: