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

Scrollwheel support for the image editor #2563

Closed
wants to merge 2 commits into from

Conversation

wassgha
Copy link
Contributor

@wassgha wassgha commented Jun 17, 2020

Summary

Zoom in/out of the image/video using the scroll wheel

User-facing changes

User now has the ability to use the scroll wheel to zoom in/out while editing an image or a video

Testing Instructions

  1. Insert an image into the canvas
  2. Double click the element to enter edit mode
  3. Use the scroll wheel / trackpad gesture to zoom in and out

Fixes #1427

@codecov
Copy link

codecov bot commented Jun 17, 2020

Codecov Report

Merging #2563 into master will decrease coverage by 1.92%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2563      +/-   ##
============================================
- Coverage     68.28%   66.35%   -1.93%     
============================================
  Files            23      689     +666     
  Lines          1545    11815   +10270     
============================================
+ Hits           1055     7840    +6785     
- Misses          490     3975    +3485     
Impacted Files Coverage Δ Complexity Δ
assets/src/edit-story/elements/media/edit.js 20.00% <0.00%> (ø) 0.00 <0.00> (?)
includes/Story_Post_Type.php 56.96% <0.00%> (-7.70%) 0.00% <0.00%> (-32.00%)
includes/Story_Renderer.php 86.36% <0.00%> (-3.81%) 0.00% <0.00%> (-17.00%)
includes/Media.php 84.04% <0.00%> (-3.67%) 0.00% <0.00%> (-29.00%)
includes/Dashboard.php 68.29% <0.00%> (-2.36%) 0.00% <0.00%> (-14.00%)
includes/Database_Upgrader.php 92.75% <0.00%> (-0.58%) 0.00% <0.00%> (-25.00%)
includes/REST_API/Fonts_Controller.php 45.97% <0.00%> (-0.54%) 0.00% <0.00%> (-28.00%)
includes/Embed_Block.php 98.21% <0.00%> (-0.30%) 0.00% <0.00%> (-16.00%)
includes/REST_API/Link_Controller.php 93.24% <0.00%> (-0.10%) 0.00% <0.00%> (-26.00%)
includes/namespace.php 0.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
... and 670 more

@github-actions
Copy link
Contributor

github-actions bot commented Jun 17, 2020

Size Change: +27.8 kB (3%)

Total Size: 871 kB

Filename Size Change
assets/js/edit-story.js 387 kB +10.3 kB (2%)
assets/js/stories-dashboard.js 467 kB +17.5 kB (3%)
assets/js/web-stories-embed-block.js 15.7 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size Change
assets/css/edit-story.css 269 B 0 B
assets/css/stories-dashboard.css 305 B 0 B
assets/css/web-stories-embed-block.css 515 B 0 B

compressed-size-action

return (
<Element>
<Element ref={editElementRef}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the event listener should work on the faded media. Otherwise, the user would always have to scroll within the visibly displayed part of the media only. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this behavior but that required removing point-events: none on the faded image in order to be able to capture the wheel event. This in turn caused the clicks on the faded image to be captured (and thus it broke closing the editor by clicking on the faded part) so I added a click event that clears editing when the faded part is clicked. Please review that behavior to make sure there are no other repercussions from removing pointer-events: none.

@wassgha wassgha requested review from dvoytenko and miina June 25, 2020 17:41
@@ -120,6 +126,7 @@ function MediaEdit({ element, box }) {
ref: setFullMedia,
draggable: false,
opacity: opacity / 100,
onClick: clearEditing,
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried just now and I see it currently already cancels editing when clicked on faded part. Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment on @miina 's review, this is now needed because I removed pointer-events: none in order to be able to capture the wheel event on the faded part

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@wassgha This might now conflict with #1192 though now -- based on Sam's comment, the whole image area should be draggable (including the faded part). Thoughts?

@@ -134,8 +141,35 @@ function MediaEdit({ element, box }) {

const isImage = 'image' === type;
const isVideo = 'video' === type;

const wheelHandler = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just inline into useEffect

setProperties({ scale: newScale });
evt.preventDefault();
},
[setProperties, scale]
Copy link
Contributor

Choose a reason for hiding this comment

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

So, this will be refreshing the callback and by extent rerun useEffect on each event including readding event handlers? I think this could be a lot more efficient. E.g. we can inline wheelHandler inside the useEffect and instead of depending on scale, we can simply use setProperties(function()) that would update scale w/o depending on the current scale value.

@swissspidy swissspidy changed the base branch from master to main July 20, 2020 10:22
@swissspidy swissspidy added the Status: Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Aug 15, 2020
@swissspidy swissspidy closed this Sep 22, 2020
@swissspidy swissspidy deleted the image-editor/scroll-wheel branch September 22, 2020 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Gives the original author opportunity to update before closing. Can be reopened as needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scroll wheel in edit mode does not zoom the image/video
5 participants