Skip to content

Commit 21abec9

Browse files
committed
fix: improve loading bottom sheet by using non modal version
1 parent 9404dd2 commit 21abec9

File tree

3 files changed

+91
-32
lines changed

3 files changed

+91
-32
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
const template = (num: number) => `import { Meta, StoryObj } from '@storybook/react'
5+
import { View } from 'react-native'
6+
7+
const Test${num} = () => {
8+
return <View style={{ flex: 1, backgroundColor: 'red' }} />
9+
}
10+
11+
const meta: Meta<typeof Test${num}> = {
12+
title: 'PerfTesting/Test${num}',
13+
component: Test${num},
14+
}
15+
16+
export default meta
17+
18+
export const Default: StoryObj<typeof Test${num}> = {}
19+
export const one: StoryObj<typeof Test${num}> = {}
20+
export const two: StoryObj<typeof Test${num}> = {}
21+
export const three: StoryObj<typeof Test${num}> = {}
22+
export const four: StoryObj<typeof Test${num}> = {}
23+
export const five: StoryObj<typeof Test${num}> = {}
24+
export const six: StoryObj<typeof Test${num}> = {}
25+
export const seven: StoryObj<typeof Test${num}> = {}
26+
export const eight: StoryObj<typeof Test${num}> = {}
27+
export const nine: StoryObj<typeof Test${num}> = {}
28+
export const ten: StoryObj<typeof Test${num}> = {}
29+
export const eleven: StoryObj<typeof Test${num}> = {}
30+
export const twelve: StoryObj<typeof Test${num}> = {}
31+
export const thirteen: StoryObj<typeof Test${num}> = {}
32+
export const fourteen: StoryObj<typeof Test${num}> = {}
33+
export const fifteen: StoryObj<typeof Test${num}> = {}
34+
export const sixteen: StoryObj<typeof Test${num}> = {}
35+
export const seventeen: StoryObj<typeof Test${num}> = {}
36+
export const eighteen: StoryObj<typeof Test${num}> = {}
37+
export const nineteen: StoryObj<typeof Test${num}> = {}`;
38+
39+
const generateFiles = () => {
40+
const baseDir = path.join(__dirname, '../components/PerfTesting');
41+
42+
// Create directory if it doesn't exist
43+
if (!fs.existsSync(baseDir)) {
44+
fs.mkdirSync(baseDir, { recursive: true });
45+
}
46+
47+
// Generate files from Test11 to Test50 (since Test1-10 already exist)
48+
for (let i = 1; i <= 200; i++) {
49+
const fileName = `Test${i}.stories.tsx`;
50+
const filePath = path.join(baseDir, fileName);
51+
52+
fs.writeFileSync(filePath, template(i));
53+
console.log(`Generated ${fileName}`);
54+
}
55+
};
56+
57+
generateFiles();

packages/react-native-ui/src/Layout.tsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -169,30 +169,6 @@ export const Layout = ({
169169
)}
170170
</View>
171171

172-
<MobileMenuDrawer ref={mobileMenuDrawerRef}>
173-
<View style={{ paddingLeft: 16, paddingTop: 4, paddingBottom: 4 }}>
174-
<StorybookLogo theme={theme} />
175-
</View>
176-
177-
<Sidebar
178-
extra={[]}
179-
previewInitialized
180-
indexError={undefined}
181-
refs={{}}
182-
setSelection={({ storyId: newStoryId }) => {
183-
const channel = addons.getChannel();
184-
185-
channel.emit(SET_CURRENT_STORY, { storyId: newStoryId });
186-
}}
187-
status={{}}
188-
index={storyHash}
189-
storyId={story?.id}
190-
refId={DEFAULT_REF_ID}
191-
/>
192-
</MobileMenuDrawer>
193-
194-
<MobileAddonsPanel ref={addonPanelRef} storyId={story?.id} />
195-
196172
{!uiHidden ? (
197173
<Container style={{ marginBottom: insets.bottom }}>
198174
<Nav>
@@ -218,6 +194,30 @@ export const Layout = ({
218194
</Nav>
219195
</Container>
220196
) : null}
197+
198+
<MobileMenuDrawer ref={mobileMenuDrawerRef}>
199+
<View style={{ paddingLeft: 16, paddingTop: 4, paddingBottom: 4 }}>
200+
<StorybookLogo theme={theme} />
201+
</View>
202+
203+
<Sidebar
204+
extra={[]}
205+
previewInitialized
206+
indexError={undefined}
207+
refs={{}}
208+
setSelection={({ storyId: newStoryId }) => {
209+
const channel = addons.getChannel();
210+
211+
channel.emit(SET_CURRENT_STORY, { storyId: newStoryId });
212+
}}
213+
status={{}}
214+
index={storyHash}
215+
storyId={story?.id}
216+
refId={DEFAULT_REF_ID}
217+
/>
218+
</MobileMenuDrawer>
219+
220+
<MobileAddonsPanel ref={addonPanelRef} storyId={story?.id} />
221221
</View>
222222
);
223223
};

packages/react-native-ui/src/MobileMenuDrawer.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {
1+
import BottomSheet, {
22
BottomSheetBackdrop,
33
BottomSheetBackdropProps,
44
BottomSheetModal,
@@ -39,28 +39,30 @@ export const MobileMenuDrawer = forwardRef<MobileMenuDrawerRef, MobileMenuDrawer
3939
useImperativeHandle(ref, () => ({
4040
setMobileMenuOpen: (open: boolean) => {
4141
if (open) {
42-
menuBottomSheetRef.current?.present();
42+
// menuBottomSheetRef.current?.present();
43+
menuBottomSheetRef.current?.expand();
4344
} else {
4445
Keyboard.dismiss();
4546

46-
menuBottomSheetRef.current?.dismiss();
47+
// menuBottomSheetRef.current?.dismiss();
48+
menuBottomSheetRef.current?.close();
4749
}
4850
},
4951
}));
5052

5153
return (
52-
<BottomSheetModal
54+
<BottomSheet
5355
ref={menuBottomSheetRef}
54-
index={1}
56+
index={-1}
5557
animateOnMount={!reducedMotion}
5658
snapPoints={['50%', '75%']}
57-
enableDismissOnClose
59+
// enableDismissOnClose
5860
enableHandlePanningGesture
5961
enableContentPanningGesture
6062
enableDynamicSizing={false}
6163
keyboardBehavior="extend"
6264
keyboardBlurBehavior="restore"
63-
stackBehavior="replace"
65+
// stackBehavior="replace"
6466
backdropComponent={BottomSheetBackdropComponent}
6567
backgroundStyle={{ backgroundColor: theme.background.content }}
6668
handleIndicatorStyle={{ backgroundColor: theme.textMutedColor }}
@@ -73,7 +75,7 @@ export const MobileMenuDrawer = forwardRef<MobileMenuDrawerRef, MobileMenuDrawer
7375
>
7476
{children}
7577
</BottomSheetScrollView>
76-
</BottomSheetModal>
78+
</BottomSheet>
7779
);
7880
}
7981
);

0 commit comments

Comments
 (0)