Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
MinJieLiu committed Apr 25, 2020
1 parent 05835dd commit e24a9f3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-photo-view",
"version": "0.4.4",
"version": "0.4.5",
"description": "一款精致的 React 的图片预览组件",
"author": "MinJieLiu",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions src/PhotoSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import debounce from 'lodash.debounce';
import PhotoView from './PhotoView';
import SlideWrap from './components/SlideWrap';
import VisibleAnimationHandle from './components/VisibleAnimationHandle';
import CloseSVG from './components/CloseSVG';
import Close from './components/Close';
import ArrowLeft from './components/ArrowLeft';
import ArrowRight from './components/ArrowRight';
import isTouchDevice from './utils/isTouchDevice';
Expand Down Expand Up @@ -169,7 +169,7 @@ export default class PhotoSlider extends React.Component<IPhotoSliderProps, Phot
};
}
const offsetClientY = Math.abs(clientY - lastClientY);
const opacity = Math.max(Math.min(defaultOpacity, defaultOpacity - offsetClientY / 100 / 2), 0);
const opacity = Math.max(Math.min(defaultOpacity, defaultOpacity - offsetClientY / 100 / 4), 0);
return {
touched: true,
lastClientY,
Expand Down Expand Up @@ -354,7 +354,7 @@ export default class PhotoSlider extends React.Component<IPhotoSliderProps, Phot
{photoIndex + 1} / {imageLength}
</div>
<div className="PhotoView-PhotoSlider__BannerRight">
<CloseSVG className="PhotoView-PhotoSlider__Close" onClick={this.handleClose} />
<Close className="PhotoView-PhotoSlider__Close" onClick={this.handleClose} />
</div>
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/CloseSVG.tsx → src/components/Close.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

function CloseSVG(props) {
function Close(props) {
return (
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="44" height="44" viewBox="0 0 768 768" {...props}>
<path
Expand All @@ -11,4 +11,4 @@ function CloseSVG(props) {
);
}

export default CloseSVG;
export default Close;
13 changes: 4 additions & 9 deletions src/components/SlideWrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,27 @@ import classNames from 'classnames';
import './SlideWrap.less';

const SlideWrap: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({ className, children, ...restProps }) => {
const dialogNode = React.useMemo(() => {
// 容器
const dialogNode = document.createElement('section');
document.body.appendChild(dialogNode);
return dialogNode;
}, [] as readonly []);
const dialogNode = React.useRef<HTMLElement>(document.createElement('section'));
const originalOverflowCallback = React.useRef('');

React.useEffect(() => {
document.body.appendChild(dialogNode.current);
const { style } = document.body;
originalOverflowCallback.current = style.overflow;
style.overflow = 'hidden';

return () => {
const { style } = document.body;
style.overflow = originalOverflowCallback.current;
// 清除容器
document.body.removeChild(dialogNode);
document.body.removeChild(dialogNode.current);
};
}, [] as readonly []);

return createPortal(
<div className={classNames('PhotoView-SlideWrap', className)} {...restProps}>
{children}
</div>,
dialogNode,
dialogNode.current,
);
};

Expand Down
10 changes: 9 additions & 1 deletion src/utils/correctSuitablePosition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/**
* 纠正缩放后偏离中心区域位置
*/
export default function correctSuitablePosition({ x, y, scale }: { x: number; y: number; scale: number }) {
export default function correctSuitablePosition({
x,
y,
scale,
}: {
x: number;
y: number;
scale: number;
}): { x: number; y: number } {
if (scale <= 1) {
return {
x: 0,
Expand Down

0 comments on commit e24a9f3

Please sign in to comment.