Skip to content

Added scroll behavior to layer panel when reordering by mouse#551

Merged
wassgha merged 9 commits intomasterfrom
bug/529-layer-reorder-scroll
Apr 1, 2020
Merged

Added scroll behavior to layer panel when reordering by mouse#551
wassgha merged 9 commits intomasterfrom
bug/529-layer-reorder-scroll

Conversation

@barklund
Copy link
Copy Markdown
Contributor

@barklund barklund commented Mar 12, 2020

Add scroll behavior when over edges of layer panel when mouse drag reordering layers.

Uses requestAnimationFrame to update scrollTop incrementally.

Fixes #529, fixes #718.

@barklund barklund added the Group: Editing Main editing features label Mar 12, 2020
@barklund barklund self-assigned this Mar 12, 2020
}

scrollTarget.current.scrollTop += scrollDirection * SCROLL_DISTANCE;
updateScrollRatio();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, it might be too cheeky. React (occasionally) complains that Maximum update depth exceeded. I'll rewrite to RAF...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

  1. useEffect() on startScroll and scrollDirection.
  2. The effect will start interval and cancel it in the cleanup function.
  3. 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 12, 2020

Size Change: +1.62 kB (0%)

Total Size: 508 kB

Filename Size Change
assets/js/edit-story.js 438 kB +1.62 kB (0%)
ℹ️ View Unchanged
Filename Size Change
assets/css/edit-story.css 3.01 kB 0 B
assets/css/stories-dashboard.css 206 B 0 B
assets/js/stories-dashboard.js 67.3 kB 0 B

compressed-size-action


const updateScrollRatio = useCallback(() => {
const node = scrollTarget.current;
if (!node) return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

{} for return.

}

scrollTarget.current.scrollTop += scrollDirection * SCROLL_DISTANCE;
updateScrollRatio();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

  1. useEffect() on startScroll and scrollDirection.
  2. The effect will start interval and cancel it in the cleanup function.
  3. 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.

@barklund barklund requested a review from dvoytenko March 23, 2020 15:17
@dvoytenko
Copy link
Copy Markdown
Contributor

Heads up: this is already ongoing: #709

@swissspidy swissspidy added the Type: Enhancement New feature or improvement of an existing feature label Mar 27, 2020
@wassgha
Copy link
Copy Markdown
Contributor

wassgha commented Mar 27, 2020

This should be unblocked now :))

@swissspidy
Copy link
Copy Markdown
Collaborator

@barklund Is this something you could easily bring over the finish line now that #709 has been merged?

@barklund
Copy link
Copy Markdown
Contributor Author

@barklund Is this something you could easily bring over the finish line now that #709 has been merged?

Working on it. Will be done today.

# 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}>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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}>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@barklund barklund requested a review from wassgha March 31, 2020 20:39
@dvoytenko
Copy link
Copy Markdown
Contributor

I'm already LGTM on this. So to @wassgha to do the final approval.

@wassgha wassgha merged commit b43eda9 into master Apr 1, 2020
@wassgha wassgha deleted the bug/529-layer-reorder-scroll branch April 1, 2020 07:32
const scrollTarget = useRef(null);

const setScrollTarget = useCallback(
(node) => (scrollTarget.current = node.parentElement),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This currently breaks the document tab on the right hand side ⚠️

Uncaught TypeError: Cannot read property 'parentElement' of null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@miina miina mentioned this pull request Apr 1, 2020
obetomuniz added a commit that referenced this pull request Apr 1, 2020
* 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
  ...
obetomuniz added a commit that referenced this pull request Apr 1, 2020
…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)
  ...
obetomuniz added a commit that referenced this pull request Apr 1, 2020
* 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
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Group: Editing Main editing features Type: Enhancement New feature or improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Layer panel overflow problems Layer drag-reordering doesn't auto-scroll

6 participants