Skip to content

Commit 58bf14e

Browse files
committed
react-native-tab-view upgrade
1 parent 963d48e commit 58bf14e

File tree

8 files changed

+1552
-1604
lines changed

8 files changed

+1552
-1604
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ npm install react-native-tab-view-easy
1313
```
1414

1515

16-
Now we need to install `react-native-tab-view`, `react-native-gesture-handler` and `react-native-reanimated`
16+
Now we need to install `react-native-tab-view` and `react-native-pager-view`
1717

1818
```sh
19-
yarn add react-native-tab-view react-native-gesture-handler react-native-reanimated
19+
yarn add react-native-tab-view react-native-pager-view
2020
```
2121
OR
2222
```sh
23-
npm install react-native-tab-view react-native-gesture-handler react-native-reanimated
23+
npm install react-native-tab-view react-native-pager-view
2424
```
2525
## Usage
2626

@@ -40,6 +40,8 @@ import { TabView, Tab } from 'react-native-tab-view-easy';
4040
</TabView>
4141
```
4242

43+
##[API reference](https://github.com/satya164/react-native-tab-view#api-reference)
44+
4345
## License
4446

4547
MIT

example/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = function (api) {
1010
[
1111
'module-resolver',
1212
{
13+
extensions: ['.tsx', '.ts', '.js', '.json'],
1314
alias: {
1415
// For development, we want to alias the library to the source
1516
[pak.name]: path.join(__dirname, '..', pak.source),

example/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
"react": "16.13.1",
1818
"react-dom": "16.13.1",
1919
"react-native": "0.63.4",
20-
"react-native-gesture-handler": "^1.10.1",
21-
"react-native-reanimated": "^1.13.2",
22-
"react-native-tab-view": "^2.15.2",
20+
"react-native-pager-view": "^5.1.2",
21+
"react-native-tab-view": "^3.0.0",
2322
"react-native-unimodules": "~0.12.0",
2423
"react-native-web": "~0.14.9"
2524
},

example/yarn.lock

Lines changed: 785 additions & 952 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A cross-platform Tab View component for React Native based on react-native-tab-view with easier syntax",
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": [
@@ -35,6 +35,7 @@
3535
"react-native",
3636
"ios",
3737
"android",
38+
"react-native-web",
3839
"react-native-tab-view",
3940
"react-native-tab",
4041
"tabs"
@@ -66,16 +67,15 @@
6667
"prettier": "^2.0.5",
6768
"react": "16.13.1",
6869
"react-native": "0.63.4",
70+
"react-native-tab-view": "^3.0.0",
6971
"react-native-builder-bob": "^0.17.1",
7072
"release-it": "^14.2.2",
7173
"typescript": "^4.1.3"
7274
},
7375
"peerDependencies": {
7476
"react": "*",
75-
"react-native": "*"
76-
},
77-
"dependencies": {
78-
"react-native-tab-view": "^2.15.2"
77+
"react-native": "*",
78+
"react-native-tab-view": "*"
7979
},
8080
"jest": {
8181
"preset": "react-native",

src/index.tsx

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
11
import React, { useState, useEffect, useRef, ReactNode } from 'react';
2-
import { TabView as TabViewOriginal, Route } from 'react-native-tab-view';
3-
import { View, Dimensions, StyleProp, ViewStyle } from 'react-native';
4-
import type { SceneRendererProps } from 'react-native-tab-view';
5-
6-
const initialLayout = { width: Dimensions.get('window').width };
2+
import {
3+
TabView as TabViewOriginal,
4+
Route,
5+
TabViewProps as TabViewPropsOriginal,
6+
} from 'react-native-tab-view';
7+
import { View, useWindowDimensions } from 'react-native';
78

89
interface ScenesMap {
910
[key: string]: ReactNode;
1011
}
1112

1213
export type TabViewProps = {
1314
enableOptimizations?: boolean;
14-
onIndexChange?: (index: number) => void;
15-
renderTabBar?: (props: SceneRendererProps) => React.ReactNode;
16-
tabBarPosition?: 'top' | 'bottom';
17-
initialLayout?: {
18-
width?: number;
19-
height?: number;
20-
};
21-
lazy?: boolean;
22-
lazyPreloadDistance?: number;
23-
removeClippedSubviews?: boolean;
24-
sceneContainerStyle?: StyleProp<ViewStyle>;
25-
style?: StyleProp<ViewStyle>;
26-
children?: ReactNode;
27-
};
15+
children: ReactNode;
16+
} & Omit<
17+
Partial<TabViewPropsOriginal<Route>>,
18+
'navigationState' | 'renderScene' | 'onIndexChange'
19+
>;
2820

2921
export const TabView = (props: TabViewProps) => {
3022
const [index, setIndex] = useState(0);
3123
const [routes, setRoutes] = useState<Route[]>([]);
3224
const scenes = useRef<ScenesMap>({});
3325

26+
const layout = useWindowDimensions();
27+
3428
useEffect(() => {
3529
if (props.children) {
3630
let newRoutes: Route[] = [];
@@ -55,7 +49,7 @@ export const TabView = (props: TabViewProps) => {
5549
}
5650
}, [props.children]);
5751

58-
const renderScene = ({ route }: { route: any }) => {
52+
const renderScene = ({ route }: { route: Route }) => {
5953
if (
6054
props.enableOptimizations &&
6155
Math.abs(index - routes.findIndex((item) => item.key === route.key)) > 2
@@ -69,15 +63,19 @@ export const TabView = (props: TabViewProps) => {
6963
return null;
7064
};
7165

72-
return (
73-
<TabViewOriginal
74-
{...props}
75-
navigationState={{ index, routes }}
76-
renderScene={renderScene}
77-
onIndexChange={setIndex}
78-
initialLayout={initialLayout}
79-
/>
80-
);
66+
if (routes.length) {
67+
return (
68+
// @ts-ignore
69+
<TabViewOriginal
70+
{...props}
71+
navigationState={{ index, routes }}
72+
renderScene={renderScene}
73+
onIndexChange={setIndex}
74+
initialLayout={props.initialLayout || { width: layout.width }}
75+
/>
76+
);
77+
}
78+
return null;
8179
};
8280

8381
export type TabProps = {
@@ -91,5 +89,5 @@ export type TabProps = {
9189
};
9290

9391
export const Tab = (props: TabProps) => {
94-
return <React.Fragment>{props.children}</React.Fragment>;
92+
return <>{props.children}</>;
9593
};

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"baseUrl": ".",
3+
"baseUrl": "./",
44
"paths": {
55
"react-native-tab-view-easy": ["./src/index"]
66
},

0 commit comments

Comments
 (0)