Browse Source

fix: resize 闪烁的问题

MinJieLiu 5 years ago
parent
commit
cd0c9eae83
3 changed files with 4 additions and 5 deletions
  1. 2 2
      src/PhotoConsumer.tsx
  2. 1 2
      src/PhotoSlider.tsx
  3. 1 1
      src/components/SlideWrap.tsx

+ 2 - 2
src/PhotoConsumer.tsx

@@ -11,7 +11,7 @@ export interface IPhotoConsumer {
 
 const PhotoConsumer: React.FC<IPhotoConsumer> = ({ src, intro, children }) => {
   const photoContext = React.useContext<PhotoContextType>(PhotoContext);
-  const key = React.useMemo<string>(() => uniqueId(), [] as readonly []);
+  const key = React.useMemo<string>(() => uniqueId(), []);
   const [position, updatePosition] = React.useState<{
     clientX: number | undefined;
     clientY: number | undefined;
@@ -31,7 +31,7 @@ const PhotoConsumer: React.FC<IPhotoConsumer> = ({ src, intro, children }) => {
     return () => {
       photoContext.removeItem(key);
     };
-  }, [] as readonly []);
+  }, []);
 
   function handleTouchStart(e) {
     const { clientX, clientY } = e.touches[0];

+ 1 - 2
src/PhotoSlider.tsx

@@ -1,6 +1,5 @@
 import React from 'react';
 import classNames from 'classnames';
-import debounce from 'lodash.debounce';
 import PhotoView from './PhotoView';
 import SlideWrap from './components/SlideWrap';
 import VisibleAnimationHandle from './components/VisibleAnimationHandle';
@@ -85,7 +84,6 @@ export default class PhotoSlider extends React.Component<IPhotoSliderProps, Phot
       overlayVisible: true,
       canPullClose: true,
     };
-    this.handleResize = debounce(this.handleResize, 32);
   }
 
   componentDidMount() {
@@ -137,6 +135,7 @@ export default class PhotoSlider extends React.Component<IPhotoSliderProps, Phot
         translateX: -(innerWidth + horizontalOffset) * photoIndex,
         lastClientX: undefined,
         lastClientY: undefined,
+        shouldTransition: false,
       };
     });
   };

+ 1 - 1
src/components/SlideWrap.tsx

@@ -18,7 +18,7 @@ const SlideWrap: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({ className,
       // 清除容器
       document.body.removeChild(dialogNode.current);
     };
-  }, [] as readonly []);
+  }, []);
 
   return createPortal(
     <div className={classNames('PhotoView-SlideWrap', className)} {...restProps}>