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

Fix: Introspector in iOS 14 not working for ScrollView (#55) #56

Closed

Conversation

lucastimeless
Copy link

@lucastimeless lucastimeless commented Sep 25, 2020

Looks like in iOS 14 the sibling view is the UIScrollView, as opposed to a ViewHost containing a UIScrollView. Added a check to see if the sibling itself is a UIScrollView.

The iOS 14 SwiftUI ScrollView type is as follows:

<SwiftUI.HostingScrollView: 0x7fd3ae835200; baseClass = UIScrollView; frame = (84.5 0; 151.5 568); anchorPoint = (0, 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x600001de89f0>; layer = <CALayer: 0x60000134e060>; contentOffset: {0, -20}; contentSize: {151.5, 1746.5}; adjustedContentInset: {20, 0, 0, 0}>

Tested using a simple example app:

image

image

@collindbell
Copy link

Been using this fix in production on a ScrollView and List. It works in both iOS 13 and 14.

@gianfrangiamore
Copy link

Been using this fix in production on a ScrollView and List. It works in both iOS 13 and 14.

Are you able to change the sectionFooterHeight for a List/TableVIew? The code gets called but the height never changes until the list is updated (such as adding or deleting something in the list).

@collindbell
Copy link

collindbell commented Sep 27, 2020 via email

@gianfrangiamore
Copy link

I haven't tried (though I can in a bit). I am using it successfully to hide list separators and disable scrolling in Lists and ScrollViews.

Does this work for you?

struct ContentView: View {
    var body: some View {
        List {
            ForEach(1..<10) { num in
                Text("\(num)")
            }
        }
        .introspectTableView(customize: { tableView in
            tableView.separatorStyle = .none
        })
        .listStyle(InsetGroupedListStyle())
        
    }
}

I've checked out the specific commit. The code above doesn't remove the separator inset. Am I doing something wrong?

@lucastimeless
Copy link
Author

Looks like in iOS 14 SwiftUI is handling the separator on its own and not respecting tableView.separatorStyle. In your code snippet tableView.separatorStyle is actually already .none before it gets assigned (meaning SwiftUI sets it to .none and simply handles the separators itself). A better library for your use case might be:

https://github.com/SchmidtyApps/SwiftUIListSeparator

@gianfrangiamore
Copy link

gianfrangiamore commented Oct 4, 2020

Looks like in iOS 14 SwiftUI is handling the separator on its own and not respecting tableView.separatorStyle. In your code snippet tableView.separatorStyle is actually already .none before it gets assigned (meaning SwiftUI sets it to .none and simply handles the separators itself). A better library for your use case might be:

https://github.com/SchmidtyApps/SwiftUIListSeparator

I was actually just using the line separator as an example.

What I wanted to use this library for was to reduce the height of the section footer/header.

I've noticed that if you call tableView.reloadData() after changing the height, then it works, but it takes a second to kick in, so when you launch the app the height is set to whatever the default is, and then you see the rows suddenly jump and the height is changed to whatever it was set to.

Have you got any suggestions?

@subin-sb
Copy link

subin-sb commented Oct 6, 2020

Hi, this fix works for my use cases... Waiting for this to be pulled to master...

@lucastimeless lucastimeless mentioned this pull request Oct 6, 2020
@d4rkd3v1l
Copy link

Somehow this doesn't work for me on device/simulator. But works in SwiftUI Previews 🤷‍♂️🙈
Device iOS 14.0.1
Simulator iOS 14.1 (Preview should be the same 0_o)

@jchitel jchitel mentioned this pull request Oct 21, 2020
@ldiqual
Copy link
Contributor

ldiqual commented Oct 21, 2020

@lucastimeless Thanks a ton for looking into this! I adapted your code and created 2 different methods instead. It's now fixed in master, and we can close both this PR and #55 . See 6ddd059
Thanks again and sorry for the delay!

@ldiqual ldiqual closed this Oct 21, 2020
Copy link

@connect2fayis connect2fayis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking

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

Successfully merging this pull request may close these issues.

8 participants