@storybook/react-native 6.0.1-alpha.2 → 6.0.1-alpha.7
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/babel.config.js +3 -0
- package/dist/preview/Preview.d.ts +26 -22
- package/dist/preview/Preview.js +69 -75
- package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +20 -24
- package/dist/preview/components/OnDeviceUI/Panel.js +1 -1
- package/dist/preview/components/OnDeviceUI/absolute-positioned-keyboard-aware-view.js +4 -7
- package/dist/preview/components/OnDeviceUI/addons/Addons.js +7 -11
- package/dist/preview/components/OnDeviceUI/addons/List.js +4 -9
- package/dist/preview/components/OnDeviceUI/addons/Wrapper.js +3 -4
- package/dist/preview/components/OnDeviceUI/animation.d.ts +4 -4
- package/dist/preview/components/OnDeviceUI/animation.js +21 -12
- package/dist/preview/components/OnDeviceUI/navigation/Bar.js +4 -11
- package/dist/preview/components/OnDeviceUI/navigation/Button.js +3 -4
- package/dist/preview/components/OnDeviceUI/navigation/Navigation.js +6 -10
- package/dist/preview/components/OnDeviceUI/navigation/VisibilityButton.js +2 -3
- package/dist/preview/components/StoryListView/StoryListView.js +11 -21
- package/dist/preview/components/StoryView/StoryView.js +16 -10
- package/dist/preview/loadCsf.js +22 -21
- package/package.json +31 -13
- package/scripts/__snapshots__/loader.test.js.snap +118 -0
- package/scripts/get-stories.js +3 -1
- package/scripts/handle-args.js +18 -0
- package/scripts/loader.js +80 -65
- package/scripts/loader.test.js +133 -0
- package/scripts/mocks/all-config-files/FakeComponent.tsx +1 -0
- package/scripts/mocks/all-config-files/FakeStory.stories.tsx +10 -0
- package/scripts/mocks/all-config-files/main.js +9 -0
- package/scripts/mocks/all-config-files/preview.js +24 -0
- package/scripts/mocks/blank-config/main.js +4 -0
- package/scripts/mocks/exclude-config-files/exclude-components/FakeComponent.tsx +1 -0
- package/scripts/mocks/exclude-config-files/exclude-components/FakeStory.stories.tsx +10 -0
- package/scripts/mocks/exclude-config-files/include-components/FakeComponent.tsx +1 -0
- package/scripts/mocks/exclude-config-files/include-components/FakeStory.stories.tsx +10 -0
- package/scripts/mocks/exclude-config-files/main.js +12 -0
- package/scripts/mocks/exclude-config-files/preview.js +24 -0
- package/scripts/mocks/no-preview/FakeComponent.tsx +1 -0
- package/scripts/mocks/no-preview/FakeStory.stories.tsx +10 -0
- package/scripts/mocks/no-preview/main.js +9 -0
- package/scripts/watcher.js +48 -15
package/babel.config.js
ADDED
|
@@ -4,27 +4,32 @@ import Channel from '@storybook/channels';
|
|
|
4
4
|
import { ClientApi, ConfigApi, StoryStore } from '@storybook/client-api';
|
|
5
5
|
import { Loadable } from '@storybook/core-client';
|
|
6
6
|
import { theme } from './components/Shared/theme';
|
|
7
|
-
interface
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
interface InitialSelection {
|
|
8
|
+
/**
|
|
9
|
+
* Kind is the default export name or the storiesOf("name") name
|
|
10
|
+
*/
|
|
11
|
+
kind: string;
|
|
12
|
+
/**
|
|
13
|
+
* Name is the named export or the .add("name") name
|
|
14
|
+
*/
|
|
15
|
+
name: string;
|
|
10
16
|
}
|
|
11
17
|
export declare type Params = {
|
|
12
|
-
onDeviceUI
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
keyboardAvoidingViewVerticalOffset: number;
|
|
18
|
+
onDeviceUI?: boolean;
|
|
19
|
+
resetStorybook?: boolean;
|
|
20
|
+
disableWebsockets?: boolean;
|
|
21
|
+
query?: string;
|
|
22
|
+
host?: string;
|
|
23
|
+
port?: number;
|
|
24
|
+
secured?: boolean;
|
|
25
|
+
initialSelection?: InitialSelection;
|
|
26
|
+
shouldPersistSelection?: boolean;
|
|
27
|
+
tabOpen?: number;
|
|
28
|
+
isUIHidden?: boolean;
|
|
29
|
+
shouldDisableKeyboardAvoidingView?: boolean;
|
|
30
|
+
keyboardAvoidingViewVerticalOffset?: number;
|
|
26
31
|
} & {
|
|
27
|
-
theme
|
|
32
|
+
theme?: typeof theme;
|
|
28
33
|
};
|
|
29
34
|
export default class Preview {
|
|
30
35
|
_clientApi: ClientApi;
|
|
@@ -33,18 +38,17 @@ export default class Preview {
|
|
|
33
38
|
_channel: Channel;
|
|
34
39
|
_decorators: any[];
|
|
35
40
|
_asyncStorageStoryId: string;
|
|
36
|
-
_asyncStorage: AsyncStorage | null;
|
|
37
41
|
_configApi: ConfigApi;
|
|
38
42
|
configure: (loadable: Loadable, m: NodeModule, showDeprecationWarning: boolean) => void;
|
|
39
43
|
constructor();
|
|
40
44
|
api: () => ClientApi;
|
|
41
45
|
getStorybookUI: (params?: Partial<Params>) => () => JSX.Element;
|
|
42
|
-
_setInitialStory: (initialSelection
|
|
43
|
-
_getInitialStory: (initialSelection
|
|
46
|
+
_setInitialStory: (initialSelection?: InitialSelection, shouldPersistSelection?: boolean) => Promise<void>;
|
|
47
|
+
_getInitialStory: (initialSelection?: InitialSelection, shouldPersistSelection?: boolean) => Promise<import("@storybook/client-api").PublishedStoreItem>;
|
|
44
48
|
_getStory(storyId: string): import("@storybook/client-api").PublishedStoreItem;
|
|
45
49
|
_selectStoryEvent({ storyId }: {
|
|
46
50
|
storyId: string;
|
|
47
|
-
}): void;
|
|
51
|
+
}, shouldPersistSelection: any): void;
|
|
48
52
|
_selectStory(story: any): void;
|
|
49
53
|
_checkStory(storyId: string): import("@storybook/client-api").PublishedStoreItem;
|
|
50
54
|
}
|
package/dist/preview/Preview.js
CHANGED
|
@@ -1,24 +1,79 @@
|
|
|
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 AsyncStorage from '@react-native-async-storage/async-storage';
|
|
1
11
|
import { addons } from '@storybook/addons';
|
|
2
12
|
import Channel from '@storybook/channels';
|
|
3
13
|
import { ClientApi, ConfigApi, StoryStore } from '@storybook/client-api';
|
|
4
14
|
import Events from '@storybook/core-events';
|
|
15
|
+
import { toId } from '@storybook/csf';
|
|
5
16
|
import { ThemeProvider } from 'emotion-theming';
|
|
6
17
|
import React from 'react';
|
|
7
|
-
import { loadCsf } from './loadCsf';
|
|
8
18
|
import OnDeviceUI from './components/OnDeviceUI';
|
|
9
19
|
import { theme } from './components/Shared/theme';
|
|
20
|
+
import { loadCsf } from './loadCsf';
|
|
10
21
|
const STORAGE_KEY = 'lastOpenedStory';
|
|
11
22
|
export default class Preview {
|
|
12
|
-
_clientApi;
|
|
13
|
-
_storyStore;
|
|
14
|
-
_addons;
|
|
15
|
-
_channel;
|
|
16
|
-
_decorators;
|
|
17
|
-
_asyncStorageStoryId;
|
|
18
|
-
_asyncStorage;
|
|
19
|
-
_configApi;
|
|
20
|
-
configure;
|
|
21
23
|
constructor() {
|
|
24
|
+
this.api = () => {
|
|
25
|
+
return this._clientApi;
|
|
26
|
+
};
|
|
27
|
+
this.getStorybookUI = (params = {}) => {
|
|
28
|
+
const { initialSelection, shouldPersistSelection } = params;
|
|
29
|
+
this._setInitialStory(initialSelection, shouldPersistSelection);
|
|
30
|
+
this._channel.on(Events.SET_CURRENT_STORY, (d) => {
|
|
31
|
+
this._selectStoryEvent(d, shouldPersistSelection);
|
|
32
|
+
});
|
|
33
|
+
const { _storyStore } = this;
|
|
34
|
+
addons.loadAddons(this._clientApi);
|
|
35
|
+
const appliedTheme = Object.assign(Object.assign({}, theme), params.theme);
|
|
36
|
+
return () => (React.createElement(ThemeProvider, { theme: appliedTheme },
|
|
37
|
+
React.createElement(OnDeviceUI, { storyStore: _storyStore, isUIHidden: params.isUIHidden, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset })));
|
|
38
|
+
};
|
|
39
|
+
this._setInitialStory = (initialSelection, shouldPersistSelection = true) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const story = yield this._getInitialStory(initialSelection, shouldPersistSelection);
|
|
41
|
+
if (story) {
|
|
42
|
+
this._selectStory(story);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this._getInitialStory = (initialSelection, shouldPersistSelection = true) => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
let story = null;
|
|
47
|
+
const initialSelectionId = initialSelection
|
|
48
|
+
? toId(initialSelection.kind, initialSelection.name)
|
|
49
|
+
: undefined;
|
|
50
|
+
if (initialSelection && initialSelectionId && this._checkStory(initialSelectionId)) {
|
|
51
|
+
story = initialSelectionId;
|
|
52
|
+
}
|
|
53
|
+
else if (shouldPersistSelection) {
|
|
54
|
+
try {
|
|
55
|
+
let value = this._asyncStorageStoryId;
|
|
56
|
+
if (!value) {
|
|
57
|
+
value = JSON.parse(yield AsyncStorage.getItem(STORAGE_KEY));
|
|
58
|
+
this._asyncStorageStoryId = value;
|
|
59
|
+
}
|
|
60
|
+
if (this._checkStory(value)) {
|
|
61
|
+
story = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
//
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (story) {
|
|
69
|
+
return this._getStory(story);
|
|
70
|
+
}
|
|
71
|
+
const stories = this._storyStore.raw();
|
|
72
|
+
if (stories && stories.length) {
|
|
73
|
+
return this._getStory(stories[0].id);
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
});
|
|
22
77
|
const channel = new Channel({ async: true });
|
|
23
78
|
this._decorators = [];
|
|
24
79
|
this._storyStore = new StoryStore({ channel });
|
|
@@ -33,74 +88,13 @@ export default class Preview {
|
|
|
33
88
|
this.configure = (...args) => configure('react-native', ...args);
|
|
34
89
|
addons.setChannel(channel);
|
|
35
90
|
}
|
|
36
|
-
api = () => {
|
|
37
|
-
return this._clientApi;
|
|
38
|
-
};
|
|
39
|
-
getStorybookUI = (params = {}) => {
|
|
40
|
-
if (params.asyncStorage === undefined) {
|
|
41
|
-
console.warn(`
|
|
42
|
-
Starting Storybook v5.3.0, we require you to manually pass an asyncStorage prop. Pass null to disable or use https://github.com/react-native-async-storage/async-storage.
|
|
43
|
-
|
|
44
|
-
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-native-async-storage
|
|
45
|
-
`.trim());
|
|
46
|
-
}
|
|
47
|
-
if (params.asyncStorage) {
|
|
48
|
-
this._asyncStorage = params.asyncStorage;
|
|
49
|
-
}
|
|
50
|
-
const { initialSelection, shouldPersistSelection } = params;
|
|
51
|
-
this._setInitialStory(initialSelection, shouldPersistSelection);
|
|
52
|
-
this._channel.on(Events.SET_CURRENT_STORY, (d) => {
|
|
53
|
-
this._selectStoryEvent(d);
|
|
54
|
-
});
|
|
55
|
-
const { _storyStore } = this;
|
|
56
|
-
addons.loadAddons(this._clientApi);
|
|
57
|
-
const appliedTheme = { ...theme, ...params.theme };
|
|
58
|
-
return () => (<ThemeProvider theme={appliedTheme}>
|
|
59
|
-
<OnDeviceUI storyStore={_storyStore} isUIHidden={params.isUIHidden} tabOpen={params.tabOpen} shouldDisableKeyboardAvoidingView={params.shouldDisableKeyboardAvoidingView} keyboardAvoidingViewVerticalOffset={params.keyboardAvoidingViewVerticalOffset}/>
|
|
60
|
-
</ThemeProvider>);
|
|
61
|
-
};
|
|
62
|
-
_setInitialStory = async (initialSelection, shouldPersistSelection = true) => {
|
|
63
|
-
const story = await this._getInitialStory(initialSelection, shouldPersistSelection);
|
|
64
|
-
if (story) {
|
|
65
|
-
this._selectStory(story);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
_getInitialStory = async (initialSelection, shouldPersistSelection = true) => {
|
|
69
|
-
let story = null;
|
|
70
|
-
if (initialSelection && this._checkStory(initialSelection)) {
|
|
71
|
-
story = initialSelection;
|
|
72
|
-
}
|
|
73
|
-
else if (shouldPersistSelection) {
|
|
74
|
-
try {
|
|
75
|
-
let value = this._asyncStorageStoryId;
|
|
76
|
-
if (!value && this._asyncStorage) {
|
|
77
|
-
value = JSON.parse(await this._asyncStorage.getItem(STORAGE_KEY));
|
|
78
|
-
this._asyncStorageStoryId = value;
|
|
79
|
-
}
|
|
80
|
-
if (this._checkStory(value)) {
|
|
81
|
-
story = value;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
//
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (story) {
|
|
89
|
-
return this._getStory(story);
|
|
90
|
-
}
|
|
91
|
-
const stories = this._storyStore.raw();
|
|
92
|
-
if (stories && stories.length) {
|
|
93
|
-
return this._getStory(stories[0].id);
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
};
|
|
97
91
|
_getStory(storyId) {
|
|
98
92
|
return this._storyStore.fromId(storyId);
|
|
99
93
|
}
|
|
100
|
-
_selectStoryEvent({ storyId }) {
|
|
94
|
+
_selectStoryEvent({ storyId }, shouldPersistSelection) {
|
|
101
95
|
if (storyId) {
|
|
102
|
-
if (
|
|
103
|
-
|
|
96
|
+
if (shouldPersistSelection) {
|
|
97
|
+
AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(storyId)).catch(() => { });
|
|
104
98
|
}
|
|
105
99
|
const story = this._getStory(storyId);
|
|
106
100
|
this._selectStory(story);
|
|
@@ -115,7 +109,7 @@ export default class Preview {
|
|
|
115
109
|
return null;
|
|
116
110
|
}
|
|
117
111
|
const story = this._getStory(storyId);
|
|
118
|
-
if (story.storyFn === null) {
|
|
112
|
+
if (story === null || story.storyFn === null) {
|
|
119
113
|
return null;
|
|
120
114
|
}
|
|
121
115
|
return story;
|
|
@@ -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,
|
|
@@ -36,7 +38,8 @@ const styles = StyleSheet.create({
|
|
|
36
38
|
expoAndroidContainer: { paddingTop: StatusBar.currentHeight },
|
|
37
39
|
});
|
|
38
40
|
const useSelectedStory = (storyStore) => {
|
|
39
|
-
|
|
41
|
+
var _a;
|
|
42
|
+
const [storyId, setStoryId] = useState(((_a = storyStore.getSelection()) === null || _a === void 0 ? void 0 : _a.storyId) || '');
|
|
40
43
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
41
44
|
const channel = useRef(addons.getChannel());
|
|
42
45
|
useEffect(() => {
|
|
@@ -61,6 +64,7 @@ const OnDeviceUI = ({ storyStore, isUIHidden, shouldDisableKeyboardAvoidingView,
|
|
|
61
64
|
});
|
|
62
65
|
const story = useSelectedStory(storyStore);
|
|
63
66
|
const animatedValue = useRef(new Animated.Value(tabOpen));
|
|
67
|
+
const wide = useWindowDimensions().width >= BREAKPOINT;
|
|
64
68
|
const handleToggleTab = (newTabOpen) => {
|
|
65
69
|
if (newTabOpen === tabOpen) {
|
|
66
70
|
return;
|
|
@@ -80,29 +84,21 @@ const OnDeviceUI = ({ storyStore, isUIHidden, shouldDisableKeyboardAvoidingView,
|
|
|
80
84
|
};
|
|
81
85
|
const previewWrapperStyles = [
|
|
82
86
|
flex,
|
|
83
|
-
getPreviewPosition(animatedValue.current, previewDimensions, slideBetweenAnimation),
|
|
87
|
+
getPreviewPosition(animatedValue.current, previewDimensions, slideBetweenAnimation, wide),
|
|
84
88
|
];
|
|
85
|
-
const previewStyles = [flex, getPreviewScale(animatedValue.current, slideBetweenAnimation)];
|
|
86
|
-
return (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
</Panel>
|
|
100
|
-
<Panel style={getAddonPanelPosition(animatedValue.current, previewDimensions.width)}>
|
|
101
|
-
<Addons active={tabOpen === ADDONS}/>
|
|
102
|
-
</Panel>
|
|
103
|
-
</AbsolutePositionedKeyboardAwareView>
|
|
104
|
-
<Navigation tabOpen={tabOpen} onChangeTab={handleToggleTab} initialUiVisible={!isUIHidden}/>
|
|
105
|
-
</KeyboardAvoidingView>
|
|
106
|
-
</SafeAreaView>);
|
|
89
|
+
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 }))));
|
|
107
103
|
};
|
|
108
104
|
export default React.memo(OnDeviceUI);
|
|
@@ -4,5 +4,5 @@ import styled from '@emotion/native';
|
|
|
4
4
|
const Container = styled(Animated.View)(({ theme }) => ({
|
|
5
5
|
backgroundColor: theme.backgroundColor || 'white',
|
|
6
6
|
}));
|
|
7
|
-
const Panel = ({ children, style }) => (
|
|
7
|
+
const Panel = ({ children, style }) => (React.createElement(Container, { style: [StyleSheet.absoluteFillObject, ...style] }, children));
|
|
8
8
|
export default React.memo(Panel);
|
|
@@ -9,13 +9,10 @@ const AbsolutePositionedKeyboardAwareView = ({ onLayout, previewDimensions: { wi
|
|
|
9
9
|
width: nativeEvent.layout.width,
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
-
return (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{children}
|
|
17
|
-
</View>
|
|
18
|
-
</View>);
|
|
12
|
+
return (React.createElement(View, { style: styles.container, onLayout: onLayoutHandler },
|
|
13
|
+
React.createElement(View, { style: width === 0
|
|
14
|
+
? styles.container
|
|
15
|
+
: [styles.absolute, { position: 'absolute', width, height }] }, children)));
|
|
19
16
|
};
|
|
20
17
|
const styles = StyleSheet.create({
|
|
21
18
|
absolute: { position: 'absolute' },
|
|
@@ -18,18 +18,14 @@ const Addons = ({ active }) => {
|
|
|
18
18
|
const panels = addons.getElements('panel');
|
|
19
19
|
const [addonSelected, setAddonSelected] = useState(Object.keys(panels)[0] || null);
|
|
20
20
|
if (Object.keys(panels).length === 0) {
|
|
21
|
-
return (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
</NoAddonContainer>
|
|
25
|
-
</SafeAreaView>);
|
|
21
|
+
return (React.createElement(SafeAreaView, { style: styles.container },
|
|
22
|
+
React.createElement(NoAddonContainer, null,
|
|
23
|
+
React.createElement(Label, null, "No addons loaded."))));
|
|
26
24
|
}
|
|
27
|
-
return (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
</SafeAreaView>
|
|
32
|
-
</Container>);
|
|
25
|
+
return (React.createElement(Container, null,
|
|
26
|
+
React.createElement(SafeAreaView, { style: styles.container },
|
|
27
|
+
React.createElement(AddonsList, { onPressAddon: setAddonSelected, panels: panels, addonSelected: active ? addonSelected : null }),
|
|
28
|
+
React.createElement(AddonWrapper, { addonSelected: active ? addonSelected : null, panels: panels }))));
|
|
33
29
|
};
|
|
34
30
|
const styles = StyleSheet.create({
|
|
35
31
|
container: { flex: 1 },
|
|
@@ -9,17 +9,12 @@ const Container = styled.View(({ theme }) => ({
|
|
|
9
9
|
}));
|
|
10
10
|
const AddonList = ({ panels, addonSelected, onPressAddon }) => {
|
|
11
11
|
const addonKeys = Object.keys(panels);
|
|
12
|
-
const renderTab = (id, title) => (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return (<Container>
|
|
16
|
-
<ScrollView showsHorizontalScrollIndicator={false} horizontal>
|
|
17
|
-
{addonKeys.map((id) => {
|
|
12
|
+
const renderTab = (id, title) => (React.createElement(Button, { active: id === addonSelected, key: id, id: id, onPress: () => onPressAddon(id) }, title.toUpperCase()));
|
|
13
|
+
return (React.createElement(Container, null,
|
|
14
|
+
React.createElement(ScrollView, { showsHorizontalScrollIndicator: false, horizontal: true }, addonKeys.map((id) => {
|
|
18
15
|
const { title } = panels[id];
|
|
19
16
|
const resolvedTitle = typeof title === 'function' ? title() : title;
|
|
20
17
|
return renderTab(id, resolvedTitle);
|
|
21
|
-
})
|
|
22
|
-
</ScrollView>
|
|
23
|
-
</Container>);
|
|
18
|
+
}))));
|
|
24
19
|
};
|
|
25
20
|
export default React.memo(AddonList);
|
|
@@ -15,10 +15,9 @@ const Wrapper = ({ panels, addonSelected }) => {
|
|
|
15
15
|
const addonKeys = Object.keys(panels);
|
|
16
16
|
const content = addonKeys.map((id) => {
|
|
17
17
|
const selected = addonSelected === id;
|
|
18
|
-
return (
|
|
19
|
-
|
|
20
|
-
</View>);
|
|
18
|
+
return (React.createElement(View, { key: id, style: selected ? style.flex : style.invisible },
|
|
19
|
+
React.createElement(ScrollView, null, panels[id].render({ active: selected, key: id }))));
|
|
21
20
|
});
|
|
22
|
-
return
|
|
21
|
+
return React.createElement(React.Fragment, null, content);
|
|
23
22
|
};
|
|
24
23
|
export default React.memo(Wrapper);
|
|
@@ -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
|
|
4
|
-
|
|
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
|
|
36
|
-
const
|
|
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: [
|
|
69
|
+
outputRange: [scale, slideBetweenAnimation ? scale : 1, scale],
|
|
61
70
|
}),
|
|
62
71
|
},
|
|
63
72
|
],
|
|
@@ -10,15 +10,8 @@ const Container = styled.View(({ theme }) => ({
|
|
|
10
10
|
borderBottomWidth: 1,
|
|
11
11
|
borderColor: theme.borderColor || '#e6e6e6',
|
|
12
12
|
}));
|
|
13
|
-
const Bar = ({ index, onPress }) => (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<Button onPress={onPress} testID="BottomMenu.Preview" id={PREVIEW} active={index === PREVIEW}>
|
|
18
|
-
PREVIEW
|
|
19
|
-
</Button>
|
|
20
|
-
<Button onPress={onPress} testID="BottomMenu.Addons" id={ADDONS} active={index === ADDONS}>
|
|
21
|
-
ADDONS
|
|
22
|
-
</Button>
|
|
23
|
-
</Container>);
|
|
13
|
+
const Bar = ({ index, onPress }) => (React.createElement(Container, null,
|
|
14
|
+
React.createElement(Button, { onPress: onPress, testID: "BottomMenu.Navigator", id: NAVIGATOR, active: index === NAVIGATOR }, "NAVIGATOR"),
|
|
15
|
+
React.createElement(Button, { onPress: onPress, testID: "BottomMenu.Preview", id: PREVIEW, active: index === PREVIEW }, "PREVIEW"),
|
|
16
|
+
React.createElement(Button, { onPress: onPress, testID: "BottomMenu.Addons", id: ADDONS, active: index === ADDONS }, "ADDONS")));
|
|
24
17
|
export default React.memo(Bar);
|
|
@@ -11,8 +11,7 @@ const ButtonText = styled.Text(({ theme, active }) => ({
|
|
|
11
11
|
paddingVertical: 10,
|
|
12
12
|
fontSize: 11,
|
|
13
13
|
}));
|
|
14
|
-
const Button = ({ onPress, id, active, children, testID }) => (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
</TouchableOpacity>);
|
|
14
|
+
const Button = ({ onPress, id, active, children, testID }) => (React.createElement(TouchableOpacity, { testID: testID, onPress: () => onPress(id), activeOpacity: 0.8 },
|
|
15
|
+
React.createElement(ButtonText, { active: active }, children),
|
|
16
|
+
React.createElement(ActiveBorder, { active: active })));
|
|
18
17
|
export default React.memo(Button);
|
|
@@ -22,15 +22,11 @@ const Navigation = ({ tabOpen, onChangeTab, initialUiVisible }) => {
|
|
|
22
22
|
onChangeTab(tabOpen - 1);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
return (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<VisibilityButton onPress={handleToggleUI}/>
|
|
32
|
-
</View>
|
|
33
|
-
</SafeAreaView>
|
|
34
|
-
</View>);
|
|
25
|
+
return (React.createElement(View, null,
|
|
26
|
+
React.createElement(SafeAreaView, null,
|
|
27
|
+
isUIVisible && (React.createElement(GestureRecognizer, { onSwipeLeft: handleSwipeLeft, onSwipeRight: handleSwipeRight, config: SWIPE_CONFIG },
|
|
28
|
+
React.createElement(Bar, { index: tabOpen, onPress: onChangeTab }))),
|
|
29
|
+
React.createElement(View, null,
|
|
30
|
+
React.createElement(VisibilityButton, { onPress: handleToggleUI })))));
|
|
35
31
|
};
|
|
36
32
|
export default React.memo(Navigation);
|
|
@@ -11,7 +11,6 @@ const HideIcon = styled.Text(({ theme }) => ({
|
|
|
11
11
|
fontSize: 14,
|
|
12
12
|
color: theme.buttonTextColor || '#999999',
|
|
13
13
|
}));
|
|
14
|
-
const VisibilityButton = ({ onPress }) => (
|
|
15
|
-
|
|
16
|
-
</Touchable>);
|
|
14
|
+
const VisibilityButton = ({ onPress }) => (React.createElement(Touchable, { onPress: onPress, testID: "Storybook.OnDeviceUI.toggleUI", accessibilityLabel: "Storybook.OnDeviceUI.toggleUI", hitSlop: { top: 5, left: 5, bottom: 5, right: 5 } },
|
|
15
|
+
React.createElement(HideIcon, null, "\u25A1")));
|
|
17
16
|
export default React.memo(VisibilityButton);
|