Skip to content

Commit

Permalink
Merge branch 'fix-state-bleeding-in-js' of https://github.com/sherlo-…
Browse files Browse the repository at this point in the history
…io/sherlo into fix-state-bleeding-in-js
  • Loading branch information
michalziolkowski committed Nov 30, 2024
2 parents b583ac8 + fe9d9f5 commit 337b276
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ try {

const { SherloModule: SherloNativeModule } = NativeModules;

function addToggleStorybookToDevMenu() {
function addStorybookToDevMenu() {
if (!__DEV__ || devMenuToggleInitialized) return;

const MENU_LABEL = 'Toggle Storybook';
Expand All @@ -24,4 +24,4 @@ function addToggleStorybookToDevMenu() {
devMenuToggleInitialized = true;
}

export default addToggleStorybookToDevMenu;
export default addStorybookToDevMenu;
8 changes: 2 additions & 6 deletions packages/react-native-storybook/src/index.ts
Original file line number Diff line number Diff line change
@@ -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();
9 changes: 0 additions & 9 deletions packages/react-native-storybook/src/isRunningStorybook.ts

This file was deleted.

17 changes: 17 additions & 0 deletions packages/react-native-storybook/src/isStorybookMode.ts
Original file line number Diff line number Diff line change
@@ -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;
16 changes: 0 additions & 16 deletions packages/react-native-storybook/src/shouldShowStorybook.ts

This file was deleted.

4 changes: 2 additions & 2 deletions testing/expo-storybook-8/App.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 (
<CommonProviders>
<Storybook />
Expand Down

0 comments on commit 337b276

Please sign in to comment.