@storybook/react-native 6.0.1-beta.7 → 6.0.1-canary.0

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.
Files changed (66) hide show
  1. package/dist/document-polyfill/DOM/Document.d.ts +14 -0
  2. package/dist/document-polyfill/DOM/Document.js +37 -0
  3. package/dist/document-polyfill/DOM/Element.d.ts +37 -0
  4. package/dist/document-polyfill/DOM/Element.js +58 -0
  5. package/dist/document-polyfill/DOM/HTMLCanvasElement.d.ts +4 -0
  6. package/dist/document-polyfill/DOM/HTMLCanvasElement.js +4 -0
  7. package/dist/document-polyfill/DOM/HTMLImageElement.d.ts +4 -0
  8. package/dist/document-polyfill/DOM/HTMLImageElement.js +4 -0
  9. package/dist/document-polyfill/DOM/HTMLVideoElement.d.ts +4 -0
  10. package/dist/document-polyfill/DOM/HTMLVideoElement.js +4 -0
  11. package/dist/document-polyfill/DOM/Node.d.ts +26 -0
  12. package/dist/document-polyfill/DOM/Node.js +33 -0
  13. package/dist/{preview/global.js → document-polyfill/index.d.ts} +0 -0
  14. package/dist/document-polyfill/index.js +3 -0
  15. package/dist/document-polyfill/module.d.ts +0 -0
  16. package/dist/document-polyfill/module.js +1 -0
  17. package/dist/{types-6.0.js → document-polyfill/module.native.d.ts} +0 -0
  18. package/dist/document-polyfill/module.native.js +2 -0
  19. package/dist/index.d.ts +13 -12
  20. package/dist/index.js +13 -17
  21. package/dist/preview/View.d.ts +40 -0
  22. package/dist/preview/View.js +90 -0
  23. package/dist/preview/components/OnDeviceUI/OnDeviceUI.d.ts +6 -3
  24. package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +26 -37
  25. package/dist/preview/components/OnDeviceUI/Panel.js +1 -0
  26. package/dist/preview/components/OnDeviceUI/animation.d.ts +5 -5
  27. package/dist/preview/components/OnDeviceUI/navigation/Bar.d.ts +3 -1
  28. package/dist/preview/components/OnDeviceUI/navigation/Bar.js +1 -1
  29. package/dist/preview/components/OnDeviceUI/navigation/Navigation.d.ts +4 -3
  30. package/dist/preview/components/OnDeviceUI/navigation/Navigation.js +15 -10
  31. package/dist/preview/components/OnDeviceUI/navigation/VisibilityButton.d.ts +3 -1
  32. package/dist/preview/components/OnDeviceUI/navigation/VisibilityButton.js +34 -5
  33. package/dist/preview/components/Shared/icons.d.ts +1 -0
  34. package/dist/preview/components/Shared/text.d.ts +3 -44
  35. package/dist/preview/components/StoryListView/StoryListView.d.ts +7 -4
  36. package/dist/preview/components/StoryListView/StoryListView.js +24 -15
  37. package/dist/preview/components/StoryView/StoryView.d.ts +5 -3
  38. package/dist/preview/components/StoryView/StoryView.js +6 -24
  39. package/dist/preview/executeLoadable.d.ts +24 -0
  40. package/dist/preview/executeLoadable.js +82 -0
  41. package/dist/preview/rn-host-detect.d.ts +1 -0
  42. package/dist/preview/rn-host-detect.js +62 -0
  43. package/dist/preview/start.d.ts +13 -0
  44. package/dist/preview/start.js +75 -0
  45. package/dist/{types-6.0.d.ts → types/types-6.0.d.ts} +4 -0
  46. package/dist/types/types-6.0.js +1 -0
  47. package/dist/types/types.d.ts +14 -0
  48. package/dist/types/types.js +1 -0
  49. package/package.json +16 -13
  50. package/scripts/loader.js +11 -2
  51. package/scripts/loader.test.js +23 -5
  52. package/scripts/mocks/preview-files/js/preview.js +24 -0
  53. package/scripts/mocks/preview-files/jsx/preview.jsx +24 -0
  54. package/scripts/mocks/preview-files/ts/preview.ts +9 -0
  55. package/scripts/mocks/preview-files/tsx/preview.tsx +9 -0
  56. package/scripts/mocks/wrong-extension-preview/FakeComponent.tsx +1 -0
  57. package/scripts/mocks/wrong-extension-preview/FakeStory.stories.tsx +10 -0
  58. package/scripts/mocks/wrong-extension-preview/main.js +9 -0
  59. package/scripts/mocks/wrong-extension-preview/preview.txt +24 -0
  60. package/dist/preview/Preview.d.ts +0 -57
  61. package/dist/preview/Preview.js +0 -119
  62. package/dist/preview/global.d.ts +0 -8
  63. package/dist/preview/index.d.ts +0 -1
  64. package/dist/preview/index.js +0 -1
  65. package/dist/preview/loadCsf.d.ts +0 -16
  66. package/dist/preview/loadCsf.js +0 -180
