@ledgerhq/lumen-ui-rnative 0.1.52 → 0.1.53
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/module/index.js +1 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/Components/BottomSheet/BottomSheet.js +4 -1
- package/dist/module/lib/Components/BottomSheet/BottomSheet.js.map +1 -1
- package/dist/module/lib/Components/BottomSheet/BottomSheet.mdx +133 -2
- package/dist/module/lib/Components/BottomSheet/BottomSheet.stories.js +114 -7
- package/dist/module/lib/Components/BottomSheet/BottomSheet.stories.js.map +1 -1
- package/dist/module/lib/Components/BottomSheet/BottomSheet.test.js +150 -1
- package/dist/module/lib/Components/BottomSheet/BottomSheet.test.js.map +1 -1
- package/dist/module/lib/Components/BottomSheet/BottomSheetContent.js +35 -0
- package/dist/module/lib/Components/BottomSheet/BottomSheetContent.js.map +1 -0
- package/dist/module/lib/Components/BottomSheet/BottomSheetFooter.js +43 -0
- package/dist/module/lib/Components/BottomSheet/BottomSheetFooter.js.map +1 -0
- package/dist/module/lib/Components/BottomSheet/Scrollables.js +18 -3
- package/dist/module/lib/Components/BottomSheet/Scrollables.js.map +1 -1
- package/dist/module/lib/Components/BottomSheet/index.js +2 -0
- package/dist/module/lib/Components/BottomSheet/index.js.map +1 -1
- package/dist/typescript/src/index.d.ts +1 -1
- package/dist/typescript/src/index.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/BottomSheet/BottomSheet.d.ts +8 -1
- package/dist/typescript/src/lib/Components/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/BottomSheet/BottomSheetContent.d.ts +3 -0
- package/dist/typescript/src/lib/Components/BottomSheet/BottomSheetContent.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/BottomSheet/BottomSheetFooter.d.ts +3 -0
- package/dist/typescript/src/lib/Components/BottomSheet/BottomSheetFooter.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/BottomSheet/Scrollables.d.ts +1 -0
- package/dist/typescript/src/lib/Components/BottomSheet/Scrollables.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/BottomSheet/index.d.ts +2 -0
- package/dist/typescript/src/lib/Components/BottomSheet/index.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/BottomSheet/types.d.ts +2 -0
- package/dist/typescript/src/lib/Components/BottomSheet/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/lib/Components/BottomSheet/BottomSheet.mdx +133 -2
- package/src/lib/Components/BottomSheet/BottomSheet.stories.tsx +111 -5
- package/src/lib/Components/BottomSheet/BottomSheet.test.tsx +140 -0
- package/src/lib/Components/BottomSheet/BottomSheet.tsx +25 -9
- package/src/lib/Components/BottomSheet/BottomSheetContent.tsx +44 -0
- package/src/lib/Components/BottomSheet/BottomSheetFooter.tsx +47 -0
- package/src/lib/Components/BottomSheet/Scrollables.tsx +25 -12
- package/src/lib/Components/BottomSheet/index.ts +2 -0
- package/src/lib/Components/BottomSheet/types.ts +2 -1
|
@@ -24,7 +24,8 @@ BottomSheet provides a flexible and performant way to present content, forms, or
|
|
|
24
24
|
- **Handle**: Visual indicator for draggable area
|
|
25
25
|
- **Backdrop**: Semi-transparent overlay behind the sheet
|
|
26
26
|
- **Header**: Optional header with title, description, back button, and close button
|
|
27
|
-
- **Content**: Scrollable or static content
|
|
27
|
+
- **Content**: Scrollable or static content
|
|
28
|
+
- **Footer**: Optional sticky area pinned to the bottom of the sheet
|
|
28
29
|
|
|
29
30
|
## Properties
|
|
30
31
|
|
|
@@ -97,6 +98,37 @@ Set both properties:
|
|
|
97
98
|
|
|
98
99
|
<Canvas of={BottomSheetStories.PreventClose} />
|
|
99
100
|
|
|
101
|
+
### Footer
|
|
102
|
+
|
|
103
|
+
`BottomSheetFooter` renders a sticky area pinned below the scrollable region.
|
|
104
|
+
|
|
105
|
+
`BottomSheetContent` is a non-scrollable content block that applies standard paddings.
|
|
106
|
+
|
|
107
|
+
#### BottomSheetContent
|
|
108
|
+
|
|
109
|
+
Gorhom's `BottomSheetView` is `position: absolute; top: 0`, so it always overlaps content above it-including the header. For this reason you cannot nest a second `BottomSheetView` inside another one to wrap your body content.
|
|
110
|
+
|
|
111
|
+
When using dynamic sizing (`enableDynamicSizing`), everything must live inside a single Gorhom-aware wrapper (`BottomSheetView`) so the library can measure the total height correctly. That rules out an extra `BottomSheetView` as a content wrapper.
|
|
112
|
+
|
|
113
|
+
`BottomSheetContent` solves this: it is a plain `Box`-based container (not a Gorhom component) with the standard horizontal and vertical paddings already built in, so you get consistent spacing without fighting the absolute-positioning constraint.
|
|
114
|
+
|
|
115
|
+
#### Automatic padding stripping
|
|
116
|
+
|
|
117
|
+
To avoid double-padding, `BottomSheetContent` and `BottomSheetFooter` communicate with their parent via React context:
|
|
118
|
+
|
|
119
|
+
- If `BottomSheetContent` is a child of `BottomSheetView`, its `paddingHorizontal` is dropped (the view already provides it).
|
|
120
|
+
- If a `BottomSheetFooter` is present inside the bottom sheet, `BottomSheetContent` drops its `paddingBottom` (the footer already handles the bottom spacing).
|
|
121
|
+
|
|
122
|
+
This means all combinations—with/without dynamic sizing, with/without a footer—produce consistent spacing automatically.
|
|
123
|
+
|
|
124
|
+
#### Scrollable content with a sticky footer
|
|
125
|
+
|
|
126
|
+
Footer and scrollable are siblings directly inside `BottomSheet`.
|
|
127
|
+
|
|
128
|
+
<Canvas of={BottomSheetStories.WithFooter} />
|
|
129
|
+
|
|
130
|
+
> **Android 3-button navigation:** If the footer is obscured by the system navigation bar, you can pass a bottom margin via `style` or `lx` to raise it.
|
|
131
|
+
|
|
100
132
|
</Tab>
|
|
101
133
|
<Tab label="Implementation">
|
|
102
134
|
|
|
@@ -266,10 +298,109 @@ import {
|
|
|
266
298
|
</BottomSheet>
|
|
267
299
|
```
|
|
268
300
|
|
|
301
|
+
### Footer and Content
|
|
302
|
+
|
|
303
|
+
#### BottomSheetFooter
|
|
304
|
+
|
|
305
|
+
`BottomSheetFooter` renders a sticky area at the bottom of the sheet. It must be placed inside a `BottomSheet` (context is required).
|
|
306
|
+
|
|
307
|
+
#### BottomSheetContent
|
|
308
|
+
|
|
309
|
+
`BottomSheetContent` is a non-scrollable `Box`-based container with `lx` support. By default it applies horizontal and vertical paddings.
|
|
310
|
+
|
|
311
|
+
Use it as the body wrapper whenever you need a static (non-scrollable) content area inside a `BottomSheetView`. Do **not** use a second `BottomSheetView` for this purpose. Gorhom's `BottomSheetView` is `position: absolute; top: 0`, so nesting one inside another causes it to overlap the header rather than flow below it. `BottomSheetContent` is a plain `Box` that avoids this constraint entirely.
|
|
312
|
+
|
|
313
|
+
When using dynamic sizing, all content must live inside a single `BottomSheetView` so the library can measure the sheet height. `BottomSheetContent` works correctly in this setup; a nested `BottomSheetView` does not.
|
|
314
|
+
|
|
315
|
+
Padding is handled automatically via context:
|
|
316
|
+
- `paddingHorizontal` is stripped when `BottomSheetContent` is a child of `BottomSheetView` (the view already provides it).
|
|
317
|
+
- `paddingBottom` is stripped when a `BottomSheetFooter` is present (the footer owns the bottom spacing).
|
|
318
|
+
|
|
319
|
+
#### Pattern A: scrollable content with a footer as siblings
|
|
320
|
+
|
|
321
|
+
Footer and scrollable are direct children of `BottomSheet`.
|
|
322
|
+
|
|
323
|
+
```tsx
|
|
324
|
+
import {
|
|
325
|
+
BottomSheet,
|
|
326
|
+
BottomSheetHeader,
|
|
327
|
+
BottomSheetScrollView,
|
|
328
|
+
BottomSheetFooter,
|
|
329
|
+
useBottomSheetRef,
|
|
330
|
+
} from '@ledgerhq/lumen-ui-rnative';
|
|
331
|
+
|
|
332
|
+
function MyComponent() {
|
|
333
|
+
const ref = useBottomSheetRef();
|
|
334
|
+
|
|
335
|
+
return (
|
|
336
|
+
<BottomSheet ref={ref} snapPoints={['50%']}>
|
|
337
|
+
<BottomSheetHeader spacing title="Title" density="compact" />
|
|
338
|
+
<BottomSheetScrollView>
|
|
339
|
+
{/* scrollable content */}
|
|
340
|
+
</BottomSheetScrollView>
|
|
341
|
+
<BottomSheetFooter>
|
|
342
|
+
<Button size="lg" isFull>Confirm</Button>
|
|
343
|
+
<Button size="lg" isFull appearance="ghost">Cancel</Button>
|
|
344
|
+
</BottomSheetFooter>
|
|
345
|
+
</BottomSheet>
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
#### Pattern B: static content with a footer inside BottomSheetView
|
|
351
|
+
|
|
352
|
+
Both `BottomSheetContent` and `BottomSheetFooter` are children of `BottomSheetView`.
|
|
353
|
+
|
|
354
|
+
```tsx
|
|
355
|
+
import {
|
|
356
|
+
BottomSheet,
|
|
357
|
+
BottomSheetView,
|
|
358
|
+
BottomSheetHeader,
|
|
359
|
+
BottomSheetContent,
|
|
360
|
+
BottomSheetFooter,
|
|
361
|
+
useBottomSheetRef,
|
|
362
|
+
} from '@ledgerhq/lumen-ui-rnative';
|
|
363
|
+
|
|
364
|
+
function MyComponent() {
|
|
365
|
+
const ref = useBottomSheetRef();
|
|
366
|
+
|
|
367
|
+
return (
|
|
368
|
+
<BottomSheet ref={ref} snapPoints={null} enableDynamicSizing>
|
|
369
|
+
<BottomSheetView>
|
|
370
|
+
<BottomSheetHeader title="Title" density="compact" />
|
|
371
|
+
<BottomSheetContent lx={{ gap: 's12' }}>
|
|
372
|
+
{/* static content */}
|
|
373
|
+
</BottomSheetContent>
|
|
374
|
+
<BottomSheetFooter>
|
|
375
|
+
<Button size="lg" isFull>Confirm</Button>
|
|
376
|
+
<Button size="lg" isFull appearance="ghost">Cancel</Button>
|
|
377
|
+
</BottomSheetFooter>
|
|
378
|
+
</BottomSheetView>
|
|
379
|
+
</BottomSheet>
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
#### Pattern C: standalone BottomSheetContent without a scrollable parent
|
|
385
|
+
|
|
386
|
+
`BottomSheetContent` is a direct child of `BottomSheet`, not wrapped in any scrollable.
|
|
387
|
+
|
|
388
|
+
```tsx
|
|
389
|
+
<BottomSheet ref={ref} snapPoints={['50%']}>
|
|
390
|
+
<BottomSheetHeader spacing title="Title" density="compact" />
|
|
391
|
+
<BottomSheetContent>
|
|
392
|
+
{/* content */}
|
|
393
|
+
</BottomSheetContent>
|
|
394
|
+
<BottomSheetFooter>
|
|
395
|
+
<Button size="lg" isFull>Confirm</Button>
|
|
396
|
+
</BottomSheetFooter>
|
|
397
|
+
</BottomSheet>
|
|
398
|
+
```
|
|
399
|
+
|
|
269
400
|
### Important Notes
|
|
270
401
|
|
|
271
402
|
- **Dynamic Sizing**: When using `enableDynamicSizing`, do not define `snapPoints`
|
|
272
|
-
- **Header Spacing**: Use `spacing` prop on `BottomSheetHeader` when using FlatList/VirtualizedList
|
|
403
|
+
- **Header Spacing**: Use `spacing` prop on `BottomSheetHeader` when using FlatList/VirtualizedList or when the footer is a sibling of a list-based scrollable
|
|
273
404
|
- **SectionList**: Not compatible with react-native-web. See [Gorhom documentation](https://gorhom.dev/react-native-bottom-sheet/components/bottomsheetsectionlist).
|
|
274
405
|
- **FlashList**: Requires `@shopify/flash-list` package. See [Gorhom docs](https://gorhom.dev/react-native-bottom-sheet/components/bottomsheetflashlist)
|
|
275
406
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
import type { FC } from 'react';
|
|
3
|
-
import { useState } from 'react';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
4
|
import { Button } from '../Button';
|
|
5
5
|
import { SearchInput } from '../SearchInput';
|
|
6
6
|
import { Spot } from '../Spot';
|
|
7
7
|
import { Box, RadialGradient, Text } from '../Utility';
|
|
8
8
|
import { BottomSheet } from './BottomSheet';
|
|
9
|
+
import { BottomSheetContent } from './BottomSheetContent';
|
|
10
|
+
import { BottomSheetFooter } from './BottomSheetFooter';
|
|
9
11
|
import { BottomSheetHeader } from './BottomSheetHeader';
|
|
10
12
|
import {
|
|
11
13
|
BottomSheetFlatList,
|
|
@@ -137,7 +139,7 @@ export const Base: Story = {
|
|
|
137
139
|
density='compact'
|
|
138
140
|
description='Description'
|
|
139
141
|
/>
|
|
140
|
-
<
|
|
142
|
+
<BottomSheetContent lx={{ flexDirection: 'column', gap: 's12' }}>
|
|
141
143
|
{Array.from({ length: 3 }).map((_, index) => (
|
|
142
144
|
<Text typography='body2' lx={{ color: 'base' }} key={index}>
|
|
143
145
|
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
|
|
@@ -146,7 +148,52 @@ export const Base: Story = {
|
|
|
146
148
|
voluptates eum, sunt asperiores quod.
|
|
147
149
|
</Text>
|
|
148
150
|
))}
|
|
149
|
-
</
|
|
151
|
+
</BottomSheetContent>
|
|
152
|
+
</BottomSheetView>
|
|
153
|
+
</BottomSheet>
|
|
154
|
+
</Box>
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const BaseOpen: Story = {
|
|
160
|
+
args: {
|
|
161
|
+
...Base.args,
|
|
162
|
+
},
|
|
163
|
+
render: (args) => {
|
|
164
|
+
const bottomSheetRef = useBottomSheetRef();
|
|
165
|
+
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
bottomSheetRef.current?.present();
|
|
168
|
+
}, [bottomSheetRef]);
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<Box
|
|
172
|
+
lx={{
|
|
173
|
+
height: 's320',
|
|
174
|
+
width: 'full',
|
|
175
|
+
alignItems: 'center',
|
|
176
|
+
justifyContent: 'center',
|
|
177
|
+
paddingTop: 's32',
|
|
178
|
+
}}
|
|
179
|
+
>
|
|
180
|
+
<BottomSheet {...args} ref={bottomSheetRef}>
|
|
181
|
+
<BottomSheetView>
|
|
182
|
+
<BottomSheetHeader
|
|
183
|
+
title='Title'
|
|
184
|
+
density='compact'
|
|
185
|
+
description='Description'
|
|
186
|
+
/>
|
|
187
|
+
<BottomSheetContent lx={{ flexDirection: 'column', gap: 's12' }}>
|
|
188
|
+
{Array.from({ length: 3 }).map((_, index) => (
|
|
189
|
+
<Text typography='body2' lx={{ color: 'base' }} key={index}>
|
|
190
|
+
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
|
|
191
|
+
Vitae excepturi odit, quis tenetur iste perspiciatis mollitia
|
|
192
|
+
porro velit laborum quasi numquam reiciendis dolor! Et quia
|
|
193
|
+
voluptates eum, sunt asperiores quod.
|
|
194
|
+
</Text>
|
|
195
|
+
))}
|
|
196
|
+
</BottomSheetContent>
|
|
150
197
|
</BottomSheetView>
|
|
151
198
|
</BottomSheet>
|
|
152
199
|
</Box>
|
|
@@ -187,7 +234,7 @@ export const TitleExpanded: Story = {
|
|
|
187
234
|
density='expanded'
|
|
188
235
|
description='Expanded description.'
|
|
189
236
|
/>
|
|
190
|
-
<
|
|
237
|
+
<BottomSheetContent>
|
|
191
238
|
<Text typography='body2' lx={{ color: 'base' }}>
|
|
192
239
|
Lorem ipsum dolor sit amet consectetur adipisicing elit. Vitae
|
|
193
240
|
excepturi odit, quis tenetur iste perspiciatis mollitia porro
|
|
@@ -197,7 +244,7 @@ export const TitleExpanded: Story = {
|
|
|
197
244
|
consectetur adipiscing elit. Donec ullamcorper nulla non metus
|
|
198
245
|
auctor fringilla.
|
|
199
246
|
</Text>
|
|
200
|
-
</
|
|
247
|
+
</BottomSheetContent>
|
|
201
248
|
</BottomSheetView>
|
|
202
249
|
</BottomSheet>
|
|
203
250
|
</Box>
|
|
@@ -829,3 +876,62 @@ export const InfoStateVariants: Story = {
|
|
|
829
876
|
);
|
|
830
877
|
},
|
|
831
878
|
};
|
|
879
|
+
|
|
880
|
+
export const WithFooter: Story = {
|
|
881
|
+
args: {
|
|
882
|
+
hideCloseButton: false,
|
|
883
|
+
enableHandlePanningGesture: true,
|
|
884
|
+
enablePanDownToClose: true,
|
|
885
|
+
enableBlurKeyboardOnGesture: true,
|
|
886
|
+
enableDynamicSizing: true,
|
|
887
|
+
detached: false,
|
|
888
|
+
backdropPressBehavior: 'close',
|
|
889
|
+
},
|
|
890
|
+
render: (args) => {
|
|
891
|
+
const bottomSheetRef = useBottomSheetRef();
|
|
892
|
+
|
|
893
|
+
return (
|
|
894
|
+
<Box
|
|
895
|
+
lx={{
|
|
896
|
+
height: 's320',
|
|
897
|
+
width: 'full',
|
|
898
|
+
alignItems: 'center',
|
|
899
|
+
justifyContent: 'center',
|
|
900
|
+
paddingTop: 's32',
|
|
901
|
+
}}
|
|
902
|
+
>
|
|
903
|
+
<Button size='sm' onPress={() => bottomSheetRef.current?.present()}>
|
|
904
|
+
Toggle open
|
|
905
|
+
</Button>
|
|
906
|
+
<BottomSheet {...args} ref={bottomSheetRef}>
|
|
907
|
+
<BottomSheetHeader
|
|
908
|
+
spacing
|
|
909
|
+
title='With Footer'
|
|
910
|
+
density='compact'
|
|
911
|
+
description='Scrollable content with a sticky footer'
|
|
912
|
+
/>
|
|
913
|
+
<BottomSheetScrollView>
|
|
914
|
+
<Box lx={{ flexDirection: 'column', gap: 's12' }}>
|
|
915
|
+
{Array.from({ length: 10 }).map((_, index) => (
|
|
916
|
+
<Text typography='body2' lx={{ color: 'base' }} key={index}>
|
|
917
|
+
Item {index + 1}: Lorem ipsum dolor sit amet consectetur
|
|
918
|
+
adipisicing elit. Vitae excepturi odit, quis tenetur iste
|
|
919
|
+
perspiciatis mollitia porro velit laborum quasi numquam
|
|
920
|
+
reiciendis dolor!
|
|
921
|
+
</Text>
|
|
922
|
+
))}
|
|
923
|
+
</Box>
|
|
924
|
+
</BottomSheetScrollView>
|
|
925
|
+
<BottomSheetFooter>
|
|
926
|
+
<Button size='lg' isFull>
|
|
927
|
+
Confirm
|
|
928
|
+
</Button>
|
|
929
|
+
<Button size='lg' isFull appearance='gray'>
|
|
930
|
+
Cancel
|
|
931
|
+
</Button>
|
|
932
|
+
</BottomSheetFooter>
|
|
933
|
+
</BottomSheet>
|
|
934
|
+
</Box>
|
|
935
|
+
);
|
|
936
|
+
},
|
|
937
|
+
};
|
|
@@ -5,7 +5,10 @@ import { fireEvent, render } from '@testing-library/react-native';
|
|
|
5
5
|
import { Text, View } from 'react-native';
|
|
6
6
|
import { ThemeProvider } from '../ThemeProvider/ThemeProvider';
|
|
7
7
|
import { BottomSheet as BottomSheetComponent } from './BottomSheet';
|
|
8
|
+
import { BottomSheetContent } from './BottomSheetContent';
|
|
9
|
+
import { BottomSheetFooter } from './BottomSheetFooter';
|
|
8
10
|
import { BottomSheetHeader } from './BottomSheetHeader';
|
|
11
|
+
import { BottomSheetView } from './Scrollables';
|
|
9
12
|
// Mock react-native-gesture-handler which is used by @gorhom/bottom-sheet
|
|
10
13
|
jest.mock('react-native-gesture-handler', () => ({}));
|
|
11
14
|
|
|
@@ -397,3 +400,140 @@ describe('BottomSheet', () => {
|
|
|
397
400
|
});
|
|
398
401
|
});
|
|
399
402
|
});
|
|
403
|
+
|
|
404
|
+
describe('BottomSheetContent', () => {
|
|
405
|
+
it('renders children', () => {
|
|
406
|
+
const { BottomSheet } = require('./BottomSheet');
|
|
407
|
+
const { getByText } = renderWithTheme(
|
|
408
|
+
<BottomSheet testID='bottom-sheet'>
|
|
409
|
+
<BottomSheetContent>
|
|
410
|
+
<Text>Content child</Text>
|
|
411
|
+
</BottomSheetContent>
|
|
412
|
+
</BottomSheet>,
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
expect(getByText('Content child')).toBeTruthy();
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('renders without BottomSheet context without throwing (contextRequired: false)', () => {
|
|
419
|
+
expect(() =>
|
|
420
|
+
renderWithTheme(
|
|
421
|
+
<BottomSheetContent>
|
|
422
|
+
<Text>Standalone</Text>
|
|
423
|
+
</BottomSheetContent>,
|
|
424
|
+
),
|
|
425
|
+
).not.toThrow();
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('detects scrollable parent context and does not throw', () => {
|
|
429
|
+
const { BottomSheet } = require('./BottomSheet');
|
|
430
|
+
expect(() =>
|
|
431
|
+
renderWithTheme(
|
|
432
|
+
<BottomSheet testID='bottom-sheet'>
|
|
433
|
+
<BottomSheetView>
|
|
434
|
+
<BottomSheetContent>
|
|
435
|
+
<Text>Inside view</Text>
|
|
436
|
+
</BottomSheetContent>
|
|
437
|
+
</BottomSheetView>
|
|
438
|
+
</BottomSheet>,
|
|
439
|
+
),
|
|
440
|
+
).not.toThrow();
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
it('renders when BottomSheetFooter is present as a sibling inside BottomSheetView', () => {
|
|
444
|
+
const { BottomSheet } = require('./BottomSheet');
|
|
445
|
+
expect(() =>
|
|
446
|
+
renderWithTheme(
|
|
447
|
+
<BottomSheet testID='bottom-sheet'>
|
|
448
|
+
<BottomSheetView>
|
|
449
|
+
<BottomSheetContent>
|
|
450
|
+
<Text>Content</Text>
|
|
451
|
+
</BottomSheetContent>
|
|
452
|
+
<BottomSheetFooter>
|
|
453
|
+
<Text>Footer</Text>
|
|
454
|
+
</BottomSheetFooter>
|
|
455
|
+
</BottomSheetView>
|
|
456
|
+
</BottomSheet>,
|
|
457
|
+
),
|
|
458
|
+
).not.toThrow();
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
describe('BottomSheetFooter', () => {
|
|
463
|
+
it('renders children', () => {
|
|
464
|
+
const { BottomSheet } = require('./BottomSheet');
|
|
465
|
+
const { getByText } = renderWithTheme(
|
|
466
|
+
<BottomSheet testID='bottom-sheet'>
|
|
467
|
+
<BottomSheetFooter>
|
|
468
|
+
<Text>Footer content</Text>
|
|
469
|
+
</BottomSheetFooter>
|
|
470
|
+
</BottomSheet>,
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
expect(getByText('Footer content')).toBeTruthy();
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it('renders inside BottomSheetView without throwing', () => {
|
|
477
|
+
const { BottomSheet } = require('./BottomSheet');
|
|
478
|
+
expect(() =>
|
|
479
|
+
renderWithTheme(
|
|
480
|
+
<BottomSheet testID='bottom-sheet'>
|
|
481
|
+
<BottomSheetView>
|
|
482
|
+
<BottomSheetFooter>
|
|
483
|
+
<Text>Footer inside view</Text>
|
|
484
|
+
</BottomSheetFooter>
|
|
485
|
+
</BottomSheetView>
|
|
486
|
+
</BottomSheet>,
|
|
487
|
+
),
|
|
488
|
+
).not.toThrow();
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it('signals footer presence to context (renders alongside BottomSheetContent without throwing)', () => {
|
|
492
|
+
const { BottomSheet } = require('./BottomSheet');
|
|
493
|
+
expect(() =>
|
|
494
|
+
renderWithTheme(
|
|
495
|
+
<BottomSheet testID='bottom-sheet'>
|
|
496
|
+
<BottomSheetView>
|
|
497
|
+
<BottomSheetContent>
|
|
498
|
+
<Text>Content</Text>
|
|
499
|
+
</BottomSheetContent>
|
|
500
|
+
<BottomSheetFooter>
|
|
501
|
+
<Text>Footer</Text>
|
|
502
|
+
</BottomSheetFooter>
|
|
503
|
+
</BottomSheetView>
|
|
504
|
+
</BottomSheet>,
|
|
505
|
+
),
|
|
506
|
+
).not.toThrow();
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
describe('BottomSheetView', () => {
|
|
511
|
+
it('renders children', () => {
|
|
512
|
+
const { BottomSheet } = require('./BottomSheet');
|
|
513
|
+
const { getByText } = renderWithTheme(
|
|
514
|
+
<BottomSheet testID='bottom-sheet'>
|
|
515
|
+
<BottomSheetView>
|
|
516
|
+
<Text>View child</Text>
|
|
517
|
+
</BottomSheetView>
|
|
518
|
+
</BottomSheet>,
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
expect(getByText('View child')).toBeTruthy();
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('renders when BottomSheetFooter is a sibling inside BottomSheetView', () => {
|
|
525
|
+
const { BottomSheet } = require('./BottomSheet');
|
|
526
|
+
expect(() =>
|
|
527
|
+
renderWithTheme(
|
|
528
|
+
<BottomSheet testID='bottom-sheet'>
|
|
529
|
+
<BottomSheetView>
|
|
530
|
+
<Text>Content</Text>
|
|
531
|
+
<BottomSheetFooter>
|
|
532
|
+
<Text>Footer</Text>
|
|
533
|
+
</BottomSheetFooter>
|
|
534
|
+
</BottomSheetView>
|
|
535
|
+
</BottomSheet>,
|
|
536
|
+
),
|
|
537
|
+
).not.toThrow();
|
|
538
|
+
});
|
|
539
|
+
});
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { SNAP_POINT_TYPE } from '@gorhom/bottom-sheet';
|
|
2
2
|
import { BottomSheetModal as GorhomBottomSheetModal } from '@gorhom/bottom-sheet';
|
|
3
3
|
import { createSafeContext, useMergedRef } from '@ledgerhq/lumen-utils-shared';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
useCallback,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
type Dispatch,
|
|
10
|
+
type SetStateAction,
|
|
11
|
+
} from 'react';
|
|
5
12
|
import { StyleSheet } from 'react-native';
|
|
6
13
|
import { useStyleSheet } from '../../../styles';
|
|
7
14
|
import { RuntimeConstants } from '../../utils';
|
|
@@ -56,13 +63,15 @@ const useStyles = ({
|
|
|
56
63
|
);
|
|
57
64
|
};
|
|
58
65
|
|
|
59
|
-
const [BottomSheetProvider, useBottomSheetContext] =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
const [BottomSheetProvider, useBottomSheetContext] = createSafeContext<
|
|
67
|
+
Pick<
|
|
68
|
+
BottomSheetProps,
|
|
69
|
+
'onBack' | 'hideCloseButton' | 'onHeaderClosePressed'
|
|
70
|
+
> & {
|
|
71
|
+
hasFooter: boolean;
|
|
72
|
+
setHasFooter: Dispatch<SetStateAction<boolean>>;
|
|
73
|
+
}
|
|
74
|
+
>('BottomSheet');
|
|
66
75
|
|
|
67
76
|
export const BottomSheet = ({
|
|
68
77
|
onOpen,
|
|
@@ -93,6 +102,7 @@ export const BottomSheet = ({
|
|
|
93
102
|
const innerRef = useRef<GorhomBottomSheetModal>(null);
|
|
94
103
|
const mergedRefs = useMergedRef<GorhomBottomSheetModal>(ref, innerRef);
|
|
95
104
|
const [isOpen, setIsOpen] = useState(false);
|
|
105
|
+
const [hasFooter, setHasFooter] = useState(false);
|
|
96
106
|
|
|
97
107
|
const styles = useStyles({
|
|
98
108
|
shadow: hideBackdrop && isOpen,
|
|
@@ -208,7 +218,13 @@ export const BottomSheet = ({
|
|
|
208
218
|
backdropComponent={hideBackdrop ? undefined : renderBackdrop}
|
|
209
219
|
>
|
|
210
220
|
<BottomSheetProvider
|
|
211
|
-
value={{
|
|
221
|
+
value={{
|
|
222
|
+
onBack,
|
|
223
|
+
hideCloseButton,
|
|
224
|
+
onHeaderClosePressed,
|
|
225
|
+
hasFooter,
|
|
226
|
+
setHasFooter,
|
|
227
|
+
}}
|
|
212
228
|
>
|
|
213
229
|
{children}
|
|
214
230
|
</BottomSheetProvider>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { useStyleSheet } from '../../../styles';
|
|
3
|
+
import { Box } from '../Utility';
|
|
4
|
+
import { useBottomSheetContext } from './BottomSheet';
|
|
5
|
+
import { useIsInsideScrollableView } from './Scrollables';
|
|
6
|
+
import type { BottomSheetContentProps } from './types';
|
|
7
|
+
|
|
8
|
+
const useStyles = (hasFooter: boolean, isInsideScrollableView: boolean) =>
|
|
9
|
+
useStyleSheet(
|
|
10
|
+
(t) => ({
|
|
11
|
+
container: StyleSheet.flatten([
|
|
12
|
+
{
|
|
13
|
+
flex: 1,
|
|
14
|
+
paddingBottom: hasFooter ? 0 : t.spacings.s16,
|
|
15
|
+
},
|
|
16
|
+
!isInsideScrollableView && {
|
|
17
|
+
paddingHorizontal: t.spacings.s16,
|
|
18
|
+
},
|
|
19
|
+
]),
|
|
20
|
+
}),
|
|
21
|
+
[hasFooter, isInsideScrollableView],
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const BottomSheetContent = ({
|
|
25
|
+
children,
|
|
26
|
+
style,
|
|
27
|
+
lx,
|
|
28
|
+
...props
|
|
29
|
+
}: BottomSheetContentProps) => {
|
|
30
|
+
const ctx = useBottomSheetContext({
|
|
31
|
+
consumerName: 'BottomSheetContent',
|
|
32
|
+
contextRequired: false,
|
|
33
|
+
});
|
|
34
|
+
const styles = useStyles(
|
|
35
|
+
ctx?.hasFooter ?? false,
|
|
36
|
+
useIsInsideScrollableView(),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Box {...props} lx={lx} style={[styles.container, style]}>
|
|
41
|
+
{children}
|
|
42
|
+
</Box>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import { useStyleSheet } from '../../../styles';
|
|
4
|
+
import { Box } from '../Utility';
|
|
5
|
+
import { useBottomSheetContext } from './BottomSheet';
|
|
6
|
+
import { useIsInsideScrollableView } from './Scrollables';
|
|
7
|
+
import type { BottomSheetFooterProps } from './types';
|
|
8
|
+
|
|
9
|
+
const useStyles = (isInsideScrollableView: boolean) =>
|
|
10
|
+
useStyleSheet(
|
|
11
|
+
(t) => ({
|
|
12
|
+
root: StyleSheet.flatten([
|
|
13
|
+
{
|
|
14
|
+
paddingTop: t.spacings.s12,
|
|
15
|
+
paddingBottom: t.spacings.s16,
|
|
16
|
+
backgroundColor: t.colors.bg.canvasSheet,
|
|
17
|
+
gap: t.spacings.s8,
|
|
18
|
+
},
|
|
19
|
+
!isInsideScrollableView && { paddingHorizontal: t.spacings.s16 },
|
|
20
|
+
]),
|
|
21
|
+
}),
|
|
22
|
+
[isInsideScrollableView],
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const BottomSheetFooter = ({
|
|
26
|
+
children,
|
|
27
|
+
style,
|
|
28
|
+
lx,
|
|
29
|
+
}: BottomSheetFooterProps) => {
|
|
30
|
+
const insideScrollableView = useIsInsideScrollableView();
|
|
31
|
+
const styles = useStyles(insideScrollableView);
|
|
32
|
+
const { setHasFooter } = useBottomSheetContext({
|
|
33
|
+
consumerName: 'BottomSheetFooter',
|
|
34
|
+
contextRequired: true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
setHasFooter(true);
|
|
39
|
+
return () => setHasFooter(false);
|
|
40
|
+
}, [setHasFooter]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Box style={[styles.root, style]} lx={lx}>
|
|
44
|
+
{children}
|
|
45
|
+
</Box>
|
|
46
|
+
);
|
|
47
|
+
};
|