A react-native storybook addon to show different backgrounds for your preview
@storybook/addon-ondevice-backgrounds (deprecated)
[!WARNING] Backgrounds are built into
@storybook/react-nativeand enabled by default since v11. This package is a compatibility stub that does nothing. Remove it from your project.
What the stub does
@storybook/addon-ondevice-backgrounds/registerregisters nothing. In development it logs one warning asking you to remove the package. The built-in Backgrounds panel stays enabled, so you get exactly one panel.withBackgroundsrenders the story unchanged, so backgrounds aren't applied twice. The built-in panel applies them without a decorator.- The
Backgroundtype is still exported.
The built-in panel also reads the legacy parameters this addon used (values and default), so existing stories keep their backgrounds.
Migrating
-
Remove the addon from
deviceAddonsin.rnstorybook/main.ts:const main: StorybookConfig = { deviceAddons: [ '@storybook/addon-ondevice-notes', - '@storybook/addon-ondevice-backgrounds', ], }; -
Remove
withBackgroundsfrom your preview decorators. -
Uninstall the package:
npm uninstall @storybook/addon-ondevice-backgrounds -
Optionally move from
valuesanddefaulttooptionsandinitialGlobals, the same format Storybook web uses:// .rnstorybook/preview.tsx -import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds'; const preview: Preview = { - decorators: [withBackgrounds], parameters: { backgrounds: { - default: 'plain', - values: [ - { name: 'plain', value: 'white' }, - { name: 'dark', value: '#333' }, - ], + options: { + plain: { name: 'Plain', value: 'white' }, + dark: { name: 'Dark', value: '#333' }, + }, }, }, + initialGlobals: { + backgrounds: { value: 'plain' }, + }, };A story-level
defaultbecomesglobals: { backgrounds: { value: 'dark' } }on that story, which also locks the panel for it.
Until you migrate, legacy values are keyed by their name, and default (or the first value when there's no default) is applied while no backgrounds global is set.
To turn the built-in panel off, set features: { ondeviceBackgrounds: false } in .rnstorybook/main.ts.
See the Backgrounds guide for the full documentation.
- ndelangen
- shilman
- tmeasday
- winkervsbecks
- kylegach
- jreinhold