@@ -0,0 +1,14 @@
1
+ export default Document;
2
+ declare class Document extends Element {
3
+ constructor();
4
+ body: Element;
5
+ documentElement: Element;
6
+ readyState: string;
7
+ createElement(tagName: any): Element;
8
+ createElementNS(tagName: any): Element;
9
+ getElementById(id: any): Element;
10
+ location: {
11
+ search: string;
12
+ };
13
+ }
14
+ import Element from "./Element";
@@ -0,0 +1,37 @@
1
+ import Element from './Element';
2
+ import HTMLVideoElement from './HTMLVideoElement';
3
+ import HTMLImageElement from './HTMLImageElement';
4
+ import HTMLCanvasElement from './HTMLCanvasElement';
5
+ class Document extends Element {
6
+ constructor() {
7
+ super('#document');
8
+ this.location = { search: '' };
9
+ this.body = new Element('BODY');
10
+ this.documentElement = new Element('HTML');
11
+ this.readyState = 'complete';
12
+ }
13
+ createElement(tagName) {
14
+ switch ((tagName || '').toLowerCase()) {
15
+ case 'video':
16
+ return new HTMLVideoElement(tagName);
17
+ case 'img':
18
+ return new HTMLImageElement(tagName);
19
+ case 'canvas':
20
+ return new HTMLCanvasElement(tagName);
21
+ case 'iframe':
22
+ // Return nothing to keep firebase working.
23
+ return null;
24
+ default:
25
+ return new Element(tagName);
26
+ }
27
+ }
28
+ createElementNS(tagName) {
29
+ const element = this.createElement(tagName);
30
+ element.toDataURL = () => ({});
31
+ return element;
32
+ }
33
+ getElementById(id) {
34
+ return new Element('div');
35
+ }
36
+ }
37
+ export default Document;
@@ -0,0 +1,37 @@
1
+ export default Element;
2
+ declare class Element extends Node {
3
+ doc: {
4
+ body: {
5
+ innerHTML: string;
6
+ };
7
+ };
8
+ get tagName(): any;
9
+ get clientWidth(): number;
10
+ get clientHeight(): number;
11
+ get offsetWidth(): number;
12
+ get offsetHeight(): number;
13
+ get innerWidth(): number;
14
+ get innerHeight(): number;
15
+ getContext(contextType: any, contextOptions: any, context: any): {
16
+ fillText: (text: any, x: any, y: any, maxWidth: any) => {};
17
+ measureText: (text: any) => {
18
+ width: number;
19
+ height: number;
20
+ };
21
+ fillRect: () => {};
22
+ drawImage: () => {};
23
+ getImageData: () => {
24
+ data: Uint8ClampedArray;
25
+ };
26
+ getContextAttributes: () => {
27
+ stencil: boolean;
28
+ };
29
+ getExtension: () => {
30
+ loseContext: () => void;
31
+ };
32
+ putImageData: () => {};
33
+ createImageData: () => {};
34
+ };
35
+ get ontouchstart(): {};
36
+ }
37
+ import Node from "./Node";
@@ -0,0 +1,58 @@
1
+ import Node from './Node';
2
+ class Element extends Node {
3
+ constructor(tagName) {
4
+ return super(tagName.toUpperCase());
5
+ // eslint-disable-next-line no-unreachable
6
+ this.doc = {
7
+ body: {
8
+ innerHTML: '',
9
+ },
10
+ };
11
+ }
12
+ get tagName() {
13
+ return this.nodeName;
14
+ }
15
+ setAttributeNS() { }
16
+ get clientWidth() {
17
+ return this.innerWidth;
18
+ }
19
+ get clientHeight() {
20
+ return this.innerHeight;
21
+ }
22
+ get offsetWidth() {
23
+ return this.innerWidth;
24
+ }
25
+ get offsetHeight() {
26
+ return this.innerHeight;
27
+ }
28
+ get innerWidth() {
29
+ return window.innerWidth;
30
+ }
31
+ get innerHeight() {
32
+ return window.innerHeight;
33
+ }
34
+ getContext(contextType, contextOptions, context) {
35
+ return {
36
+ fillText: (text, x, y, maxWidth) => ({}),
37
+ measureText: (text) => ({
38
+ width: (text || '').split('').length * 6,
39
+ height: 24,
40
+ }),
41
+ fillRect: () => ({}),
42
+ drawImage: () => ({}),
43
+ getImageData: () => ({ data: new Uint8ClampedArray([255, 0, 0, 0]) }),
44
+ getContextAttributes: () => ({
45
+ stencil: true,
46
+ }),
47
+ getExtension: () => ({
48
+ loseContext: () => { },
49
+ }),
50
+ putImageData: () => ({}),
51
+ createImageData: () => ({}),
52
+ };
53
+ }
54
+ get ontouchstart() {
55
+ return {};
56
+ }
57
+ }
58
+ export default Element;
@@ -0,0 +1,4 @@
1
+ export default HTMLCanvasElement;
2
+ declare class HTMLCanvasElement extends Element {
3
+ }
4
+ import Element from "./Element";
@@ -0,0 +1,4 @@
1
+ import Element from './Element';
2
+ class HTMLCanvasElement extends Element {
3
+ }
4
+ export default HTMLCanvasElement;
@@ -0,0 +1,4 @@
1
+ export default HTMLImageElement;
2
+ declare class HTMLImageElement extends Element {
3
+ }
4
+ import Element from "./Element";
@@ -0,0 +1,4 @@
1
+ import Element from './Element';
2
+ class HTMLImageElement extends Element {
3
+ }
4
+ export default HTMLImageElement;
@@ -0,0 +1,4 @@
1
+ export default HTMLVideoElement;
2
+ declare class HTMLVideoElement extends Element {
3
+ }
4
+ import Element from "./Element";
@@ -0,0 +1,4 @@
1
+ import Element from './Element';
2
+ class HTMLVideoElement extends Element {
3
+ }
4
+ export default HTMLVideoElement;
@@ -0,0 +1,26 @@
1
+ export default Node;
2
+ declare class Node {
3
+ constructor(nodeName: any);
4
+ addEventListener(_eventName: any, _listener: any): void;
5
+ removeEventListener(_eventName: any, _listener: any): void;
6
+ style: {};
7
+ className: {
8
+ baseVal: string;
9
+ };
10
+ nodeName: any;
11
+ get ownerDocument(): Document;
12
+ appendChild(): void;
13
+ insertBefore(): void;
14
+ removeChild(): void;
15
+ setAttributeNS(): void;
16
+ getBoundingClientRect(): {
17
+ left: number;
18
+ top: number;
19
+ right: number;
20
+ bottom: number;
21
+ x: number;
22
+ y: number;
23
+ width: number;
24
+ height: number;
25
+ };
26
+ }
@@ -0,0 +1,33 @@
1
+ class Node {
2
+ constructor(nodeName) {
3
+ this.addEventListener = this.addEventListener.bind(this);
4
+ this.removeEventListener = this.removeEventListener.bind(this);
5
+ this.style = {};
6
+ this.className = {
7
+ baseVal: '',
8
+ };
9
+ this.nodeName = nodeName;
10
+ }
11
+ get ownerDocument() {
12
+ return window.document;
13
+ }
14
+ addEventListener(_eventName, _listener) { }
15
+ removeEventListener(_eventName, _listener) { }
16
+ appendChild() { }
17
+ insertBefore() { }
18
+ removeChild() { }
19
+ setAttributeNS() { }
20
+ getBoundingClientRect() {
21
+ return {
22
+ left: 0,
23
+ top: 0,
24
+ right: window.innerWidth,
25
+ bottom: window.innerHeight,
26
+ x: 0,
27
+ y: 0,
28
+ width: window.innerWidth,
29
+ height: window.innerHeight,
30
+ };
31
+ }
32
+ }
33
+ export default Node;
@@ -0,0 +1,3 @@
1
+ // this is temporary until we can solve the preview web crashing the app by accessing document
2
+ // adjusted from expo/browser-polyfill to not require external dependencies https://github.com/expo/browser-polyfill
3
+ import './module';
File without changes
@@ -0,0 +1 @@
1
+ // do nothing
@@ -0,0 +1,2 @@
1
+ import Document from './DOM/Document';
2
+ window.document = window.document || new Document();
package/dist/index.d.ts CHANGED
@@ -3,16 +3,17 @@
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;
8
- export declare const setAddon: ClientApi['setAddon'];
9
- export declare const addDecorator: ClientApi['addDecorator'];
10
- export declare const addParameters: ClientApi['addParameters'];
11
- export declare const addArgsEnhancer: ClientApi['addArgsEnhancer'];
12
- export declare const clearDecorators: ClientApi['clearDecorators'];
13
- export declare const configure: (loadable: import("@storybook/core-client").Loadable, m: NodeModule, showDeprecationWarning: boolean) => void;
14
- export declare const getStorybook: ClientApi['getStorybook'];
15
- export declare const getStorybookUI: (params?: Partial<import("./preview/Preview").Params>) => () => JSX.Element;
16
- export declare const raw: ClientApi['raw'];
6
+ import type { ReactNativeFramework } from './types/types-6.0';
7
+ declare const configure: (loadable: import("@storybook/core-client").Loadable) => void;
8
+ export { configure };
9
+ declare type C = ClientApi<ReactNativeFramework>;
10
+ export declare const setAddon: C['setAddon'];
11
+ export declare const addDecorator: C['addDecorator'];
12
+ export declare const addParameters: C['addParameters'];
13
+ export declare const addArgsEnhancer: C['addArgsEnhancer'];
14
+ export declare const clearDecorators: C['clearDecorators'];
15
+ export declare const getStorybook: C['getStorybook'];
16
+ export declare const raw: C['raw'];
17
17
  export declare const storiesOf: (kind: string, module: NodeModule) => StoryApi<ReactNode>;
