diff --git a/packages/react-native-storybook/src/addToggleStorybookToDevMenu.ts b/packages/react-native-storybook/src/addStorybookToDevMenu.ts similarity index 88% rename from packages/react-native-storybook/src/addToggleStorybookToDevMenu.ts rename to packages/react-native-storybook/src/addStorybookToDevMenu.ts index b2a1a7e3..aaa254df 100644 --- a/packages/react-native-storybook/src/addToggleStorybookToDevMenu.ts +++ b/packages/react-native-storybook/src/addStorybookToDevMenu.ts @@ -9,7 +9,7 @@ try { const { SherloModule: SherloNativeModule } = NativeModules; -function addToggleStorybookToDevMenu() { +function addStorybookToDevMenu() { if (!__DEV__ || devMenuToggleInitialized) return; const MENU_LABEL = 'Toggle Storybook'; @@ -24,4 +24,4 @@ function addToggleStorybookToDevMenu() { devMenuToggleInitialized = true; } -export default addToggleStorybookToDevMenu; +export default addStorybookToDevMenu; diff --git a/packages/react-native-storybook/src/index.ts b/packages/react-native-storybook/src/index.ts index bef3164c..f02c026b 100644 --- a/packages/react-native-storybook/src/index.ts +++ b/packages/react-native-storybook/src/index.ts @@ -1,12 +1,8 @@ +export { default as addStorybookToDevMenu } from './addStorybookToDevMenu'; export { default as getStorybook } from './getStorybook'; -export { default as isRunningStorybook } from './isRunningStorybook'; export { default as isRunningVisualTests } from './isRunningVisualTests'; +export { default as isStorybookMode } from './isStorybookMode'; export { default as openStorybook } from './openStorybook'; -export { default as shouldShowStorybook } from './shouldShowStorybook'; export { default as verifyIntegration } from './verifyIntegration'; export * from './types'; - -import addToggleStorybookToDevMenu from './addToggleStorybookToDevMenu'; - -addToggleStorybookToDevMenu(); diff --git a/packages/react-native-storybook/src/isRunningStorybook.ts b/packages/react-native-storybook/src/isRunningStorybook.ts deleted file mode 100644 index f705042f..00000000 --- a/packages/react-native-storybook/src/isRunningStorybook.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { NativeModules } from 'react-native'; - -const { SherloModule } = NativeModules; - -const isRunningStorybook = ['storybook', 'testing', 'verification'].includes( - SherloModule?.getConstants().mode -); - -export default isRunningStorybook; diff --git a/packages/react-native-storybook/src/isStorybookMode.ts b/packages/react-native-storybook/src/isStorybookMode.ts new file mode 100644 index 00000000..9d8e0a53 --- /dev/null +++ b/packages/react-native-storybook/src/isStorybookMode.ts @@ -0,0 +1,17 @@ +import { NativeModules } from 'react-native'; + +const { SherloModule } = NativeModules; + +/** + * isStorybookMode determines whether Storybook should be displayed. + * + * Returns true if any of the following conditions are met: + * 1. User selected "Toggle Storybook" in Dev Menu + * 2. User called "openStorybook" function imported from "@sherlo/react-native-storybook" + * 3. Build is running tests on Sherlo + */ +const isStorybookMode = ['storybook', 'testing', 'verification'].includes( + SherloModule?.getConstants().mode +); + +export default isStorybookMode; diff --git a/packages/react-native-storybook/src/shouldShowStorybook.ts b/packages/react-native-storybook/src/shouldShowStorybook.ts deleted file mode 100644 index 44d45fad..00000000 --- a/packages/react-native-storybook/src/shouldShowStorybook.ts +++ /dev/null @@ -1,16 +0,0 @@ -import isRunningStorybook from './isRunningStorybook'; - -/** - * shouldShowStorybook determines whether to show Storybook. - * - * Returns true if any of the following conditions are met: - * 1. isStorybookBuild is true - * 2. User selected "Toggle Storybook" in Dev Menu - * 3. User called "openStorybook" function imported from "@sherlo/react-native-storybook" - * 4. Build is running tests on Sherlo - */ -const shouldShowStorybook = (isStorybookBuild?: boolean) => { - return isStorybookBuild || isRunningStorybook; -}; - -export default shouldShowStorybook; diff --git a/testing/expo-storybook-8/App.tsx b/testing/expo-storybook-8/App.tsx index 2a96d166..bb7da54b 100644 --- a/testing/expo-storybook-8/App.tsx +++ b/testing/expo-storybook-8/App.tsx @@ -1,4 +1,4 @@ -import { shouldShowStorybook } from '@sherlo/react-native-storybook'; +import { isStorybookMode } from '@sherlo/react-native-storybook'; import Storybook from './.storybook'; import { PropsWithChildren } from 'react'; import HomeScreen from './src/HomeScreen'; @@ -34,7 +34,7 @@ export default function App() { * Note: If called without parameters, like "shouldShowStorybook()", * only conditions 2, 3 and 4 apply. */ - if (shouldShowStorybook(Constants.expoConfig?.extra?.storybookEnabled)) { + if (Constants.expoConfig?.extra?.storybookEnabled || isStorybookMode) { return (