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

Add a function to scroll to top when the header view is sticked. #86

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wanderingfairy
Copy link

To fix the issue in #67, a function was added.

The reason why changes to scrollView.contentOffset are ignored when the headerView is in the sticked state is related to the scrollView.observe() method.

As soon as scrollView.contentOffset is changed, the parentScrollViewDidScroll(_:) is called immediately, and parentContentOffsetY is compared with headerStickyHeight.

And because parentScrollView.contentOffset.y is reset based on the comparison result in the switch statement, the 'scroll to top' operation desired by the user is not executed.

In order to bypass parentScrollViewDidScroll(_:) with minimal impact on other parts, I added a function that disables parentKeyValueObservation for 2 seconds. If the deactivation time is too short, contentOffset.y is intercepted by the observe() method before moving to the top, so I set it to 2 seconds.

contentOffset.y is reset to zero for 2 seconds when parentKeyValueObservation is disabled.

Like resetCurrentChildViewControllerContentOffsetY or resetOtherCachedChildViewControllerContentOffsetY, the parentViewController needs a method to scroll to the top.

If you call self.resetCurrentParentViewControllerContentOffsetY(scrollView) in SegementSlideViewController, the scrollView is scrolled to the top of the scrollView even if headerView is sticked.

Thank you.

@codecov
Copy link

codecov bot commented May 13, 2021

Codecov Report

Merging #86 (c3fb911) into master (34665bd) will decrease coverage by 0.94%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master      #86      +/-   ##
==========================================
- Coverage   73.58%   72.64%   -0.95%     
==========================================
  Files          11       11              
  Lines         106      106              
==========================================
- Hits           78       77       -1     
- Misses         28       29       +1     
Impacted Files Coverage Δ
Source/Switcher/BadgeView.swift 92.53% <0.00%> (-1.50%) ⬇️

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

Successfully merging this pull request may close these issues.

1 participant