18
- export * from './types-6.0';
18
+ export declare const getStorybookUI: (params?: Partial<import("./preview/View").Params>) => () => JSX.Element;
19
+ export * from './types/types-6.0';
package/dist/index.js CHANGED
@@ -1,18 +1,14 @@
1
- import Preview from './preview';
2
- export const preview = new Preview();
3
- const rawStoriesOf = preview.api().storiesOf.bind(preview);
4
- export const setAddon = preview.api().setAddon.bind(preview);
5
- export const addDecorator = preview.api().addDecorator.bind(preview);
6
- export const addParameters = preview.api().addParameters.bind(preview);
7
- export const addArgsEnhancer = preview
8
- .api()
9
- .addArgsEnhancer.bind(preview);
10
- export const clearDecorators = preview
11
- .api()
12
- .clearDecorators.bind(preview);
13
- export const configure = preview.configure;
14
- export const getStorybook = preview.api().getStorybook.bind(preview);
15
- export const getStorybookUI = preview.getStorybookUI;
16
- export const raw = preview.api().raw.bind(preview);
1
+ import { start } from './preview/start';
2
+ const { clientApi, configure, view } = start();
3
+ export { configure };
4
+ const rawStoriesOf = clientApi.storiesOf.bind(clientApi);
5
+ export const setAddon = clientApi.setAddon.bind(clientApi);
6
+ export const addDecorator = clientApi.addDecorator.bind(clientApi);
7
+ export const addParameters = clientApi.addParameters.bind(clientApi);
8
+ export const addArgsEnhancer = clientApi.addArgsEnhancer.bind(clientApi);
9
+ export const clearDecorators = clientApi.clearDecorators.bind(clientApi);
10
+ export const getStorybook = clientApi.getStorybook.bind(clientApi);
11
+ export const raw = clientApi.raw.bind(clientApi);
17
12
  export const storiesOf = (kind, module) => rawStoriesOf(kind, module).addParameters({ framework: 'react-native' });
