|
1 | | -# react-native-scrollview-enhancer |
| 1 | +# @sendbird/react-native-scrollview-enhancer |
2 | 2 |
|
3 | | -ScrollView enhancer |
| 3 | +A utility package that enables the use of `onStartReached` and `maintainVisibleContentPosition` features in ScrollView components in react-native versions prior to 0.72. |
4 | 4 |
|
5 | 5 | ## Installation |
6 | 6 |
|
7 | 7 | ```sh |
8 | | -npm install react-native-scrollview-enhancer |
| 8 | +npm install @sendbird/react-native-scrollview-enhancer |
9 | 9 | ``` |
10 | 10 |
|
11 | 11 | ## Usage |
12 | 12 |
|
13 | | -```js |
14 | | -import { ScrollViewEnhancerView } from "react-native-scrollview-enhancer"; |
| 13 | +You can use a scroll view components with `onStartReached` and `maintainVisibleContentPosition` applied as follows. |
15 | 14 |
|
16 | | -// ... |
| 15 | +```tsx |
| 16 | +import { FlatList, ScrollView, SectionList } from '@sendbird/react-native-scrollview-enhancer'; |
17 | 17 |
|
18 | | -<ScrollViewEnhancerView color="tomato" /> |
| 18 | +const App = () => { |
| 19 | + return ( |
| 20 | + <FlatList |
| 21 | + inverted |
| 22 | + data={messages} |
| 23 | + renderItem={renderMessageItem} |
| 24 | + onEndReached={onEndReached} |
| 25 | + onStartReached={onStartReached} |
| 26 | + /> |
| 27 | + ); |
| 28 | +}; |
19 | 29 | ``` |
20 | 30 |
|
21 | | -## Contributing |
| 31 | +## Customization |
22 | 32 |
|
23 | | -See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. |
| 33 | +### maintainVisibleContentPosition |
| 34 | + |
| 35 | +The `maintainVisibleContentPosition` feature can be used by wrapping the ScrollView component (`ScrollView`, `FlatList`, `SectionList`, `VirtualizedList`) that you want to use with the `ScrollViewEnhancerView` component. |
| 36 | + |
| 37 | +```tsx |
| 38 | +import { ScrollView } from 'react-native'; |
| 39 | +import { ScrollViewEnhancerView } from '@sendbird/react-native-scrollview-enhancer'; |
| 40 | + |
| 41 | +const App = () => { |
| 42 | + return ( |
| 43 | + <ScrollViewEnhancerView> |
| 44 | + <ScrollView /> |
| 45 | + </ScrollViewEnhancerView> |
| 46 | + ); |
| 47 | +}; |
| 48 | +``` |
| 49 | + |
| 50 | +### onStartReached |
| 51 | + |
| 52 | +This package provides a `useBidirectional` hook that adds `onStartReached` to the `ScrollView`. |
| 53 | + |
| 54 | +```tsx |
| 55 | +import { View, FlatList } from 'react-native'; |
| 56 | +import { useBiDirectional } from '@sendbird/react-native-scrollview-enhancer'; |
| 57 | + |
| 58 | +const App = () => { |
| 59 | + const { renderScrollView } = useBiDirectional(FlatList, props, ref); |
| 60 | + return <View>{renderScrollView()}</View>; |
| 61 | +}; |
| 62 | +``` |
| 63 | + |
| 64 | +### Utility functions |
| 65 | + |
| 66 | +This package provides the following utility functions to make it easier to use: |
| 67 | + |
| 68 | +- enhanceScrollView: adds `maintainVisibleContentPosition` feature to the ScrollView component |
| 69 | +- enhanceScrollViewWithBidirectional: adds `maintainVisibleContentPosition` and `onStartReached` features to the ScrollView component |
| 70 | + |
| 71 | +```tsx |
| 72 | +import { ScrollView, FlatList } from 'react-native'; |
| 73 | +import { enhanceScrollView, enhanceScrollViewWithBidirectional } from '@sendbird/react-native-scrollview-enhancer'; |
| 74 | + |
| 75 | +const EnhancedScrollView = enhanceScrollView(ScrollView); |
| 76 | +const BiDirectionalFlatList = enhanceScrollViewWithBidirectional(FlatList); |
| 77 | +``` |
24 | 78 |
|
25 | 79 | ## License |
26 | 80 |
|
|
0 commit comments