Repository navigation
fix(ios): emit onPageScroll and onPageScrollStateChanged on iOS 15 #1179
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import UIKit | |
| Scroll delegate used to control underlying TabView's collection view. | ||
| */ | ||
| class PagerScrollDelegate: NSObject, UIScrollViewDelegate, UICollectionViewDelegate { | ||
| weak var originalDelegate: UICollectionViewDelegate? | ||
| weak var originalDelegate: UIScrollViewDelegate? | ||
| weak var delegate: PagerViewProviderDelegate? | ||
| var orientation: UICollectionView.ScrollDirection = .horizontal | ||
|
|
||
|
|
@@ -78,11 +78,13 @@ class PagerScrollDelegate: NSObject, UIScrollViewDelegate, UICollectionViewDeleg | |
| } | ||
|
|
||
| func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { | ||
| originalDelegate?.collectionView?(collectionView, didEndDisplaying: cell, forItemAt: indexPath) | ||
| (originalDelegate as? UICollectionViewDelegate)?.collectionView?(collectionView, didEndDisplaying: cell, forItemAt: indexPath) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: Why is this casting needed? Why can't we have
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of the type change on line 7. With The cast always succeeds here. These two methods are only called on the collection view's instance, and the original delegate there is SwiftUI's coordinator, which conforms to |
||
| } | ||
|
|
||
| func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { | ||
| originalDelegate?.collectionView?(collectionView, willDisplay: cell, forItemAt: indexPath) | ||
| // iOS 15 only, see PagerViewIOS15Compat.swift (delete together with the iOS 15 support). | ||
| PagerViewIOS15Compat.attachScrollDelegate(to: collectionView, delegate: delegate) | ||
| (originalDelegate as? UICollectionViewDelegate)?.collectionView?(collectionView, willDisplay: cell, forItemAt: indexPath) | ||
| } | ||
|
|
||
| override func responds(to aSelector: Selector!) -> Bool { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: Could you explain this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On iOS 15 the delegate of the embedded scroll view is UIKit's private
_UICollectionViewOrthogonalScrollerSectionController. It only conforms toUIScrollViewDelegate, notUICollectionViewDelegate, andPagerScrollDelegatenow forwards to it too.