MinJieLiu преди 5 години
родител
ревизия
29614ac6ac
променени са 4 файла, в които са добавени 14 реда и са изтрити 21 реда
  1. 1 1
      example/package.json
  2. 1 1
      package.json
  3. 7 6
      src/Photo.tsx
  4. 5 13
      src/PhotoView.tsx

+ 1 - 1
example/package.json

@@ -10,7 +10,7 @@
   "scripts": {
     "start": "start-storybook -p 6006",
     "build": "build-storybook",
-    "deploy-storybook": "storybook-to-ghpages"
+    "deploy": "storybook-to-ghpages"
   },
   "eslintConfig": {
     "extends": "react-app"

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "react-photo-view",
-  "version": "0.3.1",
+  "version": "0.3.2",
   "description": "React photo preview.",
   "author": "MinJieLiu",
   "license": "MIT",

+ 7 - 6
src/Photo.tsx

@@ -13,7 +13,7 @@ export interface IPhotoProps extends React.HTMLAttributes<any> {
   width: number;
   height: number;
   className?: string;
-  onPhotoResize: () => void;
+  onPhotoResize?: () => void;
   onImageLoad: (PhotoParams, callback?: Function) => void;
   loadingElement?: JSX.Element;
   brokenElement?: JSX.Element;
@@ -79,11 +79,12 @@ export default class Photo extends React.PureComponent<
   handleResize = () => {
     const { loaded, naturalWidth, naturalHeight } = this.props;
     if (loaded && this.isMount) {
-      const { onPhotoResize, onImageLoad } = this.props;
-      onImageLoad(
-        getSuitableImageSize(naturalWidth, naturalHeight),
-        onPhotoResize,
-      );
+      const { onImageLoad, onPhotoResize } = this.props;
+      onImageLoad(getSuitableImageSize(naturalWidth, naturalHeight));
+
+      if (onPhotoResize) {
+        onPhotoResize();
+      }
     }
   };
 

+ 5 - 13
src/PhotoView.tsx

@@ -143,10 +143,8 @@ export default class PhotoView extends React.Component<
     }
   }
 
-  handleImageLoad = (imageParams, callback) => {
-    this.setState({
-      ...imageParams,
-    }, callback);
+  handleImageLoad = imageParams => {
+    this.setState(imageParams);
   };
 
   handleStart = (clientX: number, clientY: number, touchLength: number = 0) => {
@@ -423,14 +421,6 @@ export default class PhotoView extends React.Component<
     this.handleUp(clientX, clientY);
   };
 
-  handleResize = () => {
-    this.setState(initialState);
-    const { onPhotoResize } = this.props;
-    if (onPhotoResize) {
-      onPhotoResize();
-    }
-  };
-
   render() {
     const {
       src,
@@ -439,6 +429,8 @@ export default class PhotoView extends React.Component<
       style,
       loadingElement,
       brokenElement,
+      onPhotoResize,
+
       showAnimateType,
       originRect,
       onShowAnimateEnd,
@@ -485,7 +477,7 @@ export default class PhotoView extends React.Component<
             onMouseDown={isMobile ? undefined : this.handleMouseDown}
             onTouchStart={isMobile ? this.handleTouchStart : undefined}
             onWheel={this.handleWheel}
-            onPhotoResize={this.handleResize}
+            onPhotoResize={onPhotoResize}
             style={{
               WebkitTransform: transform,
               transform,