Repository navigation
feat: pinch zoom (#84) - #198
Merged
Merged
Conversation
tbolis
force-pushed
the
feat/pinch-zoom
branch
from
October 30, 2026 08:24
f02fcf5 to
9f82f9d
Compare
Two fingers on the canvas zoom and pan its view (#84): the pinchZoom, minZoom and maxZoom properties, the onViewChange callback and resetView(). The view is the viewport of the canvas, the objects stay where they are, so it is not saved, not an undo step, and onChange is not called for it. toDataURL() draws the whole drawing, whatever the view. When the second finger comes, what the first one started is dropped: the objects it added are taken off the canvas and out of the history, the free stroke stops, and the tool forgets the press (new cancel() hook of the tools, cancel() of the eraser and laser brushes). The eraser brush follows the first finger only, as the other brushes.
The View section has the pinchZoom switch, the smallest and the largest zoom, and the view as onViewChange reports it (also the chip of the section). The reset view button is next to the zoom buttons of the canvas.
tbolis
force-pushed
the
feat/pinch-zoom
branch
from
October 30, 2026 15:45
9f82f9d to
f33dfae
Compare
…uttons The buttons scale the drawing with zoom(), which is not the view of the fingers that resetView() puts back, so on a desktop the reset did nothing. The showcase keeps the factor the buttons scaled by, and the reset scales by its inverse before it resets the view. The factor starts again when the canvas is cleared, a value is loaded, or the scenario changes.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds pinch zoom for 1.1.0 (issue #84).
The branch is rebased on
release/1.1.0, which has #197 (polygon), the arrow fixes (#200, #201) and the line style (#202). The commits here arefeat: pinch zoom, its docs, and the showcase.pinchZoomproperty (defaulttrue),minZoom(0.5) andmaxZoom(8), theonViewChange({ zoom, x, y })callback, and theresetView()method. The canvas cannot be taken out of sight: a quarter of its smaller side stays in the window.toJSON(), it is not an undo step, andonChangeis not called for it. It is notzoom(factor), which scales the objects.cancel()hook on the tools, acancel()on the eraser and laser brushes, anddiscard()on the history.pinch.ts.pinchZoomswitch, the smallest and the largest zoom, and the view asonViewChangereports it, also in the chip of the section) and a reset view button next to the zoom buttons of the canvas.Changes of behavior
toDataURL()draws the whole drawing, whatever the zoom and pan of the view. Before, the pan tool shifted what the image showed. It is in the CHANGELOG under Changed.Checks
yarn format:check,yarn lint,yarn typecheckandyarn buildpass.yarn test: 361 passing and 1 todo, on React 19 and on React 18 (27 tests for the gesture: the view, the limits, nothing saved or undone, each tool, the polygon in progress, the export, unmount). Changing the code on purpose made the tests fail in each case I tried (dropping the strokes, aborting the free stroke, the order of the handlers,onChange, the export, the polygon press).In headless Chrome, with a real two-finger gesture sent through the DevTools protocol, in the middle of a polygon: the view went to the expected zoom and pan, the vertices placed were unchanged, nothing was added to the sketch, the next tap was placed in the zoomed view, and
toDataURL()left the view as it was.The showcase, built and served, in headless Chrome with a two-finger gesture sent through the DevTools protocol: the view went from 1.00 to 4.00 and the readout and the chip showed it, the reset view button took it back to 1.00, and with the switch off the same gesture changed nothing.
Not checked: a physical touch device.
Notes for review
Fixesline of the release PR (Release v1.1.0 #196), as closing keywords do not act on a merge intorelease/1.1.0.