Skip to content

Commit

Permalink
Include the flip normalization from the core library
Browse files Browse the repository at this point in the history
  • Loading branch information
Norserium committed Aug 27, 2022
1 parent e5f24b5 commit 3bd01ee
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

---

:warning: It's the beta version. The API can be changed in the future.
:warning: It's the beta version. The API can be changed in the future. Therefore, it's recommended to fix the version with `~`.

---

Expand Down
15 changes: 3 additions & 12 deletions example/src/components/croppers/DefaultCropper/DefaultCropper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,17 @@ export const DefaultCropper = ({ wrapperClassName, className, ...props }: Defaul
};

const onRotate = (angle: number) => {
if (cropperRef.current) {
cropperRef.current.rotateImage(angle);
}
cropperRef.current?.rotateImage(angle);
};

const onFlip = (horizontal: boolean, vertical: boolean) => {
const cropper = cropperRef.current;
if (cropper) {
if (cropper.getTransforms().rotate % 180 !== 0) {
cropper.flipImage(!horizontal, !vertical);
} else {
cropper.flipImage(horizontal, vertical);
}
}
cropperRef.current?.flipImage(horizontal, vertical);
};

const onReset = () => {
const cropper = cropperRef.current;
if (cropper) {
cropper.setState(getDefaultState(cropper));
cropperRef.current?.setState(getDefaultState(cropper));
}
};
const onChange = (cropper: CropperRef) => {
Expand Down
18 changes: 3 additions & 15 deletions example/src/components/examples/RotateImageExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,11 @@ export const RotateImageExample = () => {
const cropperRef = useRef<CropperRef>(null);

const flip = (horizontal: boolean, vertical: boolean) => () => {
const cropper = cropperRef.current;
if (cropper) {
if (cropper.getTransforms().rotate % 180 !== 0) {
cropper.flipImage(!horizontal, !vertical);
} else {
cropper.flipImage(horizontal, vertical);
}
}
cropperRef.current?.flipImage(horizontal, vertical);
};

const rotate = (angle: number) => () => {
const cropper = cropperRef.current;
if (cropper) {
cropper.rotateImage(angle);
}
cropperRef.current?.rotateImage(angle);
};

const download = () => {
Expand All @@ -46,9 +36,7 @@ export const RotateImageExample = () => {
<Cropper
ref={cropperRef}
className={'rotate-image-example__cropper'}
src={
'/react-advanced-cropper/img/images/photo-1600353068867-5b4de71e3afb.jpg'
}
src={'/react-advanced-cropper/img/images/photo-1600353068867-5b4de71e3afb.jpg'}
/>
<VerticalButtons>
<SquareButton title="Flip Horizontal" onClick={flip(true, false)}>
Expand Down
24 changes: 16 additions & 8 deletions example/src/components/showcase/Telegram/components/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { forwardRef, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';
import { ImmediatelyOptions, InteractionOptions, TransitionOptions } from 'advanced-cropper';
import { ImmediatelyOptions, InteractionOptions, NormalizeOptions, TransitionOptions } from 'advanced-cropper';
import cn from 'classnames';
import { FlipHorizontalIcon } from '../icons/FlipHorizontalIcon';
import { RotateRightIcon } from '../icons/RotateRightIcon';
Expand All @@ -26,7 +26,7 @@ interface NavigationProps extends PublicNavigationProps {
onFlip?: (
horizontal: boolean,
vertical?: boolean,
options?: TransitionOptions & InteractionOptions & ImmediatelyOptions,
options?: TransitionOptions & InteractionOptions & ImmediatelyOptions & NormalizeOptions,
) => void;
className?: string;
disabled?: unknown;
Expand Down Expand Up @@ -122,16 +122,24 @@ export const Navigation = forwardRef<NavigationRef, NavigationProps>(
}
};

const flipHorizontal = () => {
if (onFlip && !disabled) {
onFlip(true);
const flip = (horizontal: boolean, vertical: boolean) => {
if (quarter % 2 === 0) {
onFlip?.(horizontal, vertical, {
normalize: false,
});
} else {
onFlip?.(vertical, horizontal, {
normalize: false,
});
}
};

const flipHorizontal = () => {
flip(true, false);
};

const flipVertical = () => {
if (onFlip && !disabled) {
onFlip(false, true);
}
flip(false, true);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-advanced-cropper",
"version": "0.10.5",
"version": "0.11.0",
"description": "The react cropper library that gives the possibility to create croppers exactly suited for your website design",
"author": "Norserium",
"license": "MIT",
Expand Down Expand Up @@ -78,7 +78,7 @@
"dist"
],
"dependencies": {
"advanced-cropper": "~0.10.3",
"advanced-cropper": "~0.11.0",
"classnames": "^2.2.6",
"tslib": "^2.4.0"
},
Expand Down

0 comments on commit 3bd01ee

Please sign in to comment.