diff --git a/examples/android-material-ui/.storybook/main.js b/examples/android-material-ui/.storybook/main.js index 122c5f0c..dd3d6d2c 100644 --- a/examples/android-material-ui/.storybook/main.js +++ b/examples/android-material-ui/.storybook/main.js @@ -1,10 +1,10 @@ -import { nativePreviewHead } from "@storybook/native/dist/previewHeader"; +import { nativePreviewHead } from "@storybook/native"; -const config = { +const config = { stories: ["../stories/*.stories.jsx"], framework: { name: "@storybook/react-webpack5", - options: {}, + options: {} }, addons: [ "@storybook/addon-docs", @@ -14,8 +14,7 @@ const config = { docs: { autodocs: true }, - previewHead: nativePreviewHead, - + previewHead: nativePreviewHead }; export default config; diff --git a/examples/cross-platform/.storybook/main.js b/examples/cross-platform/.storybook/main.js index 4bcac6d3..724e9760 100644 --- a/examples/cross-platform/.storybook/main.js +++ b/examples/cross-platform/.storybook/main.js @@ -1,8 +1,12 @@ -const config = { - stories: [{ directory: '../src', files: '**/*.stories.@(mdx|tsx|ts|jsx|js)' }], +import { nativePreviewHead } from "@storybook/native"; + +const config = { + stories: [ + { directory: "../src", files: "**/*.stories.@(mdx|tsx|ts|jsx|js)" } + ], framework: { name: "@storybook/react-webpack5", - options: {}, + options: {} }, addons: [ "@storybook/addon-docs", @@ -11,7 +15,8 @@ const config = { ], docs: { autodocs: true - } + }, + previewHead: nativePreviewHead }; export default config; diff --git a/examples/cross-platform/src/android.stories.jsx b/examples/cross-platform/src/android.stories.jsx index 70402811..c7d65d3d 100644 --- a/examples/cross-platform/src/android.stories.jsx +++ b/examples/cross-platform/src/android.stories.jsx @@ -1,10 +1,10 @@ import React from "react"; import rgbHex from "rgb-hex"; -import { DeepLinkRenderer } from "@storybook/native-components"; +import { EmulatorRenderer } from "@storybook/native-components"; const AndroidRenderer = ({ extraParams, component }) => { return ( - { return ( - { const IosRenderer = ({ extraParams, component }) => { return ( - { return ( - { +const appetizeSessionMap = new Map(); + +const WithStore = (props: DeepLinkRendererProps): React.ReactElement => { const dispatch = useAppDispatch(); const networkLogs = useNetworkLogs(); const logs = useLogs(); const [session, setSession] = React.useState(); + const sessionKey = props.context ?? props.platform; useEffect(() => { if (!window.appetize) { addons.getChannel().emit(EmulatorEvents.onMissingClient, null); return; } - window.appetize.getClient("#appetize-iframe").then((client: Client) => { + + if (sessionKey && appetizeSessionMap.has(sessionKey)) { + setSession(appetizeSessionMap.get(sessionKey)); + resetNetworkLogs(dispatch); + addons.getChannel().emit(EmulatorEvents.onRestNetworkLogs); + return; + } + + const frameId = `#appetize-iframe${ + props.context ? `-${props.context}` : "" + }`; + window.appetize.getClient(frameId).then((client: Client) => { addons.getChannel().emit(EmulatorEvents.onClient, client); + client.on("error", (error: string) => { + console.error(error); + appetizeSessionMap.delete(sessionKey); + }); + client.on("session", (newSession: Session) => { + if (sessionKey) appetizeSessionMap.set(sessionKey, newSession); setSession(newSession); resetNetworkLogs(dispatch); addons.getChannel().emit(EmulatorEvents.onRestNetworkLogs); @@ -52,7 +72,7 @@ const WithStore = (props: RendererProps): React.ReactElement => { addons.getChannel().emit(EmulatorEvents.onSession, session); }); }); - }, [networkLogs, logs]); + }, [networkLogs, logs, props.context]); return ( <> @@ -64,7 +84,7 @@ const WithStore = (props: RendererProps): React.ReactElement => { ); }; -export default (props: RendererProps): React.ReactElement => { +export default (props: DeepLinkRendererProps): React.ReactElement => { return (