18
- export * from './types-6.0';
13
+ export const getStorybookUI = view.getStorybookUI;
14
+ export * from './types/types-6.0';
@@ -0,0 +1,40 @@
1
+ /// <reference types="react" />
2
+ import { StoryIndex, SelectionSpecifier } from '@storybook/store';
3
+ import { StoryContext } from '@storybook/csf';
4
+ import { theme } from './components/Shared/theme';
5
+ import type { ReactNativeFramework } from '../types/types-6.0';
6
+ import { PreviewWeb } from '@storybook/preview-web';
7
+ declare type StoryKind = string;
8
+ declare type StoryName = string;
9
+ declare type InitialSelection = `${StoryKind}--${StoryName}` | {
10
+ /**
11
+ * Kind is the default export name or the storiesOf("name") name
12
+ */
13
+ kind: StoryKind;
14
+ /**
15
+ * Name is the named export or the .add("name") name
16
+ */
17
+ name: StoryName;
18
+ };
19
+ export declare type Params = {
20
+ initialSelection?: InitialSelection;
21
+ shouldPersistSelection?: boolean;
22
+ tabOpen?: number;
23
+ isUIHidden?: boolean;
24
+ shouldDisableKeyboardAvoidingView?: boolean;
25
+ keyboardAvoidingViewVerticalOffset?: number;
26
+ } & {
27
+ theme?: typeof theme;
28
+ };
29
+ export declare class View {
30
+ _storyIndex: StoryIndex;
31
+ _setStory: (story: StoryContext<ReactNativeFramework>) => void;
32
+ _forceRerender: () => void;
33
+ _ready: boolean;
34
+ _preview: PreviewWeb<ReactNativeFramework>;
35
+ _asyncStorageStoryId: string;
36
+ constructor(preview: PreviewWeb<ReactNativeFramework>);
37
+ _getInitialStory: ({ initialSelection, shouldPersistSelection, }?: Partial<Params>) => Promise<SelectionSpecifier>;
38
+ getStorybookUI: (params?: Partial<Params>) => () => JSX.Element;
39
+ }
40
+ export {};
@@ -0,0 +1,90 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React, { useEffect, useState, useReducer } from 'react';
11
+ import AsyncStorage from '@react-native-async-storage/async-storage';
12
+ import { toId } from '@storybook/csf';
13
+ import { addons } from '@storybook/addons';
14
+ import { ThemeProvider } from 'emotion-theming';
15
+ import { SafeAreaProvider } from 'react-native-safe-area-context';
16
+ import OnDeviceUI from './components/OnDeviceUI';
17
+ import { theme } from './components/Shared/theme';
18
+ const STORAGE_KEY = 'lastOpenedStory';
19
+ export class View {
20
+ constructor(preview) {
21
+ this._setStory = () => { };
22
+ this._ready = false;
23
+ this._getInitialStory = ({ initialSelection, shouldPersistSelection = true, } = {}) => __awaiter(this, void 0, void 0, function* () {
24
+ if (initialSelection) {
25
+ if (typeof initialSelection === 'string') {
26
+ return { storySpecifier: initialSelection, viewMode: 'story' };
27
+ }
28
+ else {
29
+ return {
30
+ storySpecifier: toId(initialSelection.kind, initialSelection.name),
31
+ viewMode: 'story',
32
+ };
33
+ }
34
+ }
35
+ if (shouldPersistSelection) {
36
+ try {
37
+ let value = this._asyncStorageStoryId;
38
+ if (!value) {
39
+ value = yield AsyncStorage.getItem(STORAGE_KEY);
40
+ this._asyncStorageStoryId = value;
41
+ }
42
+ return { storySpecifier: value, viewMode: 'story' };
43
+ }
44
+ catch (e) {
45
+ console.warn('storybook-log: error reading from async storage', e);
46
+ }
47
+ }
48
+ return { storySpecifier: '*', viewMode: 'story' };
49
+ });
50
+ this.getStorybookUI = (params = {}) => {
51
+ const { shouldPersistSelection = true } = params;
52
+ const initialStory = this._getInitialStory(params);
53
+ addons.loadAddons({
54
+ store: () => ({
55
+ fromId: (id) => this._preview.storyStore.getStoryContext(this._preview.storyStore.fromId(id)),
56
+ getSelection: () => {
57
+ return this._preview.currentSelection;
58
+ },
59
+ _channel: this._preview.channel,
60
+ }),
61
+ });
62
+ // eslint-disable-next-line consistent-this
63
+ const self = this;
64
+ const appliedTheme = Object.assign(Object.assign({}, theme), params.theme);
65
+ return () => {
66
+ const [context, setContext] = useState();
67
+ const [, forceUpdate] = useReducer((x) => x + 1, 0);
68
+ useEffect(() => {
69
+ self._setStory = (newStory) => {
70
+ setContext(newStory);
71
+ if (shouldPersistSelection) {
72
+ AsyncStorage.setItem(STORAGE_KEY, newStory.id).catch((e) => {
73
+ console.warn('storybook-log: error writing to async storage', e);
74
+ });
75
+ }
76
+ };
77
+ self._forceRerender = () => forceUpdate();
78
+ initialStory.then((story) => {
79
+ self._preview.urlStore.selectionSpecifier = story;
80
+ self._preview.selectSpecifiedStory();
81
+ });
82
+ }, []);
83
+ return (React.createElement(SafeAreaProvider, null,
84
+ React.createElement(ThemeProvider, { theme: appliedTheme },
85
+ React.createElement(OnDeviceUI, { context: context, storyIndex: self._storyIndex, isUIHidden: params.isUIHidden, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset }))));
86
+ };
87
+ };
88
+ this._preview = preview;
89
+ }
90
+ }
@@ -1,13 +1,16 @@
1
- import { StoryStore } from '@storybook/client-api';
1
+ import { StoryIndex } from '@storybook/client-api';
2
2
  import React from 'react';
