question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access shared value of scrollY in Scrollables

See original GitHub issue

Ask your Question

Is there a way to access the scrollY value of BottomSheetScrollView so I can animate other elements while the user scrolls? If so, how can I achieve this? In v3 I was able to achieve this by setting value in onScroll prop which is not accessible anymore.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
branislaavcommented, Jan 3, 2022

@mohandere sorry for the late response. I was able to access scrollY by customizing scrollEventsHandlersHook. My solution is not perfect but works for now if anyone has an idea how this can be achieved in a better way let us know, please.

Solution: I copied useScrollEventsHandlersDefault to my repository and renamed it to useCustomScrollEventsHandlers also added third argument scrollY, than I added this block of code to handleOnScroll callback

if (animatedScrollableState.value !== SCROLLABLE_STATE.LOCKED) {
       scrollY.value = e.contentOffset.y
 }

after that, you can use it in a bottom sheet like this

const scrollY = useSharedValue(0)

<BottomSheetScrollView
      scrollEventsHandlersHook={(ref, contentOffsetY) =>
          useCustomScrollEventsHandlers(ref, contentOffsetY, scrollY)
      }
>
0reactions
branislaavcommented, Jan 9, 2022

just spotted a bug in my implementation. 🙈 I had sticky header animation styles applied on scrollY but after I called bottomSheetRef.current?.collapse() when still scrolled and then expanded bottom sheet back to full height, header animated styles were still applied.

It looks that I was able to fix it by adding

if (animatedScrollableState.value === SCROLLABLE_STATE.LOCKED) {
     scrollY.value = 0
}

to handleOnScroll callback

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get the scrollbar position with JavaScript?
scrollTop - is the pixels hidden in top due to the scroll. With no scroll its value is 0. element.scrollHeight - is the...
Read more >
4 Ways to Listen to Page Scrolling for Dynamic UI in Angular ft ...
First, we create a BehaviourSubject to store the scrollY position. Additionally, we create an observable from the scrollY BehaviorSubject, to ...
Read more >
Scrollable element is keyboard accessible[proposed] | ACT Rule
Description. This rule checks that scrollable elements can be scrolled by keyboard. Applicability. This rule applies to any HTML element that has visible ......
Read more >
Scrollable element is keyboard accessible
A scrollable element is an element with a horizontal scroll distance or a vertical scroll distance greater than 0. horizontal scroll distance: ...
Read more >
Access scrollbar.value not possible through code? - Unity Forum
This position is controlled by Scrollbar.value , but it seems i can't access it through code. I tried both Awake(), Start() and OnEnable() ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found