diff --git a/apps/example/.storybook/storybook.requires.ts b/apps/example/.storybook/storybook.requires.ts index 2a90ed6..5e57996 100644 --- a/apps/example/.storybook/storybook.requires.ts +++ b/apps/example/.storybook/storybook.requires.ts @@ -1,6 +1,10 @@ /* do not change this file, it is auto generated by storybook. */ -import { start } from "@storybook/react-native"; +import { + start, + prepareStories, + getProjectAnnotations, +} from "@storybook/react-native"; import "@storybook/addon-ondevice-controls/register"; import "@storybook/addon-ondevice-actions/register"; @@ -34,14 +38,37 @@ const normalizedStories = [ }, ]; -// @ts-ignore +declare global { + var view: ReturnType; + var STORIES: typeof normalizedStories; +} + +const annotations = [ + require("./preview"), + require("@storybook/react-native/dist/preview"), + require("@storybook/addon-actions/preview"), +]; + global.STORIES = normalizedStories; -export const view = start({ - annotations: [ - require("./preview"), - require("@storybook/react-native/dist/preview"), - require("@storybook/addon-actions/preview"), - ], - storyEntries: normalizedStories, -}); +// @ts-ignore +module?.hot?.accept?.(); + +if (!global.view) { + global.view = start({ + annotations, + storyEntries: normalizedStories, + }); +} else { + const { importMap } = prepareStories({ storyEntries: normalizedStories }); + + global.view._preview.onStoriesChanged({ + importFn: async (importPath: string) => importMap[importPath], + }); + + global.view._preview.onGetProjectAnnotationsChanged({ + getProjectAnnotations: getProjectAnnotations(global.view, annotations), + }); +} + +export const view = global.view; diff --git a/apps/example/package.json b/apps/example/package.json index a6ba395..ba8cb5f 100644 --- a/apps/example/package.json +++ b/apps/example/package.json @@ -31,9 +31,9 @@ "@react-native-async-storage/async-storage": "^1.21.0", "@react-native-community/datetimepicker": "^7.6.2", "@react-native-community/slider": "^4.5.0", - "@storybook/addon-ondevice-actions": "^7.6.15", - "@storybook/addon-ondevice-controls": "^7.6.15", - "@storybook/react-native": "^7.6.15", + "@storybook/addon-ondevice-actions": "^7.6.17", + "@storybook/addon-ondevice-controls": "^7.6.17", + "@storybook/react-native": "^7.6.17", "@types/react": "~18.2.45", "babel-loader": "^8.3.0", "eslint": "^8.56.0", diff --git a/bun.lockb b/bun.lockb index 0c7011e..c130e68 100755 Binary files a/bun.lockb and b/bun.lockb differ