* Reducing the size of the ui. * Addon scrollview with addon names * Updated style, shows addons list with loaded addons. * Updated status bar, so content would not be drawn below it on android. * Added some addons to example. * Moved out of state * Fixed event on android. * Temporary disabled yellow box. * Adding two options for storybook ui: isUIOpen - whether to initially show top bar - default true. isStoryMenuOpen - should show story menu open by default - default false. * Creating rn-addons.js file inside generators. * Removed separate addon store. * Using active prop. * Rewrote addons wrapper without using modal. We cannot use modal since addons expect to be rendered all the time. So now we display the wrapper as position absolute and make it 0 0 size when it is not visible. * Fixing yellow box warnings. * Addon window by default is scrollable. * Removed yellow box disabling, cleared up example index. * Reverted accidentally deleted line. * Updated dependencies. * Dependency bump * Updated UI. Removed modal, displaying menus as panels appearing from sides. * Clearing up the style a little bit. * Temporary disabling some examples * Updating the readmes. * Updating the readme. * Added notes addon that support rn * Updated addon documentation regarding setTimeout. * Fixed proptypes issue, properly set initial tab from the props. * Reduced the amount of rerenders, if you use onDeviceUI it only listens to story change events once instead of twice. * Adding more addons. * OnDeviceUI is now set to true by default. * Updated the notes addon so it renders markdown properly. * Fixes endless cycle when initially rendering when both onDeviceUI and server are enabled. * Selection prop is not required ( it is not set when not using onDeviceUI). * Renamed rn-notes to ondevice-notes addon. * Added option to use channels as async. * Using async channel if onDeviceUI is set to true. * Updated notes documentation/tests. * Adding backgrounds addon. * Updated notes readme. * Adding ondevice knobs addon. * Updated example * Reverted accidental merge issue. * Updating documentation. * Fixed knobs entry file. * Updating documentation. * Updating documentation. * Removed packager completely. * Updated cli. * Added missing dependency. * Websocket doesn't throw red screen on connection fail anymore. * Takes children from props instead out of state.. * Fixed bug where selecting story didn't actually select it. * Removed ondeviceUI in example. * If it fails to connect it selects initial story. * Knobs are properly reset on change. * Proper import in example * Reverts to localhost if no host is defined. * Ui doesnt jump when hiding bottom bar, should handle keyboard correctly on ios. * Updated background addon to unregister on unmount. * Properly handles animations on android. * Creates channel as soon as getStorybookUI is called instead of during the render. * Displays message if no addons are loaded. * setOptions called without timeout. * Sets initial story if connection to websocket server fail. * Updating style. * Removed margin bottom. * Added swiping on the nav bar, touching preview maximizes it. * Fixed keyboard aware view. * Fixed background panel so it doesn't lose color immediately. * Uses preview width for panels. * Moving class inside preview. * All react native installations receive same template. * Removed react_native fixture. * Fixing lint. * Lint fix. * Improving performance dramatically. * Adding on device addons. * Reverted back fixtures change. * Reverting file change * Updating readmes. * Updated readme about server. * Reverted yarn.lock * Fixing propTypes. * Splitting out onDeviceUI/index to smaller components. * Splitting up onDeviceUI. * Removed unused dependency. * Properly uses whole screen for preview. * Updated visibility button. * Few code review fixes Updated readme, Renamed handlers. * Fixed where width is taken from.
Storybook for React Native
With Storybook for React Native you can design and develop individual React Native components without running your app.
For more information visit: storybook.js.org
Getting Started
The storybook
CLI tool can be used to add Storybook to your React Native app. Install the storybook
tool if necessary and run it from your project directory with these commands:
npm -g i @storybook/cli
storybook init
The next thing you need to do is make Storybook UI visible in your app.
CRNA, React Native vanilla
The easiest way to use Storybook is to simply replace your App with the Storybook UI, which is possible by replacing App.js
with a single line of code:
export default from './storybook';
This will get you up and running quickly, but then you lose your app! There are multiple options here. for example, you can export conditionally:
import StorybookUI from './storybook';
import App from './app';
module.exports = __DEV__ ? StorybookUI : App;
React Native Navigation, other complex use cases
StorybookUI
is simply a RN View
component that can be embedded anywhere in your RN application, e.g. on a tab or within an admin screen.
Start Storybook server (optional)
If you want to control storybook from browser/VS Code/websockets you need to start the server. After initial setup start the storybook server with the storybook npm script.
npm run storybook
Now, you can open http://localhost:7007 to view your storybook menus in the browser.
Old standalone behaviour
Since storybook version v4.0 packager is removed from storybook. The suggested storybook usage is to include it inside your app. If you want to keep the old behaviour, you have to start the packager yourself with a different project root.
npm run storybook start -p 7007 | react-native start --projectRoot storybook
Start App
To see your Storybook stories on the device, you should start your mobile app for the <platform>
of your choice (typically ios
or android
). (Note that due to an implementation detail, your stories will only show up in the left pane of your browser window after your device has connected to this storybook server.)
For CRNA apps:
npm run <platform>
For RN apps:
react-native run-<platform>
Once your app is started, changing the selected story in web browser will update the story displayed within your mobile app.
If you are using Android and you get the following error after running the app: 'websocket: connection error', 'Failed to connect to localhost/127.0.0.1:7007'
, you have to forward the port 7007 on your device/emulator to port 7007 on your local machine with the following command:
adb reverse tcp:7007 tcp:7007
Start Command Parameters
The following parameters can be passed to the start command:
-h, --host <host>
host to listen on
-p, --port <port>
port to listen on
-s, --secured
whether server is running on https
-c, --config-dir [dir-name]
storybook config directory
-e, --environment [environment]
DEVELOPMENT/PRODUCTION environment for webpack
-i, --manual-id
allow multiple users to work with same storybook
--smoke-test
Exit after successful start
getStorybookUI Options
You can pass these parameters to getStorybookUI call in your storybook entry point:
{
onDeviceUI: Boolean (true)
-- display navigator and addons on the device
disableWebsockets: Boolean (false)
-- allows to display stories without running storybook server. Should be used with onDeviceUI
secured: Boolean (false)
-- use wss/https instead of ws/http
host: String (NativeModules.SourceCode.scriptURL)
-- host to use
port: Number (7007)
-- port to use
query: String ("")
-- additional query string to pass to websockets
isUIHidden: Boolean (false)
-- should the ui be closed initialy.
tabOpen: Number (0)
-- which tab should be open. -1 Navigator, 0 Preview, 1 Addons
}
Learn More
Check the docs
directory in this repo for more advanced setup guides and other info.