Allow ScrollView to be controllable via scrollTop#740
Allow ScrollView to be controllable via scrollTop#740joefiorini wants to merge 3 commits intorevery-ui:masterfrom
Conversation
|
@Et7f3 looks like the build failed due to cache restore failures on macOS and Linux. Then the test run hung on macOS with no output (and timed out after 15 minutes). Could this be a build agent issue? Is it possible to rerun the checks? |
glennsl
left a comment
There was a problem hiding this comment.
We've done something similar for the TreeVIew in Oni2, except it uses a spring animation instead of a custom bounce mechanism, and supports alignment using other reference poiits than just top. But maybe it can serve as a source of inspiration anyway.
Most of the complexity of the scrolling mechanism is encapsulated in a custom useScroll hook, which is then used here.
| let%hook () = | ||
| Hooks.effect( | ||
| Always, | ||
| () => { | ||
| if (scrollTop != actualScrollTop) { | ||
| switch (onScroll) { | ||
| | Some(_) => dispatch(ScrollUpdated(scrollTop)) | ||
| | None => () | ||
| }; | ||
| }; | ||
| None; | ||
| }, | ||
| ); |
There was a problem hiding this comment.
I don't think this will work if ~scrollTop is omitted, since it would then always reset to 0, its default value. So either scrollTop and onScroll needs to be mandatory, which I don't think is desirable, or scrollTop needs to be optional but without a default value so this can be skipped if it's not set.
There was a problem hiding this comment.
@glennsl I just tested it by adding an additional ScrollView to the example and leaving off the onScroll and scrollTop. Everything seemed to work fine in that case. Then I passed just a scrollTop and it rendered as expected. Are you referring to a case where scrollTop is missing but onScroll is provided?
There was a problem hiding this comment.
Hmm, yeah that's a necessary condition too. It should check for the presence of scrollTop instead of onScroll. It's not very intuitive that hard-coding scrollTop and not setting onScroll would result in scrollTop being ignored.
I also don't think the effect hook is really necessary, and mostly just complicates the logic. Instead you could rename actualScrollTop to something like InternalScrollTop and then set actualScrollTop to scrollTop if present, or internalScrollTop if not.
|
@joefiorini I had rerun the check and it is 👌. |
Allows setting/syncing
scrollTopproperty ofScrollViewso consumers can dynamically update scroll position as needed. AddsonScrollprop to allow the parent component to keep the scroll value in sync when the user manually scrolls.