Unverified Commit 91220ea4 authored by Zeng1998's avatar Zeng1998 Committed by GitHub

fix: reset image state in gallery (#730)

parent 4bebbf3e
...@@ -20,14 +20,16 @@ interface State { ...@@ -20,14 +20,16 @@ interface State {
originY: number; originY: number;
} }
const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }: Props) => { const defaultState: State = {
const [currentIndex, setCurrentIndex] = useState(initialIndex);
const [state, setState] = useState<State>({
angle: 0, angle: 0,
scale: 1, scale: 1,
originX: -1, originX: -1,
originY: -1, originY: -1,
}); };
const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }: Props) => {
const [currentIndex, setCurrentIndex] = useState(initialIndex);
const [state, setState] = useState<State>(defaultState);
const handleCloseBtnClick = () => { const handleCloseBtnClick = () => {
destroy(); destroy();
...@@ -43,12 +45,14 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }: ...@@ -43,12 +45,14 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
const handleImgContainerClick = (event: React.MouseEvent) => { const handleImgContainerClick = (event: React.MouseEvent) => {
if (event.clientX < window.innerWidth / 2) { if (event.clientX < window.innerWidth / 2) {
if (currentIndex > 0) { if (currentIndex > 0) {
setState(defaultState);
setCurrentIndex(currentIndex - 1); setCurrentIndex(currentIndex - 1);
} else { } else {
destroy(); destroy();
} }
} else { } else {
if (currentIndex < imgUrls.length - 1) { if (currentIndex < imgUrls.length - 1) {
setState(defaultState);
setCurrentIndex(currentIndex + 1); setCurrentIndex(currentIndex + 1);
} else { } else {
destroy(); destroy();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment