Skip to content

Commit 0d9dbca

Browse files
committed
fix: enhancers to work for a list
1 parent 4333d26 commit 0d9dbca

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

examples/expo-example/.storybook/preview.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { View, Appearance } from 'react-native';
32
import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
43
import type { Preview } from '@storybook/react';

packages/react-native/scripts/generate.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,26 @@ function generate({ configPath, absolute = false, useJs = false }) {
4848

4949
const registerAddons = main.addons?.map((addon) => `import "${addon}/register";`).join('\n');
5050

51-
const doctools = 'require("@storybook/react-native/dist/preview")';
51+
const docTools = 'require("@storybook/react-native/dist/preview")';
5252

53-
const enhancer = [];
53+
const enhancers = [docTools];
5454

55-
main.addons?.forEach((addon) => {
55+
for (const addon of main.addons) {
5656
let addonPath;
5757
try {
5858
addonPath = path.dirname(require.resolve(addon));
5959
} catch (error) {
6060
console.error(`Failed to resolve addon: ${addon}`, error);
61+
6162
return null; // Skip this addon if it cannot be resolved
6263
}
64+
6365
const isPreviewFileExists = getPreviewExists({ configPath: addonPath });
66+
6467
if (isPreviewFileExists) {
65-
enhancer.push(`require('${addon}/preview')`);
68+
enhancers.push(`require('${addon}/preview')`);
6669
}
67-
});
70+
}
6871

6972
let options = '';
7073
let optionsVar = '';
@@ -77,7 +80,11 @@ function generate({ configPath, absolute = false, useJs = false }) {
7780

7881
const previewExists = getPreviewExists({ configPath });
7982

80-
const annotations = `[${previewExists ? "require('./preview')," : ''}${doctools}, ${enhancer}]`;
83+
if (previewExists) {
84+
enhancers.unshift("require('./preview')");
85+
}
86+
87+
const annotations = `[${enhancers.join(', ')}]`;
8188

8289
const globalTypes = `
8390
declare global {

0 commit comments

Comments
 (0)