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: auto scrolling to bottom #4256

Merged
merged 1 commit into from
Dec 10, 2024
Merged

fix: auto scrolling to bottom #4256

merged 1 commit into from
Dec 10, 2024

Conversation

urmauur
Copy link
Member

@urmauur urmauur commented Dec 10, 2024

Describe Your Changes

  1. Imports Adjustments:

    • useCallback is added to the existing imports from React.
  2. New Refs Introduced:

    • prevScrollTop: Added as a useRef to track the previous scroll position.
    • isUserManuallyScrollingUp: Added as a useRef to flag when the user manually scrolls up.
  3. Effect Logic Update:

    • An additional condition is added in the useEffect to return early if the user is manually scrolling up or if parentRef.current is not defined.
  4. Virtualizer Adjustment Function:

    • An early return is added in the shouldAdjustScrollPositionOnItemSizeChange function to avoid adjustments if the user manually scrolls up.
  5. New Scroll Handler:

    • A handleScroll function is defined using useCallback. It detects manual user scrolling by comparing the current scroll position with the previous one.
    • The function also checks if the scroll position reaches the bottom, resetting the manual scrolling flag accordingly.
    • Scroll event handling is added to prevent the default/propagation when manual scrolling is detected, updating prevScrollTop.
  6. DOM Changes:

    • The onScroll event listener is added to a div element referring to handleScroll.

These changes collectively add functionality to detect and handle user-initiated upward scrolling differently, enhancing the control over virtualized list interactions.

Fixes Issues

Screen.Recording.2024-12-10.at.11.26.48.mov

Self Checklist

  • Added relevant comments, esp in complex areas
  • Updated docs (for bug fixes / features)
  • Created issues for follow-up changes or refactoring needed

@urmauur urmauur added the type: bug Something isn't working label Dec 10, 2024
@urmauur urmauur added this to the v0.5.12 milestone Dec 10, 2024
@urmauur urmauur requested a review from louis-jan December 10, 2024 04:38
@urmauur urmauur self-assigned this Dec 10, 2024
Copy link
Contributor

Barecheck - Code coverage report

Total: 68.58%

Your code coverage diff: -0.23% ▾

Uncovered files and lines
FileLines
web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx20-21, 23-24, 26, 30-31, 34-35, 37, 39, 43, 60-62, 64-65, 70, 72-73, 76-78, 80-81, 91, 93, 98-99, 105-106, 108-109, 111-113, 115-116, 120-122, 124, 159

Copy link
Contributor

@louis-jan louis-jan left a comment

Choose a reason for hiding this comment

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

Thank you

Copy link
Contributor

This is the build for this pull request. You can download it from the Artifacts section here: Build URL.

@urmauur urmauur merged commit 09bfc05 into dev Dec 10, 2024
21 checks passed
@urmauur urmauur deleted the fix/auto-scroll-bottom branch December 10, 2024 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: If I scroll up it keeps autoscrolling so I have to fight with it or wait for it to finish
2 participants