Skip to content

Commit 18138c5

Browse files
committed
fix: Fix noScroll props issue.
1 parent 5f2178d commit 18138c5

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/index.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ const CodePreview = React.forwardRef<CodePreviewRef, CodePreviewProps>((props, r
104104
const {
105105
playerId,
106106
setDemoDom,
107-
initHeight,
108107
code,
109108
setCode,
110109
fullScreen,
@@ -148,6 +147,22 @@ const CodePreview = React.forwardRef<CodePreviewRef, CodePreviewProps>((props, r
148147
);
149148
// eslint-disable-next-line react-hooks/exhaustive-deps
150149
}, []);
150+
151+
const transitionend = () => setShowEdit(width !== 1);
152+
153+
useEffect(() => {
154+
const dom = demoRef.current;
155+
if (dom) {
156+
dom.addEventListener('transitionend', transitionend);
157+
}
158+
return () => {
159+
if (dom) {
160+
dom.removeEventListener('transitionend', transitionend);
161+
}
162+
};
163+
// eslint-disable-next-line react-hooks/exhaustive-deps
164+
}, [width]);
165+
151166
const handleChange = (value: string, viewUpdate: ViewUpdate) => {
152167
setCode(value);
153168
if (editProps && editProps.onChange) {
@@ -170,12 +185,7 @@ const CodePreview = React.forwardRef<CodePreviewRef, CodePreviewProps>((props, r
170185
}
171186
};
172187
return (
173-
<Split
174-
visiable={visiable}
175-
className={cls}
176-
style={{ flex: 1, ...style, height: width === 1 ? initHeight : '' }}
177-
{...otherProps}
178-
>
188+
<Split visiable={visiable} className={cls} style={{ flex: 1, ...style }} {...otherProps}>
179189
{!noPreview && !onlyEdit && (
180190
<div
181191
className={[

src/useCodePreview.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { babelTransform } from './transform';
55
import { CodePreviewProps } from './';
66

77
export function useCodePreview(props: CodePreviewProps) {
8-
const [initHeight, setInitHeight] = useState<number>();
98
const [demoDom, setDemoDom] = useState<HTMLDivElement>();
109
const playerId = useRef(`${parseInt(String(Math.random() * 1e9), 10).toString(36)}`);
1110
const [fullScreen, setFullScreen] = useState(false);
@@ -39,9 +38,6 @@ export function useCodePreview(props: CodePreviewProps) {
3938
// eslint-disable-next-line no-new-func
4039
new Function(...args).apply(null, argv);
4140
setErrorMessage('');
42-
if (demoDom && !initHeight) {
43-
setInitHeight(demoDom.clientHeight);
44-
}
4541
} catch (err: any) {
4642
let message = '';
4743
if (err && err.message) {
@@ -58,8 +54,6 @@ export function useCodePreview(props: CodePreviewProps) {
5854
playerId,
5955
demoDom,
6056
setDemoDom,
61-
initHeight,
62-
setInitHeight,
6357
fullScreen,
6458
setFullScreen,
6559
errorMessage,

0 commit comments

Comments
 (0)