Skip to content

Commit df0bf5f

Browse files
committed
fix: apply initial scale on KeepScale mount
1 parent f5677c5 commit df0bf5f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/components/keep-scale/keep-scale.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@ export const KeepScale = React.forwardRef<
1111
const instance = useContext(Context);
1212

1313
useEffect(() => {
14-
return instance.onChange((ctx) => {
14+
const applyScale = (scale: number) => {
1515
if (localRef.current) {
1616
const positionX = 0;
1717
const positionY = 0;
1818
localRef.current.style.transform = instance.handleTransformStyles(
1919
positionX,
2020
positionY,
21-
1 / ctx.instance.transformState.scale,
21+
1 / scale,
2222
);
2323
}
24+
};
25+
26+
applyScale(instance.transformState.scale);
27+
28+
return instance.onChange((ctx) => {
29+
applyScale(ctx.instance.transformState.scale);
2430
});
2531
}, [instance]);
2632

0 commit comments

Comments
 (0)