Add ability to pinch to zoom in Previewer area using trackpad #1196
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
✨ Pull Request
📓 Referenced Issue
ℹ️ About the PR
It looks like there may have been some confusion in the original issue as to exactly what the functional requirements should be of this new feature. Based on your comments, my interpretation was that the user should be able to pinch-to-zoom on a trackpad in the preview area, which should zoom the devices in or out by updating the
zoomFactor
state variable.setZoomFactor
reducer and added anonWheel
event listener in thePreviewer
component. This only worked when the mouse was not hovering over awebview
element. When it was, the event listener would not fire. I did some searching through the docs and apparently "You can not add keyboard, mouse, and scroll event listeners towebview
."ipcRenderer
andipcMain
modules to communicate the zoom gesture from the WebView to the main process.zoomIn
andzoomOut
to cover the instances when the user might pinch-to-zoom and fall in-between one of the predefined zoom steps, and then later use the zoom buttons. I rewrote the reducers to find the nearest predefined step (i.e. if the user pinched-to-zoom and landed on 40%, and then later used the zoom in button, it should go up to 50%. Or if they zoomed out from 40%, it should go to 33%).renderer.individualZoomFactor
andrenderer.zoomFactor
in the Electron store are based on actual values instead of indices of the zoomSteps array. Again, because pinch-to-zoom allows "infinite" steps, I wanted to make it so that the application would remember the lastzoomFactor
even if it fell in between two pre-defined zoom steps.I do have some concerns about the performance of this feature, as pinching-to-zoom can cause hundreds of re-rerenders, which sometimes caused some visible stuttering. The only other solution I could think of was updating the scale of the
webview
tags directly through CSS using a ref, and using some kind of debouncing function to only update thezoomFactor
once the user has stopped pinching. I tested this and while it was visibly smoother, I ultimately decided against it because it required a lot more work-arounds and seemed a bit like an anti-pattern for React overall.Hopefully I haven't missed anything. I'd be happy to make any requested changes to this implementation!
(sidenote: are the devices supposed to have that white space underneath? The prod application doesn't seem to have this but running the app locally, even on the
master
branch does for me.)🖼️ Testing Scenarios / Screenshots
My.Movie.5.mp4