3
+ import { StoryContext } from '@storybook/csf';
4
+ import { ReactNativeFramework } from 'src/types/types-6.0';
3
5
  export declare const IS_EXPO: boolean;
4
6
  interface OnDeviceUIProps {
5
- storyStore: StoryStore;
7
+ context: StoryContext<ReactNativeFramework>;
8
+ storyIndex: StoryIndex;
6
9
  url?: string;
7
10
  tabOpen?: number;
8
11
  isUIHidden?: boolean;
9
12
  shouldDisableKeyboardAvoidingView?: boolean;
10
13
  keyboardAvoidingViewVerticalOffset?: number;
11
14
  }
12
- declare const _default: React.MemoExoticComponent<({ storyStore, isUIHidden, shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset, tabOpen: initialTabOpen, }: OnDeviceUIProps) => JSX.Element>;
15
+ declare const _default: React.MemoExoticComponent<({ context, storyIndex, isUIHidden, shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset, tabOpen: initialTabOpen, }: OnDeviceUIProps) => JSX.Element>;
13
16
  export default _default;
@@ -1,8 +1,6 @@
1
1
  import styled from '@emotion/native';
2
- import { addons } from '@storybook/addons';
3
- import React, { useState, useEffect, useRef, useReducer } from 'react';
4
- import { Animated, Dimensions, Keyboard, KeyboardAvoidingView, Platform, SafeAreaView, TouchableOpacity, StatusBar, StyleSheet, } from 'react-native';
5
- import Events from '@storybook/core-events';
2
+ import React, { useState, useRef } from 'react';
3
+ import { Animated, Dimensions, Keyboard, KeyboardAvoidingView, Platform, SafeAreaView, TouchableOpacity, StatusBar, StyleSheet, View, } from 'react-native';
6
4
  import StoryListView from '../StoryListView';
