Skip to content

Commit 4b9942e

Browse files
committed
feat: clear preview to show the main app
1 parent d9d380b commit 4b9942e

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/react-native/preview-host.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ export const PreviewHost = (props: PreviewHostProps): JSX.Element => {
3131
}
3232
);
3333

34+
const removePreviewClearListener = client.onMessage(
35+
"preview-clear",
36+
() => {
37+
setPreviewName(null);
38+
setComponent(null);
39+
}
40+
);
41+
3442
return () => {
3543
removePreviewSelectListener.remove();
44+
removePreviewClearListener.remove();
3645
};
3746
}, [client]);
3847

src/shared/messaging.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Preview } from "./types";
33

44
export type PreviewPluginEventMap = {
55
"request-initial-data": unknown;
6+
"preview-clear": unknown;
67
"preview-list": Preview[];
78
"preview-added": Preview;
89
"preview-select": {

src/ui/preview-panel.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export default function PreviewPanel() {
4848
client.send("preview-select", { name });
4949
};
5050

51+
const showMainApp = () => {
52+
if (!client) return;
53+
54+
client.send("preview-clear", {});
55+
};
56+
5157
return (
5258
<div className="preview-panel">
5359
<div className="preview-container">
@@ -61,6 +67,25 @@ export default function PreviewPanel() {
6167
<h1>Preview Panel</h1>
6268
<p>Select your component to open the preview on the simulator</p>
6369
</div>
70+
<button
71+
className="show-main-app-btn"
72+
onClick={showMainApp}
73+
title="Show Main App"
74+
style={{
75+
marginLeft: 'auto',
76+
padding: '6px 14px',
77+
borderRadius: '6px',
78+
border: 'none',
79+
background: '#2d72d9',
80+
color: 'white',
81+
fontWeight: 500,
82+
cursor: 'pointer',
83+
fontSize: '0.95em',
84+
boxShadow: '0 1px 3px rgba(0,0,0,0.04)'
85+
}}
86+
>
87+
Show Main App
88+
</button>
6489
</div>
6590
</div>
6691

0 commit comments

Comments
 (0)