Skip to content

Commit 4e607e8

Browse files
huderlemyayvery
authored andcommitted
Add flashlist support for bottomsheet
1 parent 0cc59ee commit 4e607e8

File tree

8 files changed

+131
-3
lines changed

8 files changed

+131
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"peerDependencies": {
6767
"@types/react": "*",
6868
"@types/react-native": "*",
69+
"@shopify/flash-list": "*",
6970
"react": "*",
7071
"react-native": "*",
7172
"react-native-gesture-handler": ">=1.10.1",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as React from 'react';
2+
import {
3+
FlashList as ShopifyFlashList,
4+
FlashListProps,
5+
} from '@shopify/flash-list';
6+
import { SCROLLABLE_TYPE } from '../../constants';
7+
import { createBottomSheetScrollableComponent } from './createBottomSheetScrollableComponent';
8+
import type {
9+
BottomSheetFlashListMethods,
10+
BottomSheetFlashListProps,
11+
} from './types';
12+
import Animated from 'react-native-reanimated';
13+
import BottomSheetScrollView from './BottomSheetScrollView';
14+
15+
const AnimatedShopifyFlashList =
16+
Animated.createAnimatedComponent(ShopifyFlashList);
17+
const AnimatedFlashList = React.forwardRef<any, FlashListProps<any>>(
18+
(props, ref) => (
19+
<AnimatedShopifyFlashList
20+
ref={ref}
21+
// @ts-ignore
22+
renderScrollComponent={BottomSheetScrollView}
23+
{...props}
24+
/>
25+
)
26+
);
27+
28+
const BottomSheetFlashListComponent = createBottomSheetScrollableComponent<
29+
BottomSheetFlashListMethods,
30+
BottomSheetFlashListProps<any>
31+
>(SCROLLABLE_TYPE.FLASHLIST, AnimatedFlashList);
32+
33+
const BottomSheetFlashList = React.memo(BottomSheetFlashListComponent);
34+
BottomSheetFlashList.displayName = 'BottomSheetFlashList';
35+
36+
export default BottomSheetFlashList as <T>(
37+
props: BottomSheetFlashListProps<T>
38+
) => ReturnType<typeof BottomSheetFlashList>;

src/components/bottomSheetScrollable/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
export { createBottomSheetScrollableComponent } from './createBottomSheetScrollableComponent';
22
export { default as BottomSheetSectionList } from './BottomSheetSectionList';
3+
export { default as BottomSheetFlashList } from './BottomSheetFlashList';
34
export { default as BottomSheetFlatList } from './BottomSheetFlatList';
45
export { default as BottomSheetScrollView } from './BottomSheetScrollView';
56
export { default as BottomSheetVirtualizedList } from './BottomSheetVirtualizedList';
67

78
export type {
9+
BottomSheetFlashListMethods,
810
BottomSheetFlatListMethods,
911
BottomSheetScrollViewMethods,
1012
BottomSheetSectionListMethods,

src/components/bottomSheetScrollable/types.d.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
} from 'react-native';
1919
import type Animated from 'react-native-reanimated';
2020
import type { ScrollEventsHandlersHookType } from '../../types';
21+
import type { FlashListProps } from '@shopify/flash-list';
2122

2223
export interface BottomSheetScrollableProps {
2324
/**
@@ -62,6 +63,7 @@ export interface BottomSheetScrollableProps {
6263
export type ScrollableProps<T> =
6364
| ScrollViewProps
6465
| FlatListProps<T>
66+
| FlashListProps<T>
6567
| SectionListProps<T>;
6668

6769
//#region FlatList
@@ -142,6 +144,87 @@ export interface BottomSheetFlatListMethods {
142144
}
143145
//#endregion
144146

147+
//#region FlatList
148+
export type BottomSheetFlashListProps<T> = Omit<
149+
FlashListProps<T>,
150+
| 'decelerationRate'
151+
| 'onScroll'
152+
| 'scrollEventThrottle'
153+
| 'renderScrollComponent'
154+
> &
155+
BottomSheetScrollableProps & {
156+
ref?: Ref<BottomSheetFlashListMethods>;
157+
};
158+
159+
export interface BottomSheetFlashListMethods {
160+
/**
161+
* Scrolls to the end of the content. May be janky without `getItemLayout` prop.
162+
*/
163+
scrollToEnd: (params?: { animated?: boolean | null }) => void;
164+
165+
/**
166+
* Scrolls to the item at the specified index such that it is positioned in the viewable area
167+
* such that viewPosition 0 places it at the top, 1 at the bottom, and 0.5 centered in the middle.
168+
* Cannot scroll to locations outside the render window without specifying the getItemLayout prop.
169+
*/
170+
scrollToIndex: (params: {
171+
animated?: boolean | null;
172+
index: number;
173+
viewOffset?: number;
174+
viewPosition?: number;
175+
}) => void;
176+
177+
/**
178+
* Requires linear scan through data - use `scrollToIndex` instead if possible.
179+
* May be janky without `getItemLayout` prop.
180+
*/
181+
scrollToItem: (params: {
182+
animated?: boolean | null;
183+
item: any;
184+
viewPosition?: number;
185+
}) => void;
186+
187+
/**
188+
* Scroll to a specific content pixel offset, like a normal `ScrollView`.
189+
*/
190+
scrollToOffset: (params: {
191+
animated?: boolean | null;
192+
offset: number;
193+
}) => void;
194+
195+
/**
196+
* Tells the list an interaction has occured, which should trigger viewability calculations,
197+
* e.g. if waitForInteractions is true and the user has not scrolled. This is typically called
198+
* by taps on items or by navigation actions.
199+
*/
200+
recordInteraction: () => void;
201+
202+
/**
203+
* Displays the scroll indicators momentarily.
204+
*/
205+
flashScrollIndicators: () => void;
206+
207+
/**
208+
* Provides a handle to the underlying scroll responder.
209+
*/
210+
getScrollResponder: () => ScrollResponderMixin | null | undefined;
211+
212+
/**
213+
* Provides a reference to the underlying host component
214+
*/
215+
getNativeScrollRef: () =>
216+
| RefObject<View>
217+
| RefObject<ScrollViewComponent>
218+
| null
219+
| undefined;
220+
221+
getScrollableNode: () => any;
222+
223+
// TODO: use `unknown` instead of `any` for Typescript >= 3.0
224+
setNativeProps: (props: { [key: string]: any }) => void;
225+
}
226+
//#endregion
227+
145228
//#region ScrollView
146229
export type BottomSheetScrollViewProps = Omit<
147230
Animated.AnimateProps<ScrollViewProps>,

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum SCROLLABLE_TYPE {
3232
SCROLLVIEW,
3333
SECTIONLIST,
3434
VIRTUALIZEDLIST,
35+
FLASHLIST,
3536
}
3637

3738
enum ANIMATION_STATE {

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export { useScrollableSetter } from './hooks/useScrollableSetter';
2424
export {
2525
BottomSheetScrollView,
2626
BottomSheetSectionList,
27+
BottomSheetFlashList,
2728
BottomSheetFlatList,
2829
BottomSheetVirtualizedList,
2930
} from './components/bottomSheetScrollable';
@@ -55,6 +56,7 @@ export type { BottomSheetBackdropProps } from './components/bottomSheetBackdrop'
5556
export type { BottomSheetFooterProps } from './components/bottomSheetFooter';
5657

5758
export type {
59+
BottomSheetFlashListMethods,
5860
BottomSheetFlatListMethods,
5961
BottomSheetScrollViewMethods,
6062
BottomSheetSectionListMethods,

src/types.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
WithSpringConfig,
1616
WithTimingConfig,
1717
} from 'react-native-reanimated';
18+
import type { FlashList } from '@shopify/flash-list';
1819
import type { GESTURE_SOURCE } from './constants';
1920

2021
//#region Methods
@@ -107,7 +108,7 @@ export interface BottomSheetVariables {
107108
}
108109

109110
//#region scrollables
110-
export type Scrollable = FlatList | ScrollView | SectionList;
111+
export type Scrollable = FlashList | FlatList | ScrollView | SectionList;
111112
export type ScrollableRef = {
112113
id: number;
113114
node: React.RefObject<Scrollable>;
@@ -156,7 +157,7 @@ export type ScrollEventsHandlersHookType = (
156157
ref: React.RefObject<Scrollable>,
157158
contentOffsetY: SharedValue<number>,
158159
scrollBuffer: number | undefined,
159-
preserveScrollMomentum: boolean | undefined,
160+
preserveScrollMomentum: boolean | undefined
160161
) => {
161162
handleOnScroll?: ScrollEventHandlerCallbackType;
162163
handleOnBeginDrag?: ScrollEventHandlerCallbackType;

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6381,7 +6381,7 @@ lodash.clonedeep@^4.5.0:
63816381
lodash.debounce@^4.0.8:
63826382
version "4.0.8"
63836383
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
6384-
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
6384+
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==
63856385

63866386
lodash.escaperegexp@^4.1.2:
63876387
version "4.1.2"

0 commit comments

Comments
 (0)