Added scroll behavior to layer panel when reordering by mouse#551
Added scroll behavior to layer panel when reordering by mouse#551
Conversation
| } | ||
|
|
||
| scrollTarget.current.scrollTop += scrollDirection * SCROLL_DISTANCE; | ||
| updateScrollRatio(); |
There was a problem hiding this comment.
This is the cheeky bit. This updates scrollRatio which causes the component to re-render - and including scrollRatio in the deps array then makes this effect re-run.
There was a problem hiding this comment.
Hm, it might be too cheeky. React (occasionally) complains that Maximum update depth exceeded. I'll rewrite to RAF...
There was a problem hiding this comment.
I agree - should definitely do a requestAnimationFrame and probably cancel it on cleanup and then we should also use useBatchingCallback for updateScrollRatio.
But my alternative suggestion is also this:
useEffect()onstartScrollandscrollDirection.- The effect will start interval and cancel it in the cleanup function.
- On each interval callback: read current scroll position, calc
canScrollX, and increment/decrement the scroll position.
This way, there's no re-rendering involved on each cycle. And such a scrolling implementation is more similar to the actual manual browser scroll. Another thing this could allow in the future: since the whole scrolling process will be captured within a single useEffect/setInterval we can play with the momentum. E.g. a longer scroll could pick up speed.
|
Size Change: +1.62 kB (0%) Total Size: 508 kB
ℹ️ View Unchanged
|
|
|
||
| const updateScrollRatio = useCallback(() => { | ||
| const node = scrollTarget.current; | ||
| if (!node) return; |
| } | ||
|
|
||
| scrollTarget.current.scrollTop += scrollDirection * SCROLL_DISTANCE; | ||
| updateScrollRatio(); |
There was a problem hiding this comment.
I agree - should definitely do a requestAnimationFrame and probably cancel it on cleanup and then we should also use useBatchingCallback for updateScrollRatio.
But my alternative suggestion is also this:
useEffect()onstartScrollandscrollDirection.- The effect will start interval and cancel it in the cleanup function.
- On each interval callback: read current scroll position, calc
canScrollX, and increment/decrement the scroll position.
This way, there's no re-rendering involved on each cycle. And such a scrolling implementation is more similar to the actual manual browser scroll. Another thing this could allow in the future: since the whole scrolling process will be captured within a single useEffect/setInterval we can play with the momentum. E.g. a longer scroll could pick up speed.
|
Heads up: this is already ongoing: #709 |
|
This should be unblocked now :)) |
# Conflicts: # assets/src/edit-story/app/snackbar/useSnackbar.js # assets/src/edit-story/components/panels/layer/layerList.js
| // Disable reason: This one does not need keyboard interactivity | ||
| // - there are better ways to reorder using keyboard. | ||
| // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events | ||
| <Wrapper onMouseOver={handlePointerEnter} {...props}> |
There was a problem hiding this comment.
Had to switch this one to mouseover. The problem was, that with a scrolling container, a new separator might scroll in under the cursor, but without the cursor actually leaving and entering the separator, it would not correctly register as the current one.
With mouse over, this is fixed, as this event also triggers, when the element moves under the mouse, and not just when the mouse moves over the element.
This might have issues for touch devices, but we'll have to revisit then.
| return ( | ||
| <Context.Provider value={state}> | ||
| <ReorderableContainer {...props}>{children}</ReorderableContainer> | ||
| <ReorderableContainer ref={setScrollTarget} {...props}> |
There was a problem hiding this comment.
Can't just use the ref here, as we actually need the parent container, which is the one that actually scroll. Or we could just use the ref directly here and then use ref.current.parentNode where used. But ref'ing the parent directly seems more sensible here.
|
I'm already LGTM on this. So to @wassgha to do the final approval. |
| const scrollTarget = useRef(null); | ||
|
|
||
| const setScrollTarget = useCallback( | ||
| (node) => (scrollTarget.current = node.parentElement), |
There was a problem hiding this comment.
This currently breaks the document tab on the right hand side
Uncaught TypeError: Cannot read property 'parentElement' of null
There was a problem hiding this comment.
Just saw the same thing trying to work on the Document Panel.
Looks like a test is missing for the tabs to ensure these at least open without erroring.
* master: (61 commits) Change placeholder text for pre-publish panel (#934) Bump @ampproject/toolbox-optimizer from 2.0.1 to 2.1.0 (#931) Bump eslint-plugin-testing-library from 3.0.1 to 3.0.2 (#932) Fix Document panel crashing (#930) Fix deployment (#928) Update URL when publishing post. (#836) Fix multiple warnings and proptype issues (#929) Added scroll behavior to layer panel when reordering by mouse (#551) Fix forms events in Firefox (#875) Add save story error message (#888) lints fixed tests font size calculations fixed Use native aspect-ration format for grid layers Fixed behavior for selected elements (#924) Fix ID prefix in auto-advanve-after (#915) Review fixes Switch to using Resource object throughout. Fix related bugs. Bump uuid from 7.0.2 to 7.0.3 (#913) Use Resource type everywhere relevant ...
…working * master: (50 commits) Update react-moveable and disable snap digits again (#941) Template Animation: Added move and repeater animation (#618) (#881) Fix storybook hierarchy (#939) Fix spinner / progress bar when saving (#937) Change placeholder text for pre-publish panel (#934) Bump @ampproject/toolbox-optimizer from 2.0.1 to 2.1.0 (#931) Bump eslint-plugin-testing-library from 3.0.1 to 3.0.2 (#932) Fix Document panel crashing (#930) Fix deployment (#928) Update URL when publishing post. (#836) Fix multiple warnings and proptype issues (#929) Added scroll behavior to layer panel when reordering by mouse (#551) Fix forms events in Firefox (#875) Add save story error message (#888) lints fixed tests font size calculations fixed Use native aspect-ration format for grid layers Fixed behavior for selected elements (#924) Fix ID prefix in auto-advanve-after (#915) ...
* master: (56 commits) Add Snackbar for Invalid Links. (#912) Renamed files to make more sense, updated aria-label. Finished initial pass on Dashboard My Stories Page UI Grid View Update react-moveable and disable snap digits again (#941) Template Animation: Added move and repeater animation (#618) (#881) Fix storybook hierarchy (#939) Fix spinner / progress bar when saving (#937) Change placeholder text for pre-publish panel (#934) Bump @ampproject/toolbox-optimizer from 2.0.1 to 2.1.0 (#931) Bump eslint-plugin-testing-library from 3.0.1 to 3.0.2 (#932) Fix Document panel crashing (#930) Fix deployment (#928) Update URL when publishing post. (#836) Fix multiple warnings and proptype issues (#929) Added scroll behavior to layer panel when reordering by mouse (#551) Fix forms events in Firefox (#875) Add save story error message (#888) lints fixed tests font size calculations fixed ...
Add scroll behavior when over edges of layer panel when mouse drag reordering layers.
Uses
requestAnimationFrameto updatescrollTopincrementally.Fixes #529, fixes #718.