Skip to content

Commit 636f845

Browse files
fix: fixed typescript declarations and upgrade flat-list-mvcp to 0.10.0
1 parent b261a78 commit 636f845

8 files changed

+680
-628
lines changed

babel.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
2-
presets: ['module:metro-react-native-babel-preset'],
2+
presets: [
3+
'module:metro-react-native-babel-preset',
4+
'@babel/preset-typescript',
5+
],
36
};

example/babel.config.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
const path = require('path');
2-
const pak = require('../package.json');
3-
41
module.exports = {
5-
presets: ['module:metro-react-native-babel-preset'],
6-
plugins: [
7-
[
8-
'module-resolver',
9-
{
10-
alias: {
11-
[pak.name]: path.join(__dirname, '..', pak.source),
12-
},
13-
},
14-
],
2+
presets: [
3+
'module:metro-react-native-babel-preset',
4+
'@babel/preset-typescript',
155
],
166
};

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"start": "react-native start"
1010
},
1111
"dependencies": {
12-
"@stream-io/flat-list-mvcp": "^",
12+
"@stream-io/flat-list-mvcp": "0.10.0",
1313
"react": "16.13.1",
1414
"react-native": "0.63.4",
1515
"react-native-bidirectional-infinite-scroll": "link:../"

example/yarn.lock

Lines changed: 142 additions & 145 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Birectional infinite scroll for react-native",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
7-
"types": "lib/typescript/src/index.d.ts",
7+
"types": "lib/typescript/index.d.ts",
88
"react-native": "src/index",
99
"source": "src/index",
1010
"files": [
@@ -50,10 +50,10 @@
5050
"@commitlint/config-conventional": "^11.0.0",
5151
"@react-native-community/eslint-config": "^2.0.0",
5252
"@release-it/conventional-changelog": "^2.0.0",
53-
"@stream-io/flat-list-mvcp": "^",
53+
"@stream-io/flat-list-mvcp": "^0.10.0",
5454
"@types/jest": "^26.0.0",
5555
"@types/react": "^16.9.19",
56-
"@types/react-native": "0.62.13",
56+
"@types/react-native": "0.63.50",
5757
"commitlint": "^11.0.0",
5858
"eslint": "^7.2.0",
5959
"eslint-config-prettier": "^7.0.0",
@@ -69,7 +69,7 @@
6969
"typescript": "^4.1.3"
7070
},
7171
"peerDependencies": {
72-
"@stream-io/flat-list-mvcp": "*",
72+
"@stream-io/flat-list-mvcp": ">=0.10.0",
7373
"react": "*",
7474
"react-native": "*"
7575
},

src/index.tsx renamed to src/BidirectionalFlatList.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ const styles = StyleSheet.create({
1616
},
1717
});
1818

19-
type Props<T> = Omit<FlatListProps<T>, 'maintainVisibleContentPosition'> & {
19+
export type Props<T> = Omit<
20+
FlatListProps<T>,
21+
'maintainVisibleContentPosition'
22+
> & {
2023
/**
2124
* Called once when the scroll position gets close to end of list. This must return a promise.
2225
* You can `onEndReachedThreshold` as distance from end of list, when this function should be called.
@@ -27,7 +30,7 @@ type Props<T> = Omit<FlatListProps<T>, 'maintainVisibleContentPosition'> & {
2730
* You can `onStartReachedThreshold` as distance from beginning of list, when this function should be called.
2831
*/
2932
onStartReached: () => Promise<void>;
30-
/** Color or inline loading indicator */
33+
/** Color for inline loading indicator */
3134
activityIndicatorColor?: string;
3235
/**
3336
* Enable autoScrollToTop.
@@ -56,7 +59,6 @@ type Props<T> = Omit<FlatListProps<T>, 'maintainVisibleContentPosition'> & {
5659
/** Custom UI component for footer indicator of FlatList. Only used when `showDefaultLoadingIndicators` is false */
5760
ListFooterComponent?: React.ComponentType;
5861
};
59-
6062
/**
6163
* Note:
6264
* - `onEndReached` and `onStartReached` must return a promise.
@@ -67,20 +69,19 @@ type Props<T> = Omit<FlatListProps<T>, 'maintainVisibleContentPosition'> & {
6769
* - doesn't accept `ListHeaderComponent` via prop, since it is occupied by `HeaderLoadingIndicator`
6870
* Set `showDefaultLoadingIndicators` to use `ListHeaderComponent`.
6971
*/
70-
const BidirectionalFlatList = React.forwardRef(
71-
(
72-
// TODO: Fix typescript generics for ref forwarding.
73-
props: Props<any>,
72+
export const BidirectionalFlatList = (React.forwardRef(
73+
<T extends any>(
74+
props: Props<T>,
7475
ref:
75-
| ((instance: FlatListType | null) => void)
76-
| MutableRefObject<FlatListType | null>
76+
| ((instance: FlatListType<T> | null) => void)
77+
| MutableRefObject<FlatListType<T> | null>
7778
| null
7879
) => {
7980
const {
8081
activityIndicatorColor = 'black',
82+
autoscrollToTopThreshold = 100,
8183
data,
8284
enableAutoscrollToTop,
83-
autoscrollToTopThreshold = 100,
8485
FooterLoadingIndicator,
8586
HeaderLoadingIndicator,
8687
ListHeaderComponent,
@@ -227,15 +228,14 @@ const BidirectionalFlatList = React.forwardRef(
227228

228229
return (
229230
<>
230-
<FlatList
231+
<FlatList<T>
231232
{...props}
232233
ref={ref}
233234
progressViewOffset={50}
234235
ListHeaderComponent={renderHeaderLoadingIndicator}
235236
ListFooterComponent={renderFooterLoadingIndicator}
236237
onEndReached={null}
237238
onScroll={handleScroll}
238-
// @ts-ignore
239239
maintainVisibleContentPosition={{
240240
autoscrollToTopThreshold: enableAutoscrollToTop
241241
? autoscrollToTopThreshold
@@ -246,6 +246,8 @@ const BidirectionalFlatList = React.forwardRef(
246246
</>
247247
);
248248
}
249-
);
249+
) as unknown) as BidirectionalFlatListType;
250250

251-
export { BidirectionalFlatList as FlatList };
251+
type BidirectionalFlatListType = <T extends any>(
252+
props: Props<T>
253+
) => React.ReactElement;

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { BidirectionalFlatList as FlatList } from './BidirectionalFlatList';

0 commit comments

Comments
 (0)