Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: custom height and iframe SecurityError #26

Merged
merged 5 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export default function Base() {
src="https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*NZuwQp_vcIQAAAAAAAAAAABkARQnAQ"
width={200}
/>

<Image
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
width={200}
height={100}
/>
</div>
);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
"np": "^6.3.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"typescript": "^4.0.2"
"typescript": "^3.9.7"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥改回来了。

Copy link
Member Author

@shaodahong shaodahong Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4.0 配合 eslint 有问题 typescript-eslint/typescript-eslint#1436

发现是 yarn 的问题,改回来了

}
}
1 change: 1 addition & 0 deletions src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const ImageInternal: React.FC<ImageProps> = ({
className: cn(`${prefixCls}-img`, {
[`${prefixCls}-img-placeholder`]: placeholder === true,
}),
style: height !== undefined ? { height } : undefined,
};

return (
Expand Down
16 changes: 11 additions & 5 deletions src/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classnames from 'classnames';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import { getOffset } from 'rc-util/lib/Dom/css';
import { warning } from 'rc-util/lib/warning';
import useFrameSetState from './hooks/useFrameSetState';
import getFixScaleEleTransPosition from './getFixScaleEleTransPosition';

Expand Down Expand Up @@ -155,11 +156,16 @@ const Preview: React.FC<PreviewProps> = props => {
const onMouseUpListener = addEventListener(window, 'mouseup', onMouseUp, false);
const onMouseMoveListener = addEventListener(window, 'mousemove', onMouseMove, false);

// Resolve if in iframe lost event
/* istanbul ignore next */
if (window.top !== window.self) {
onTopMouseUpListener = addEventListener(window.top, 'mouseup', onMouseUp, false);
onTopMouseMoveListener = addEventListener(window.top, 'mousemove', onMouseMove, false);
try {
// Resolve if in iframe lost event
/* istanbul ignore next */
if (window.top !== window.self) {
onTopMouseUpListener = addEventListener(window.top, 'mouseup', onMouseUp, false);
onTopMouseMoveListener = addEventListener(window.top, 'mousemove', onMouseMove, false);
}
} catch (error) {
/* istanbul ignore next */
warning(false, `[rc-image] ${error}`);
}

return () => {
Expand Down