@storybook/react-native 6.0.1-alpha.5 → 6.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@
3
3
  import { StoryApi } from '@storybook/addons';
4
4
  import { ClientApi } from '@storybook/client-api';
5
5
  import { ReactNode } from 'react';
6
+ import Preview from './preview';
7
+ export declare const preview: Preview;
6
8
  export declare const setAddon: ClientApi['setAddon'];
7
9
  export declare const addDecorator: ClientApi['addDecorator'];
8
10
  export declare const addParameters: ClientApi['addParameters'];
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Preview from './preview';
2
- const preview = new Preview();
2
+ export const preview = new Preview();
3
3
  const rawStoriesOf = preview.api().storiesOf.bind(preview);
4
4
  export const setAddon = preview.api().setAddon.bind(preview);
5
5
  export const addDecorator = preview.api().addDecorator.bind(preview);
@@ -25,7 +25,7 @@ export default class Preview {
25
25
  return this._clientApi;
26
26
  };
27
27
  this.getStorybookUI = (params = {}) => {
28
- const { initialSelection, shouldPersistSelection } = params;
28
+ const { initialSelection, shouldPersistSelection = true } = params;
29
29
  this._setInitialStory(initialSelection, shouldPersistSelection);
30
30
  this._channel.on(Events.SET_CURRENT_STORY, (d) => {
31
31
  this._selectStoryEvent(d, shouldPersistSelection);
@@ -11,12 +11,14 @@ import { getAddonPanelPosition, getNavigatorPanelPosition, getPreviewPosition, g
11
11
  import Navigation from './navigation';
12
12
  import { PREVIEW, ADDONS } from './navigation/constants';
13
13
  import Panel from './Panel';
14
+ import { useWindowDimensions } from 'react-native';
14
15
  const ANIMATION_DURATION = 300;
15
16
  const IS_IOS = Platform.OS === 'ios';
16
17
  // @ts-ignore: Property 'Expo' does not exist on type 'Global'
17
18
  const getExpoRoot = () => global.Expo || global.__expo || global.__exponent;
18
19
  export const IS_EXPO = getExpoRoot() !== undefined;
19
20
  const IS_ANDROID = Platform.OS === 'android';
21
+ const BREAKPOINT = 1024;
20
22
  const flex = { flex: 1 };
21
23
  const Preview = styled.View(flex, ({ disabled, theme }) => ({
22
24
  borderLeftWidth: disabled ? 0 : 1,
@@ -62,6 +64,7 @@ const OnDeviceUI = ({ storyStore, isUIHidden, shouldDisableKeyboardAvoidingView,
62
64
  });
63
65
  const story = useSelectedStory(storyStore);
64
66
  const animatedValue = useRef(new Animated.Value(tabOpen));
67
+ const wide = useWindowDimensions().width >= BREAKPOINT;
65
68
  const handleToggleTab = (newTabOpen) => {
66
69
  if (newTabOpen === tabOpen) {
67
70
  return;
@@ -81,9 +84,9 @@ const OnDeviceUI = ({ storyStore, isUIHidden, shouldDisableKeyboardAvoidingView,
81
84
  };
82
85
  const previewWrapperStyles = [
83
86
  flex,
84
- getPreviewPosition(animatedValue.current, previewDimensions, slideBetweenAnimation),
87
+ getPreviewPosition(animatedValue.current, previewDimensions, slideBetweenAnimation, wide),
85
88
  ];
86
- const previewStyles = [flex, getPreviewScale(animatedValue.current, slideBetweenAnimation)];
89
+ const previewStyles = [flex, getPreviewScale(animatedValue.current, slideBetweenAnimation, wide)];
87
90
  return (React.createElement(SafeAreaView, { style: [flex, IS_ANDROID && IS_EXPO && styles.expoAndroidContainer] },
88
91
  React.createElement(KeyboardAvoidingView, { enabled: !shouldDisableKeyboardAvoidingView || tabOpen !== PREVIEW, behavior: IS_IOS ? 'padding' : null, keyboardVerticalOffset: keyboardAvoidingViewVerticalOffset, style: flex },
89
92
  React.createElement(AbsolutePositionedKeyboardAwareView, { onLayout: setPreviewDimensions, previewDimensions: previewDimensions },
@@ -92,9 +95,9 @@ const OnDeviceUI = ({ storyStore, isUIHidden, shouldDisableKeyboardAvoidingView,
92
95
  React.createElement(Preview, { disabled: tabOpen === PREVIEW },
93
96
  React.createElement(StoryView, { story: story })),
94
97
  tabOpen !== PREVIEW ? (React.createElement(TouchableOpacity, { style: absolutePosition, onPress: () => handleToggleTab(PREVIEW) })) : null)),
95
- React.createElement(Panel, { style: getNavigatorPanelPosition(animatedValue.current, previewDimensions.width) },
98
+ React.createElement(Panel, { style: getNavigatorPanelPosition(animatedValue.current, previewDimensions.width, wide) },
96
99
  React.createElement(StoryListView, { storyStore: storyStore, selectedStory: story })),
97
- React.createElement(Panel, { style: getAddonPanelPosition(animatedValue.current, previewDimensions.width) },
100
+ React.createElement(Panel, { style: getAddonPanelPosition(animatedValue.current, previewDimensions.width, wide) },
98
101
  React.createElement(Addons, { active: tabOpen === ADDONS }))),
99
102
  React.createElement(Navigation, { tabOpen: tabOpen, onChangeTab: handleToggleTab, initialUiVisible: !isUIHidden }))));
100
103
  };
@@ -1,18 +1,18 @@
1
1
  import { Animated } from 'react-native';
2
2
  import { PreviewDimens } from './absolute-positioned-keyboard-aware-view';
3
- export declare const getNavigatorPanelPosition: (animatedValue: Animated.Value, previewWidth: number) => {
3
+ export declare const getNavigatorPanelPosition: (animatedValue: Animated.Value, previewWidth: number, wide: boolean) => {
4
4
  transform: {
5
5
  translateX: Animated.AnimatedInterpolation;
6
6
  }[];
7
7
  width: number;
8
8
  }[];
9
- export declare const getAddonPanelPosition: (animatedValue: Animated.Value, previewWidth: number) => {
9
+ export declare const getAddonPanelPosition: (animatedValue: Animated.Value, previewWidth: number, wide: boolean) => {
10
10
  transform: {
11
11
  translateX: Animated.AnimatedInterpolation;
12
12
  }[];
13
13
  width: number;
14
14
  }[];
15
- export declare const getPreviewPosition: (animatedValue: Animated.Value, { width: previewWidth, height: previewHeight }: PreviewDimens, slideBetweenAnimation: boolean) => {
15
+ export declare const getPreviewPosition: (animatedValue: Animated.Value, { width: previewWidth, height: previewHeight }: PreviewDimens, slideBetweenAnimation: boolean, wide: boolean) => {
16
16
  transform: ({
17
17
  translateX: Animated.AnimatedInterpolation;
18
18
  translateY?: undefined;
@@ -21,7 +21,7 @@ export declare const getPreviewPosition: (animatedValue: Animated.Value, { width
21
21
  translateX?: undefined;
22
22
  })[];
23
23
  };
24
- export declare const getPreviewScale: (animatedValue: Animated.Value, slideBetweenAnimation: boolean) => {
24
+ export declare const getPreviewScale: (animatedValue: Animated.Value, slideBetweenAnimation: boolean, wide: boolean) => {
25
25
  transform: {
26
26
  scale: Animated.AnimatedInterpolation;
27
27
  }[];
@@ -1,39 +1,47 @@
1
1
  import { NAVIGATOR, PREVIEW, ADDONS } from './navigation/constants';
2
2
  const PREVIEW_SCALE = 0.3;
3
- const panelWidth = (width) => width * (1 - PREVIEW_SCALE - 0.05);
4
- export const getNavigatorPanelPosition = (animatedValue, previewWidth) => {
3
+ const PREVIEW_WIDE_SCREEN = 0.7;
4
+ const SCALE_OFFSET = 0.025;
5
+ const TRANSLATE_X_OFFSET = 6;
6
+ const TRANSLATE_Y_OFFSET = 12;
7
+ const panelWidth = (width, wide) => {
8
+ const scale = wide ? PREVIEW_WIDE_SCREEN : PREVIEW_SCALE;
9
+ return width * (1 - scale - SCALE_OFFSET);
10
+ };
11
+ export const getNavigatorPanelPosition = (animatedValue, previewWidth, wide) => {
5
12
  return [
6
13
  {
7
14
  transform: [
8
15
  {
9
16
  translateX: animatedValue.interpolate({
10
17
  inputRange: [NAVIGATOR, PREVIEW],
11
- outputRange: [0, -panelWidth(previewWidth) - 1],
18
+ outputRange: [0, -panelWidth(previewWidth, wide) - 1],
12
19
  }),
13
20
  },
14
21
  ],
15
- width: panelWidth(previewWidth),
22
+ width: panelWidth(previewWidth, wide),
16
23
  },
17
24
  ];
18
25
  };
19
- export const getAddonPanelPosition = (animatedValue, previewWidth) => {
26
+ export const getAddonPanelPosition = (animatedValue, previewWidth, wide) => {
20
27
  return [
21
28
  {
22
29
  transform: [
23
30
  {
24
31
  translateX: animatedValue.interpolate({
25
32
  inputRange: [PREVIEW, ADDONS],
26
- outputRange: [previewWidth, previewWidth - panelWidth(previewWidth)],
33
+ outputRange: [previewWidth, previewWidth - panelWidth(previewWidth, wide)],
27
34
  }),
28
35
  },
29
36
  ],
30
- width: panelWidth(previewWidth),
37
+ width: panelWidth(previewWidth, wide),
31
38
  },
32
39
  ];
33
40
  };
34
- export const getPreviewPosition = (animatedValue, { width: previewWidth, height: previewHeight }, slideBetweenAnimation) => {
35
- const translateX = previewWidth / 2 - (previewWidth * PREVIEW_SCALE) / 2 - 6;
36
- const translateY = -(previewHeight / 2 - (previewHeight * PREVIEW_SCALE) / 2 - 12);
41
+ export const getPreviewPosition = (animatedValue, { width: previewWidth, height: previewHeight }, slideBetweenAnimation, wide) => {
42
+ const scale = wide ? PREVIEW_WIDE_SCREEN : PREVIEW_SCALE;
43
+ const translateX = previewWidth / 2 - (previewWidth * scale) / 2 - TRANSLATE_X_OFFSET;
44
+ const translateY = -(previewHeight / 2 - (previewHeight * scale) / 2 - TRANSLATE_Y_OFFSET);
37
45
  return {
38
46
  transform: [
39
47
  {
@@ -51,13 +59,14 @@ export const getPreviewPosition = (animatedValue, { width: previewWidth, height:
51
59
  ],
52
60
  };
53
61
  };
54
- export const getPreviewScale = (animatedValue, slideBetweenAnimation) => {
62
+ export const getPreviewScale = (animatedValue, slideBetweenAnimation, wide) => {
63
+ const scale = wide ? PREVIEW_WIDE_SCREEN : PREVIEW_SCALE;
55
64
  return {
56
65
  transform: [
57
66
  {
58
67
  scale: animatedValue.interpolate({
59
68
  inputRange: [NAVIGATOR, PREVIEW, ADDONS],
60
- outputRange: [PREVIEW_SCALE, slideBetweenAnimation ? PREVIEW_SCALE : 1, PREVIEW_SCALE],
69
+ outputRange: [scale, slideBetweenAnimation ? scale : 1, scale],
61
70
  }),
62
71
  },
63
72
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-native",
3
- "version": "6.0.1-alpha.5",
3
+ "version": "6.0.1-beta.1",
4
4
  "description": "A better way to develop React Native Components for your app",
5
5
  "keywords": [
6
6
  "react",
@@ -49,13 +49,13 @@
49
49
  "dependencies": {
50
50
  "@emotion/core": "^10.0.20",
51
51
  "@emotion/native": "^10.0.14",
52
- "@storybook/addons": "^6",
53
- "@storybook/channel-websocket": "^6",
54
- "@storybook/channels": "^6",
55
- "@storybook/client-api": "^6",
56
- "@storybook/client-logger": "^6",
57
- "@storybook/core-client": "^6",
58
- "@storybook/core-events": "^6",
52
+ "@storybook/addons": "~6.3",
53
+ "@storybook/channel-websocket": "~6.3",
54
+ "@storybook/channels": "~6.3",
55
+ "@storybook/client-api": "~6.3",
56
+ "@storybook/client-logger": "~6.3",
57
+ "@storybook/core-client": "~6.3",
58
+ "@storybook/core-events": "~6.3",
59
59
  "@storybook/csf": "0.0.1",
60
60
  "chokidar": "^3.5.1",
61
61
  "commander": "^8.2.0",
@@ -66,7 +66,7 @@
66
66
  "util": "^0.12.4"
67
67
  },
68
68
  "devDependencies": {
69
- "@types/react-native": "^0.65.1",
69
+ "@types/react-native": "^0.66.15",
70
70
  "babel-jest": "^26.6.3",
71
71
  "jest": "^26.6.3",
72
72
  "react-test-renderer": "17.0.2"
@@ -82,5 +82,5 @@
82
82
  "publishConfig": {
83
83
  "access": "public"
84
84
  },
85
- "gitHead": "6f8419cefb00be5cf88132a626b768ec8a332515"
85
+ "gitHead": "bad70d5d87f5ce1d72b8bdd466fb67fa30b0cf27"
86
86
  }
@@ -1,5 +1,40 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`loader writeRequires when there is a story glob and exclude paths globs writes the story imports 1`] = `
4
+ "
5
+ /* do not change this file, it is auto generated by storybook. */
6
+
7
+ import { configure, addDecorator, addParameters, addArgsEnhancer } from '@storybook/react-native';
8
+
9
+ import \\"@storybook/addon-ondevice-notes/register\\";
10
+ import \\"@storybook/addon-ondevice-controls/register\\";
11
+ import \\"@storybook/addon-ondevice-backgrounds/register\\";
12
+ import \\"@storybook/addon-ondevice-actions/register\\";
13
+
14
+ import { argsEnhancers } from \\"@storybook/addon-actions/dist/modern/preset/addArgs\\"
15
+
16
+
17
+ import { decorators, parameters } from './preview';
18
+
19
+ if (decorators) {
20
+ decorators.forEach((decorator) => addDecorator(decorator));
21
+ }
22
+
23
+ if (parameters) {
24
+ addParameters(parameters);
25
+ }
26
+
27
+
28
+ argsEnhancers.forEach(enhancer => addArgsEnhancer(enhancer))
29
+
30
+ const getStories=() => {
31
+ return [require(\\"include-components/FakeStory.stories.tsx\\")];
32
+ }
33
+
34
+ configure(getStories, module, false)
35
+ "
36
+ `;
37
+
3
38
  exports[`loader writeRequires when there is a story glob writes the story imports 1`] = `
4
39
  "
5
40
  /* do not change this file, it is auto generated by storybook. */
package/scripts/loader.js CHANGED
@@ -17,6 +17,21 @@ const previewImports = `
17
17
  }
18
18
  `;
19
19
 
20
+ function normalizeExcludePaths(paths) {
21
+ // automatically convert a string to an array of a single string
22
+ if (typeof paths === 'string') {
23
+ return [paths];
24
+ }
25
+
26
+ // ensure the paths is an array and if any items exists, they are strings
27
+ if (Array.isArray(paths) && paths.every((p) => typeof p === 'string')) {
28
+ return paths;
29
+ }
30
+
31
+ // when the paths aren't a string or an (empty) array of strings, return
32
+ return undefined;
33
+ }
34
+
20
35
  function requireUncached(module) {
21
36
  delete require.cache[require.resolve(module)];
22
37
  return require(module);
@@ -36,8 +51,19 @@ function writeRequires({ configPath, absolute = false }) {
36
51
  const storybookRequiresLocation = path.resolve(cwd, configPath, 'storybook.requires.js');
37
52
 
38
53
  const main = getMain({ configPath });
54
+ const reactNativeOptions = main.reactNativeOptions;
55
+ const excludePaths = reactNativeOptions && reactNativeOptions.excludePaths;
56
+ const normalizedExcludePaths = normalizeExcludePaths(excludePaths);
57
+
39
58
  const storyPaths = main.stories.reduce((acc, storyGlob) => {
40
- const paths = glob.sync(storyGlob, { cwd: path.resolve(cwd, configPath), absolute });
59
+ const paths = glob.sync(storyGlob, {
60
+ cwd: path.resolve(cwd, configPath),
61
+ absolute,
62
+ // default to always ignore (exclude) anything in node_modules
63
+ ignore: normalizedExcludePaths !== undefined
64
+ ? normalizedExcludePaths
65
+ : ['**/node_modules'],
66
+ });
41
67
  return [...acc, ...paths];
42
68
  }, []);
43
69
 
@@ -86,6 +86,20 @@ describe('loader', () => {
86
86
  });
87
87
  });
88
88
 
89
+ describe('when there is a story glob and exclude paths globs', () => {
90
+ it('writes the story imports', () => {
91
+ writeRequires({ configPath: 'scripts/mocks/exclude-config-files' });
92
+ expect(pathMock).toEqual(
93
+ path.resolve(__dirname, 'mocks/exclude-config-files/storybook.requires.js')
94
+ );
95
+
96
+ expect(fileContentMock).toContain('include-components/FakeStory.stories.tsx');
97
+ expect(fileContentMock).not.toContain('exclude-components/FakeStory.stories.tsx');
98
+
99
+ expect(fileContentMock).toMatchSnapshot();
100
+ });
101
+ });
102
+
89
103
  describe('when there is no story glob or addons', () => {
90
104
  it('writes no story imports or addons', () => {
91
105
  writeRequires({ configPath: 'scripts/mocks/blank-config' });
@@ -0,0 +1 @@
1
+ export const FakeComponent = () => null;
@@ -0,0 +1,10 @@
1
+ import { FakeComponentExcluded } from './FakeComponent';
2
+
3
+ export default {
4
+ title: 'components/FakeComponentExcluded',
5
+ component: FakeComponentExcluded,
6
+ };
7
+
8
+ export const Basic = {
9
+ args: {},
10
+ };
@@ -0,0 +1 @@
1
+ export const FakeComponent = () => null;
@@ -0,0 +1,10 @@
1
+ import { FakeComponent } from './FakeComponent';
2
+
3
+ export default {
4
+ title: 'components/FakeComponent',
5
+ component: FakeComponent,
6
+ };
7
+
8
+ export const Basic = {
9
+ args: {},
10
+ };
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ stories: ['**/*.stories.tsx'],
3
+ reactNativeOptions: {
4
+ excludePaths: '**/exclude-components/**',
5
+ },
6
+ addons: [
7
+ '@storybook/addon-ondevice-notes',
8
+ '@storybook/addon-ondevice-controls',
9
+ '@storybook/addon-ondevice-backgrounds',
10
+ '@storybook/addon-ondevice-actions',
11
+ ],
12
+ };
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+ import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
4
+
5
+ export const decorators = [
6
+ (StoryFn) => (
7
+ <View style={styles.container}>
8
+ <StoryFn />
9
+ </View>
10
+ ),
11
+ withBackgrounds,
12
+ ];
13
+ export const parameters = {
14
+ my_param: 'anything',
15
+ backgrounds: [
16
+ { name: 'plain', value: 'white', default: true },
17
+ { name: 'warm', value: 'hotpink' },
18
+ { name: 'cool', value: 'deepskyblue' },
19
+ ],
20
+ };
21
+
22
+ const styles = StyleSheet.create({
23
+ container: { padding: 8, flex: 1 },
24
+ });