7
5
  import StoryView from '../StoryView';
8
6
  import AbsolutePositionedKeyboardAwareView from './absolute-positioned-keyboard-aware-view';
@@ -12,6 +10,7 @@ import Navigation from './navigation';
12
10
  import { PREVIEW, ADDONS } from './navigation/constants';
13
11
  import Panel from './Panel';
14
12
  import { useWindowDimensions } from 'react-native';
13
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
15
14
  const ANIMATION_DURATION = 300;
16
15
  const IS_IOS = Platform.OS === 'ios';
17
16
  // @ts-ignore: Property 'Expo' does not exist on type 'Global'
@@ -37,34 +36,19 @@ const absolutePosition = {
37
36
  const styles = StyleSheet.create({
38
37
  expoAndroidContainer: { paddingTop: StatusBar.currentHeight },
39
38
  });
40
- const useSelectedStory = (storyStore) => {
41
- var _a;
42
- const [storyId, setStoryId] = useState(((_a = storyStore.getSelection()) === null || _a === void 0 ? void 0 : _a.storyId) || '');
43
- const [, forceUpdate] = useReducer((x) => x + 1, 0);
44
- const channel = useRef(addons.getChannel());
45
- useEffect(() => {
46
- const handleStoryWasSet = ({ id: newStoryId }) => setStoryId(newStoryId);
47
- const currentChannel = channel.current;
48
- channel.current.on(Events.SELECT_STORY, handleStoryWasSet);
49
- //TODO: update preview without force
50
- channel.current.on(Events.FORCE_RE_RENDER, forceUpdate);
51
- return () => {
52
- currentChannel.removeListener(Events.SELECT_STORY, handleStoryWasSet);
53
- currentChannel.removeListener(Events.FORCE_RE_RENDER, forceUpdate);
54
- };
55
- }, []);
56
- return storyStore.fromId(storyId);
57
- };
58
- const OnDeviceUI = ({ storyStore, isUIHidden, shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset, tabOpen: initialTabOpen, }) => {
39
+ const OnDeviceUI = ({ context, storyIndex, isUIHidden, shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset, tabOpen: initialTabOpen, }) => {
40
+ var _a, _b;
59
41
  const [tabOpen, setTabOpen] = useState(initialTabOpen || PREVIEW);
60
42
  const [slideBetweenAnimation, setSlideBetweenAnimation] = useState(false);
61
43
  const [previewDimensions, setPreviewDimensions] = useState({
62
44
  width: Dimensions.get('window').width,
63
45
  height: Dimensions.get('window').height,
64
46
  });
65
- const story = useSelectedStory(storyStore);
47
+ // const story = useSelectedStory(storyStore);
66
48
  const animatedValue = useRef(new Animated.Value(tabOpen));
67
49
  const wide = useWindowDimensions().width >= BREAKPOINT;
50
+ const insets = useSafeAreaInsets();
51
+ const [isUIVisible, setIsUIVisible] = useState(isUIHidden !== undefined ? !isUIHidden : true);
68
52
  const handleToggleTab = (newTabOpen) => {
69
53
  if (newTabOpen === tabOpen) {
70
54
  return;
@@ -87,18 +71,23 @@ const OnDeviceUI = ({ storyStore, isUIHidden, shouldDisableKeyboardAvoidingView,
87
71
  getPreviewPosition(animatedValue.current, previewDimensions, slideBetweenAnimation, wide),
88
72
  ];
89
73
  const previewStyles = [flex, getPreviewScale(animatedValue.current, slideBetweenAnimation, wide)];
90
- return (React.createElement(SafeAreaView, { style: [flex, IS_ANDROID && IS_EXPO && styles.expoAndroidContainer] },
91
- React.createElement(KeyboardAvoidingView, { enabled: !shouldDisableKeyboardAvoidingView || tabOpen !== PREVIEW, behavior: IS_IOS ? 'padding' : null, keyboardVerticalOffset: keyboardAvoidingViewVerticalOffset, style: flex },
92
- React.createElement(AbsolutePositionedKeyboardAwareView, { onLayout: setPreviewDimensions, previewDimensions: previewDimensions },
93
- React.createElement(Animated.View, { style: previewWrapperStyles },
94
- React.createElement(Animated.View, { style: previewStyles },
95
- React.createElement(Preview, { disabled: tabOpen === PREVIEW },
96
- React.createElement(StoryView, { story: story })),
97
- tabOpen !== PREVIEW ? (React.createElement(TouchableOpacity, { style: absolutePosition, onPress: () => handleToggleTab(PREVIEW) })) : null)),
98
- React.createElement(Panel, { style: getNavigatorPanelPosition(animatedValue.current, previewDimensions.width, wide) },
99
- React.createElement(StoryListView, { storyStore: storyStore, selectedStory: story })),
100
- React.createElement(Panel, { style: getAddonPanelPosition(animatedValue.current, previewDimensions.width, wide) },
101
- React.createElement(Addons, { active: tabOpen === ADDONS }))),
102
- React.createElement(Navigation, { tabOpen: tabOpen, onChangeTab: handleToggleTab, initialUiVisible: !isUIHidden }))));
74
+ const noSafeArea = (_b = (_a = context === null || context === void 0 ? void 0 : context.parameters) === null || _a === void 0 ? void 0 : _a.noSafeArea) !== null && _b !== void 0 ? _b : false;
75
+ const WrapperView = noSafeArea ? View : SafeAreaView;
76
+ const wrapperMargin = { marginBottom: isUIVisible ? insets.bottom + 40 : 0 };
77
+ return (React.createElement(React.Fragment, null,
78
+ React.createElement(View, { style: [flex, IS_ANDROID && IS_EXPO && styles.expoAndroidContainer] },
79
+ React.createElement(KeyboardAvoidingView, { enabled: !shouldDisableKeyboardAvoidingView || tabOpen !== PREVIEW, behavior: IS_IOS ? 'padding' : null, keyboardVerticalOffset: keyboardAvoidingViewVerticalOffset, style: flex },
80
+ React.createElement(AbsolutePositionedKeyboardAwareView, { onLayout: setPreviewDimensions, previewDimensions: previewDimensions },
81
+ React.createElement(Animated.View, { style: previewWrapperStyles },
82
+ React.createElement(Animated.View, { style: previewStyles },
83
+ React.createElement(Preview, { disabled: tabOpen === PREVIEW },
84
+ React.createElement(WrapperView, { style: [flex, wrapperMargin] },
85
+ React.createElement(StoryView, { context: context }))),
86
+ tabOpen !== PREVIEW ? (React.createElement(TouchableOpacity, { style: absolutePosition, onPress: () => handleToggleTab(PREVIEW) })) : null)),
87
+ React.createElement(Panel, { style: getNavigatorPanelPosition(animatedValue.current, previewDimensions.width, wide) },
88
+ React.createElement(StoryListView, { storyIndex: storyIndex, selectedStoryContext: context })),
89
+ React.createElement(Panel, { style: getAddonPanelPosition(animatedValue.current, previewDimensions.width, wide) },
90
+ React.createElement(Addons, { active: tabOpen === ADDONS })))),
91
+ React.createElement(Navigation, { tabOpen: tabOpen, onChangeTab: handleToggleTab, isUIVisible: isUIVisible, setIsUIVisible: setIsUIVisible }))));
103
92
  };
104
93
  export default React.memo(OnDeviceUI);
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { StyleSheet, Animated } from 'react-native';
3
3
  import styled from '@emotion/native';
4
+ // @ts-ignore styled is being weird ;(
4
5
  const Container = styled(Animated.View)(({ theme }) => ({
5
6
  backgroundColor: theme.backgroundColor || 'white',
6
7
  }));
@@ -2,27 +2,27 @@ import { Animated } from 'react-native';
2
2
  import { PreviewDimens } from './absolute-positioned-keyboard-aware-view';
3
3
  export declare const getNavigatorPanelPosition: (animatedValue: Animated.Value, previewWidth: number, wide: boolean) => {
4
4
  transform: {
5
- translateX: Animated.AnimatedInterpolation;
5
+ translateX: Animated.AnimatedInterpolation<string | number>;
6
6
  }[];
7
7
  width: number;
8
8
  }[];
9
9
  export declare const getAddonPanelPosition: (animatedValue: Animated.Value, previewWidth: number, wide: boolean) => {
10
10
  transform: {
11
- translateX: Animated.AnimatedInterpolation;
11
+ translateX: Animated.AnimatedInterpolation<string | number>;
12
12
  }[];
13
13
  width: number;
14
14
  }[];
15
15
  export declare const getPreviewPosition: (animatedValue: Animated.Value, { width: previewWidth, height: previewHeight }: PreviewDimens, slideBetweenAnimation: boolean, wide: boolean) => {
16
16
  transform: ({
17
- translateX: Animated.AnimatedInterpolation;
17
+ translateX: Animated.AnimatedInterpolation<string | number>;
18
18
  translateY?: undefined;
19
19
  } | {
20
- translateY: Animated.AnimatedInterpolation;
20
+ translateY: Animated.AnimatedInterpolation<string | number>;
21
21
  translateX?: undefined;
22
22
  })[];
23
23
  };
24
24
  export declare const getPreviewScale: (animatedValue: Animated.Value, slideBetweenAnimation: boolean, wide: boolean) => {
25
25
  transform: {
26
- scale: Animated.AnimatedInterpolation;
26
+ scale: Animated.AnimatedInterpolation<string | number>;
27
27
  }[];
28
28
  };
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
+ import { ViewStyle } from 'react-native';
2
3
  export interface Props {
3
4
  index: number;
4
5
  onPress: (id: number) => void;
6
+ style: ViewStyle;
5
7
  }
6
- declare const _default: React.MemoExoticComponent<({ index, onPress }: Props) => JSX.Element>;
8
+ declare const _default: React.MemoExoticComponent<({ index, onPress, style }: Props) => JSX.Element>;
7
9
  export default _default;