Skip to content
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

Introspector in iOS 14 not working for ScrollView... #55

Closed
luap2703 opened this issue Sep 20, 2020 · 11 comments
Closed

Introspector in iOS 14 not working for ScrollView... #55

luap2703 opened this issue Sep 20, 2020 · 11 comments

Comments

@luap2703
Copy link

First of all the specs: iOS 14, Xcode 12.2 beta and Catalina running on my Mac.

I tried to add a pulltorefresh function to a ScrollView in Swiftui but it doesnt show up. Actually the whohle introspect is never called. I tried a few times and it actually only works if I change it to List, but not with ScrollView like it is shown in the Github example. As I defo need it for ScrollView I need your help. Cheers...

So this one actually works:

List {
ForEach(0..<100)
{ _ in
Text("hello")
}
}
.introspectScrollView { scrollView in
print("Test")
scrollView.refreshControl = UIRefreshControl()
}

while this does not:

ScrollView {
ForEach(0..<100)
{ _ in
Text("hello")
}
}
.introspectScrollView { scrollView in
print("Test")
scrollView.refreshControl = UIRefreshControl()
}

@OmegaWulf
Copy link

I'm seeing the same problem. The introspectScrollView is not being called at all.

@rivera-ernesto
Copy link

rivera-ernesto commented Sep 23, 2020

The problems seems to be that the function:

public static func findAncestor<AnyViewType: PlatformView>(ofType type: AnyViewType.Type, from entry: PlatformView) -> AnyViewType? {
    var superview = entry.superview
    while let s = superview {
        if let typed = s as? AnyViewType { // This won't match a UIScrollView in iOS 14
            return typed
        }
        superview = s.superview
    }
    return nil
}

returns nil as the view that should be recognized is not a UIScrollView but a _TtGC7SwiftUI16PlatformViewHostGVS_P13$7fff56302ab832PlatformViewRepresentableAdaptorGV9FileCloud22UIKitIntrospectionViewCSo12UIScrollView___.

Where I have manually added the project sources to workaround my app having a deployment target < iOS 13.

Some debugger testing:

$ po entry
<FileCloud.IntrospectionUIView: 0x7f8181156680; frame = (0 0; 10 10); hidden = YES; userInteractionEnabled = NO; layer = <CALayer: 0x600001004ca0>>

$ po entry.superview
▿ Optional<UIView>
  ▿ some : <_TtGC7SwiftUI16PlatformViewHostGVS_P13$7fff56302ab832PlatformViewRepresentableAdaptorGV9FileCloud22UIKitIntrospectionViewCSo12UIScrollView___: 0x7f8181161500; frame = (202 547.333; 10 10); anchorPoint = (0, 0); tintColor = UIExtendedSRGBColorSpace 0.517647 0 0.329412 1; layer = <CALayer: 0x600001005180>>

$ po entry.superview is UIScrollView
false

$ po entry.superview is UIView
true

My SwiftUI code:

ScrollView {
    VStack {
        // ...
    }
}
.introspectScrollView {
    self.scrollViewHelper.scrollView = $0
}

lucastimeless pushed a commit to timeless-space/SwiftUI-Introspect that referenced this issue Sep 25, 2020
@lucastimeless
Copy link

lucastimeless commented Sep 25, 2020

Created a PR with a potential fix: #56

lucastimeless pushed a commit to timeless-space/SwiftUI-Introspect that referenced this issue Sep 28, 2020
commit 0ae9f17
Author: Lucas Wilkinson <wilkinson.lucas@gmail.com>
Date:   Fri Sep 25 00:50:17 2020 -0400

    Fix: Introspector in iOS 14 not working for ScrollView (siteline#55)
@luap2703
Copy link
Author

The #56 fix works fine for as far as I can see!

But I'm facing some other issue by adding a UIRefreshControl to the ScrollView. it has some uncommon behavior by not really showing the refresh animation but disappearing when it is pulled. I also tried it with a List but that seems to only appear on the introspected ScrollView. Am I missing something here or is it a bug? I think the "normal" behavior would be to show the refresh animation forever as I'm not giving it a target. A basic example where it happens for me is:

struct TEST: View {
    var body: some View {
           ScrollView {
           Text("Message 1")
           Text("Message 2")
           Text("Message 3")
            }
           .introspectScrollView() { scrollView in
               print("is now working with fix #56 (so definitly fires at all)")
               scrollView.refreshControl = UIRefreshControl()
           }
    }
}

yRerikh pushed a commit to CodeElves/SwiftUI-Introspect that referenced this issue Sep 30, 2020
@Mactacs
Copy link

Mactacs commented Oct 7, 2020

Hi guys! How did you fix this issue? I also experienced this bug and can't figure out how to solve it. Hoping for a quick response. Thank you

@ImTheSquid
Copy link

@Mactacs Due to the lack of quick updates to this repo, I have just downloaded the codebase mentioned in #56 and put it in a folder in my project. After that I continued importing the library as normal (while making sure to remove any previous SPM references).

@maschoffjake
Copy link

Also seeing the same behavior as Paulo has pointed out. The animation disappears once the UIRefreshControl has been enabled.

@ldiqual
Copy link
Contributor

ldiqual commented Oct 21, 2020

Fixed in master, see 6ddd059. Props to @lucastimeless for their work on #56 !

@ldiqual ldiqual closed this as completed Oct 21, 2020
@Luur
Copy link

Luur commented Nov 19, 2020

Hi @Paulo2703 @maschoffjake @ldiqual Did you find a way how to figure out the issue you described? I'm facing this issue too. The animation disappears once the UIRefreshControl has been enabled.

@maschoffjake
Copy link

maschoffjake commented Nov 21, 2020 via email

@luap2703
Copy link
Author

Hey, so i have found kind of a sneakaround by putting the scrollview into a List, where the introspect uirefreshcontrol actually works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants