Skip to content

Commit 262baec

Browse files
committed
mc
Signed-off-by: Simon Bruneaud <[email protected]>
1 parent 4d72ff1 commit 262baec

File tree

16 files changed

+394
-97
lines changed

16 files changed

+394
-97
lines changed

libs/ui-rnative/.storybook/Decorator.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { ThemeProvider } from '@ledgerhq/ldls-ui-rnative';
12
import type { Decorator } from '@storybook/react-native-web-vite';
3+
import { GestureHandlerRootView } from 'react-native-gesture-handler';
24

35
const createThemeDecorator = (
46
globalName: string,
@@ -28,3 +30,13 @@ export const withModeDecorator = createThemeDecorator('mode', [
2830
'light',
2931
'dark',
3032
]);
33+
34+
export const withProvidersDecorator: Decorator = (Story, context) => {
35+
return (
36+
<ThemeProvider>
37+
<GestureHandlerRootView style={{ flex: 1, width: '100%' }}>
38+
<Story />
39+
</GestureHandlerRootView>
40+
</ThemeProvider>
41+
);
42+
};
File renamed without changes.

libs/ui-rnative/.storybook/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const config: StorybookConfig = {
1717
},
1818
},
1919
},
20+
typescript: {
21+
reactDocgen: 'react-docgen-typescript',
22+
},
2023

2124
viteFinal: async (config) => {
2225
config.resolve = config.resolve || {};

libs/ui-rnative/.storybook/preview.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type { Preview } from '@storybook/react-native-web-vite';
22
import '../src/styles.css';
33
import './font.css';
4-
import { withBrandDecorator, withModeDecorator } from './Decorator';
4+
import {
5+
withBrandDecorator,
6+
withModeDecorator,
7+
withProvidersDecorator,
8+
} from './Decorator';
59

610
const preview: Preview = {
711
globalTypes: {
@@ -60,6 +64,7 @@ const preview: Preview = {
6064
],
6165
},
6266
},
67+
tags: ['autodocs'],
6368
actions: { argTypesRegex: '^on[A-Z].*' },
6469
controls: {
6570
matchers: {
@@ -69,7 +74,7 @@ const preview: Preview = {
6974
},
7075
},
7176

72-
decorators: [withBrandDecorator, withModeDecorator],
77+
decorators: [withBrandDecorator, withModeDecorator, withProvidersDecorator],
7378
};
7479

7580
export default preview;

libs/ui-rnative/.storybook/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ThemeVars } from 'storybook/theming';
22
import { create } from 'storybook/theming/create';
3-
import logoUrl from './lumen.svg';
3+
import logoUrl from './docs/lumen.svg';
44

55
const theme: ThemeVars = create({
66
base: 'light',

libs/ui-rnative/src/lib/Components/BottomSheet/BottomSheet.stories.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { Meta, StoryObj } from '@storybook/react-vite';
2-
import { Text, View } from 'react-native';
2+
import { View, Text } from 'react-native';
33
import { Button } from '../Button';
44
import { BottomSheet } from './BottomSheet';
55
import { BottomSheetHeader } from './BottomSheetHeader';
6+
import { BottomSheetScrollView, BottomSheetView } from './Scrollables';
67
import { useBottomSheetRef } from './useBottomSheetRef';
78

89
const meta: Meta<typeof BottomSheet> = {
910
component: BottomSheet,
10-
title: 'Communication/BottomSheet',
11+
title: 'Containment/BottomSheet',
1112
parameters: {
1213
docs: {
1314
source: {
@@ -17,28 +18,37 @@ const meta: Meta<typeof BottomSheet> = {
1718
},
1819
},
1920
},
20-
argTypes: {},
2121
};
2222

2323
export default meta;
2424
type Story = StoryObj<typeof BottomSheet>;
2525

2626
export const Base: Story = {
27-
args: {},
27+
args: {
28+
size: 'sm',
29+
enableHandlePanningGesture: true,
30+
enablePanDownToClose: true,
31+
closeable: false,
32+
onBack: () => null,
33+
onClose: () => null,
34+
},
2835
render: (args) => {
2936
const bottomSheetRef = useBottomSheetRef();
3037

3138
return (
32-
<View className='m-auto h-screen max-w-md items-center justify-center'>
39+
<View className='h-[calc(100vh-40px)] w-full items-center justify-center'>
3340
<Button size='xs' onPress={() => bottomSheetRef.current?.expand()}>
3441
Toggle open
3542
</Button>
3643
<BottomSheet {...args} ref={bottomSheetRef}>
37-
<BottomSheetHeader
38-
title='Title'
39-
description='Description'
40-
onClose={() => bottomSheetRef.current?.close()}
41-
/>
44+
<BottomSheetView>
45+
<BottomSheetHeader title='Title' description='Description' />
46+
</BottomSheetView>
47+
<BottomSheetScrollView>
48+
{Array.from({ length: 100 }).map((_, index) => (
49+
<Text key={index}>azeazea</Text>
50+
))}
51+
</BottomSheetScrollView>
4252
</BottomSheet>
4353
</View>
4454
);
Lines changed: 73 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,90 @@
11
import GorghomBottomSheet from '@gorhom/bottom-sheet';
22
import { createSafeContext, useMergedRef } from '@ledgerhq/ldls-utils-shared';
3-
import { forwardRef, useCallback, useEffect, useMemo, useRef } from 'react';
3+
import { forwardRef, useMemo, useRef } from 'react';
44
import { StyleSheet } from 'react-native';
5-
import { GestureHandlerRootView } from 'react-native-gesture-handler';
6-
75
import { BottomSheetProps } from './BottomSheet.types';
6+
import { BottomSheetHeaderActions } from './BottomSheetActions';
7+
import { HandleComponent } from './HandleComponent';
88

9-
const [BottomSheetProvider, useBottomSheetContext] =
10-
createSafeContext<BottomSheetProps>('BottomSheet');
9+
const styles = StyleSheet.create({
10+
container: {
11+
flex: 1,
12+
width: '100%',
13+
},
14+
});
15+
16+
const bottomSheetSnapPoints = {
17+
full: ['100%'],
18+
half: ['50%'],
19+
quarter: ['25%'],
20+
};
21+
22+
const [BottomSheetProvider, useBottomSheetContext] = createSafeContext<{
23+
size: BottomSheetProps['size'];
24+
}>('BottomSheet');
1125

12-
export const BottomSheet = forwardRef<
26+
const BottomSheet = forwardRef<
1327
React.ElementRef<typeof GorghomBottomSheet>,
1428
BottomSheetProps
15-
>(({ children, ...props }, ref) => {
16-
// ref
17-
const innerRef = useRef<GorghomBottomSheet>(null);
18-
const mergedRefs = useMergedRef<GorghomBottomSheet>(ref, innerRef);
19-
20-
// callbacks
21-
const handleSheetChanges = useCallback((index: number) => {
22-
console.log('handleSheetChanges', index);
23-
}, []);
24-
25-
useEffect(() => {
26-
innerRef.current?.expand();
27-
}, []);
28-
29-
const snapPoints = useMemo(() => ['25%', '50%'], []);
30-
31-
// renders
32-
return (
33-
<GestureHandlerRootView style={styles.container}>
34-
<BottomSheetProvider value={props}>
29+
>(
30+
(
31+
{
32+
onClose,
33+
onBack,
34+
closeable,
35+
children,
36+
enablePanDownToClose = true,
37+
enableHandlePanningGesture = true,
38+
detached = false,
39+
onChange,
40+
snapPoints = 'half',
41+
size = 'sm',
42+
...props
43+
},
44+
ref,
45+
) => {
46+
// ref
47+
const innerRef = useRef<GorghomBottomSheet>(null);
48+
const mergedRefs = useMergedRef<GorghomBottomSheet>(ref, innerRef);
49+
50+
const computedSnapPoints = useMemo(() => {
51+
const isString = typeof snapPoints === 'string';
52+
53+
return isString
54+
? bottomSheetSnapPoints[
55+
snapPoints as keyof typeof bottomSheetSnapPoints
56+
]
57+
: snapPoints;
58+
}, [snapPoints]);
59+
60+
// renders
61+
return (
62+
<BottomSheetProvider value={{ size }}>
3563
<GorghomBottomSheet
64+
{...props}
3665
ref={mergedRefs}
66+
style={styles.container}
3767
overDragResistanceFactor={2.5}
38-
enableHandlePanningGesture
39-
enablePanDownToClose
40-
snapPoints={snapPoints}
41-
onChange={handleSheetChanges}
68+
enableDynamicSizing={false}
69+
detached={detached}
70+
enableHandlePanningGesture={enableHandlePanningGesture}
71+
enablePanDownToClose={enablePanDownToClose}
72+
snapPoints={computedSnapPoints}
73+
onChange={onChange}
74+
handleComponent={HandleComponent}
4275
index={-1}
4376
>
77+
<BottomSheetHeaderActions
78+
onBack={onBack}
79+
onClose={onClose}
80+
closeable={closeable}
81+
/>
4482
{children}
4583
</GorghomBottomSheet>
4684
</BottomSheetProvider>
47-
</GestureHandlerRootView>
48-
);
49-
});
50-
51-
const styles = StyleSheet.create({
52-
container: {
53-
flex: 1,
54-
width: '100%',
55-
},
56-
contentContainer: {
57-
flex: 1,
58-
padding: 36,
59-
height: 120,
85+
);
6086
},
61-
});
87+
);
88+
BottomSheet.displayName = 'BottomSheet';
89+
90+
export { BottomSheet, useBottomSheetContext };

libs/ui-rnative/src/lib/Components/BottomSheet/BottomSheet.types.ts

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
1+
import { BottomSheetProps as GorhomBottomSheetProps } from '@gorhom/bottom-sheet';
12
import { PropsWithChildren, ReactNode } from 'react';
2-
import { ViewProps } from 'react-native-svg/lib/typescript/fabric/utils';
3+
import { ViewProps } from 'react-native';
4+
5+
export type BottomSheetProps = PropsWithChildren & {
6+
/**
7+
* The callback function to handle the back event.
8+
*/
9+
onBack?: () => void;
10+
/**
11+
* If true, the close button will be displayed.
12+
* This property should be used when no callback is required for the close action.
13+
* @default false
14+
*/
15+
closeable?: boolean;
16+
/**
17+
* If true, the close button will be displayed
18+
* This property should be used when a callback function to handle the close event is required.
19+
* @default false
20+
*/
21+
onClose?: () => void;
22+
/**
23+
* The size variant of the bottom sheet.
24+
* @default 'sm'
25+
*/
26+
size?: 'sm' | 'lg';
27+
/**
28+
* The snap points of the bottom sheet.
29+
*/
30+
snapPoints?: 'full' | 'half' | 'quarter' | string[] | number[];
31+
/**
32+
* Whether to enable handle panning gesture.
33+
* If true, the whole sheet area can be dragged to resize the sheet.
34+
* @default false
35+
*/
36+
enableHandlePanningGesture?: boolean;
37+
/**
38+
* Whether to enable pan down to close.
39+
* If true, the sheet can be closed by dragging down.
40+
* @default true
41+
*/
42+
enablePanDownToClose?: boolean;
43+
/**
44+
* Defines whether the bottom sheet is attached to the bottom or no.
45+
* @default false
46+
*/
47+
detached?: boolean;
48+
/**
49+
* The callback function to handle the change event.
50+
* @default undefined
51+
*/
52+
onChange?: GorhomBottomSheetProps['onChange'];
53+
};
54+
55+
export type BottomSheetHeaderActionsProps = ViewProps &
56+
Pick<BottomSheetProps, 'closeable' | 'onClose' | 'onBack'>;
357

458
export type BottomSheetHeaderProps = ViewProps & {
559
/**
@@ -15,9 +69,15 @@ export type BottomSheetHeaderProps = ViewProps & {
1569
*/
1670
onBack?: () => void;
1771
/**
18-
* The callback function to handle the close event.
72+
* If true, the close button will be displayed.
73+
* This property should be used when no callback is required for the close action.
74+
* @default false
75+
*/
76+
closeable?: boolean;
77+
/**
78+
* If true, the close button will be displayed
79+
* This property should be used when a callback function to handle the close event is required.
80+
* @default false
1981
*/
2082
onClose?: () => void;
2183
};
22-
23-
export type BottomSheetProps = PropsWithChildren & {};

0 commit comments

Comments
 (0)