Skip to content

Commit

Permalink
feat: 🎸 Enabled smooth zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
prc5 committed Jun 28, 2023
1 parent 4219373 commit c0871e2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/constants/state.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export const initialSetup: LibrarySetup = {
centerZoomedOut: false,
centerOnInit: false,
disablePadding: false,
smooth: true,
wheel: {
step: 0.2,
smooth: false,
smoothStep: 0.001,
disabled: false,
smoothStep: 0.001,
wheelDisabled: false,
touchPadDisabled: false,
activationKeys: [],
Expand Down
6 changes: 4 additions & 2 deletions src/core/handlers/handlers.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export const handleCalculateButtonZoom = (
): number => {
const { scale } = contextInstance.transformState;
const { wrapperComponent, setup } = contextInstance;
const { maxScale, minScale, zoomAnimation } = setup;
const { maxScale, minScale, zoomAnimation, smooth } = setup;
const { size } = zoomAnimation;

if (!wrapperComponent) {
throw new Error("Wrapper is not mounted");
}

const targetScale = scale + delta * step;
const targetScale = smooth
? scale * Math.exp(delta * step)
: scale + delta * step;

const newScale = checkZoomBounds(
roundNumber(targetScale, 3),
Expand Down
3 changes: 2 additions & 1 deletion src/core/wheel/wheel.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ export const handleWheelZoom = (
zoomAnimation,
wheel,
disablePadding,
smooth,
} = setup;
const { size, disabled } = zoomAnimation;
const { step, smooth, smoothStep } = wheel;
const { step, smoothStep } = wheel;

if (!contentComponent) {
throw new Error("Component not mounted");
Expand Down
2 changes: 1 addition & 1 deletion src/models/context.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export type ReactZoomPanPinchProps = {
centerOnInit?: boolean;
disablePadding?: boolean;
customTransform?: (x: number, y: number, scale: number) => string;
smooth?: boolean;
wheel?: {
step?: number;
smoothStep?: number;
smooth?: boolean;
disabled?: boolean;
wheelDisabled?: boolean;
touchPadDisabled?: boolean;
Expand Down
12 changes: 6 additions & 6 deletions src/stories/docs/props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ export const wrapperPropsTable: ComponentProps = {
description:
"We can provide custom transform function to provide different way of handling our transform logic. If we need performance we can import getMatrixTransformStyles functions and replace default one. WARNING: default transform prevents svg blur on the safari.",
},
smooth: {
type: ["boolean"],
defaultValue: String(initialSetup.smooth),
description:
"Enable smooth scrolling by multiplying the scroll delta with the smooth step factor.",
},
wheel: {
wheel: {
type: [""],
Expand All @@ -182,12 +188,6 @@ export const wrapperPropsTable: ComponentProps = {
description:
"The sensitivity multiplier of zooming with the wheel/touchpad used, instead of the step value, when smooth scrolling is enabled.",
},
smooth: {
type: ["boolean"],
defaultValue: String(initialSetup.wheel.smooth),
description:
"Enable smooth scrolling by multiplying the scroll delta with the smooth step factor.",
},
disabled: {
type: ["boolean"],
defaultValue: String(initialSetup.wheel.disabled),
Expand Down
8 changes: 0 additions & 8 deletions src/stories/types/args.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ export const argsTypes = {
defaultValue: { summary: "0" },
},
},
"wheel.smooth": {
defaultValue: initialSetup.wheel.smooth,
control: { type: "boolean" },
table: {
defaultValue: { summary: "false" },
type: { summary: "boolean" },
},
},
"wheel.disabled": {
defaultValue: initialSetup.wheel.disabled,
control: { type: "boolean" },
Expand Down

0 comments on commit c0871e2

Please sign in to comment.