Skip to content

Commit 1543e6e

Browse files
authored
Remove old implementations of TabController (#1555)
1 parent 757d64d commit 1543e6e

35 files changed

+468
-2197
lines changed

demo/src/screens/componentScreens/TabControllerScreen/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,14 @@ class TabControllerScreen extends Component<{}, State> {
146146
}
147147

148148
render() {
149-
const {key, selectedIndex, asCarousel, centerSelected, fewItems, items} = this.state;
149+
const {key, /* selectedIndex, */ asCarousel, centerSelected, fewItems, items} = this.state;
150150
return (
151151
<View flex bg-grey70>
152152
<TabController
153153
key={key}
154154
asCarousel={asCarousel}
155-
selectedIndex={selectedIndex}
155+
// selectedIndex={selectedIndex}
156+
initialIndex={0}
156157
onChangeIndex={this.onChangeIndex}
157158
items={items}
158159
>

generatedTypes/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export {default as SegmentedControl, SegmentedControlProps, SegmentedControlItem
5757
export {default as Slider, SliderProps} from './src/components/slider';
5858
export {default as Switch, SwitchProps} from './src/components/switch';
5959
export {default as TabController, TabControllerProps, TabControllerItemProps} from './src/components/tabController';
60-
export {default as TabController2} from './src/components/tabController2';
6160
export {default as TabBar, TabBarProps} from './src/components/TabBar';
6261
export {default as ScrollBar, ScrollBarProps} from './src/components/ScrollBar';
6362
export {default as StackAggregator, StackAggregatorProps} from './src/components/stackAggregator';
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
import React, { PureComponent } from 'react';
2-
import _ from 'lodash';
3-
import Animated from 'react-native-reanimated';
1+
/// <reference types="react" />
42
/**
53
* @description: TabController's Page Carousel
64
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.tsx
75
* @notes: You must pass `asCarousel` flag to TabController and render your TabPages inside a PageCarousel
86
*/
9-
declare class PageCarousel extends PureComponent {
10-
static displayName: string;
11-
static contextType: React.Context<{}>;
12-
carousel: React.RefObject<Animated.ScrollView>;
13-
onScroll: (...args: any[]) => void;
14-
componentDidMount(): void;
15-
onTabChange: ([index]: readonly number[]) => void;
16-
scrollToPage: (pageIndex: number) => void;
17-
renderCodeBlock: (() => JSX.Element) & _.MemoizedFunction;
18-
render(): JSX.Element;
19-
}
7+
declare function PageCarousel({ ...props }: {
8+
[x: string]: any;
9+
}): JSX.Element;
2010
export default PageCarousel;

generatedTypes/src/components/tabController/TabBar.d.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import React from 'react';
2-
import { TextProps, StyleProp, ViewStyle } from 'react-native';
2+
import { StyleProp, ViewStyle } from 'react-native';
33
import { TabControllerItemProps } from './TabBarItem';
44
export interface TabControllerBarProps {
55
/**
66
* The list of tab bar items
77
*/
88
items?: TabControllerItemProps[];
9-
/**
10-
* Whether the tabBar should be spread (default: true)
11-
*/
12-
spreadItems?: boolean;
139
/**
1410
* Tab Bar height
1511
*/
@@ -26,18 +22,14 @@ export interface TabControllerBarProps {
2622
* custom style for the selected indicator
2723
*/
2824
indicatorStyle?: StyleProp<ViewStyle>;
29-
/**
30-
* the indicator insets (default: Spacings.s4, set to 0 to make it wide as the item)
31-
*/
32-
indicatorInsets?: number;
3325
/**
3426
* custom label style
3527
*/
36-
labelStyle?: TextProps;
28+
labelStyle?: TabControllerItemProps['labelStyle'];
3729
/**
3830
* custom selected label style
3931
*/
40-
selectedLabelStyle?: TextProps;
32+
selectedLabelStyle?: TabControllerItemProps['selectedLabelStyle'];
4133
/**
4234
* the default label color
4335
*/
@@ -76,13 +68,17 @@ export interface TabControllerBarProps {
7668
*/
7769
centerSelected?: boolean;
7870
/**
79-
* Additional styles for the container
71+
* Whether the tabBar should be spread (default: true)
8072
*/
81-
containerStyle?: StyleProp<ViewStyle>;
73+
spreadItems?: boolean;
74+
/**
75+
* The indicator insets (default: Spacings.s4, set to 0 to make it wide as the item)
76+
*/
77+
indicatorInsets?: number;
8278
/**
83-
* Additional styles for the ScrollView
79+
* Additional styles for the container
8480
*/
85-
scrollViewStyle?: StyleProp<ViewStyle>;
81+
containerStyle?: StyleProp<ViewStyle>;
8682
/**
8783
* Used as a testing identifier
8884
*/
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
import React from 'react';
2-
declare const TabBarContext: React.Context<{}>;
2+
import Reanimated from 'react-native-reanimated';
3+
interface TabControllerContext {
4+
initialIndex?: number;
5+
selectedIndex?: number;
6+
items?: any[];
7+
asCarousel?: boolean;
8+
containerWidth: number;
9+
pageWidth: number;
10+
/** static page index */
11+
currentPage: Reanimated.SharedValue<number>;
12+
/** transition page index (can be a fraction when transitioning between pages) */
13+
targetPage: Reanimated.SharedValue<number>;
14+
carouselOffset: Reanimated.SharedValue<number>;
15+
}
16+
declare const TabBarContext: React.Context<TabControllerContext>;
317
export default TabBarContext;

generatedTypes/src/components/tabController/TabBarItem.d.ts

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { PureComponent, ReactElement } from 'react';
2-
import { /* processColor, */ TextStyle, LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';
3-
import _ from 'lodash';
1+
import { ReactElement } from 'react';
2+
import { TextStyle, LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';
43
import Reanimated from 'react-native-reanimated';
5-
import { State } from 'react-native-gesture-handler';
6-
import { BadgeProps } from '../../components/badge';
4+
import { BadgeProps } from '../badge';
75
export interface TabControllerItemProps {
86
/**
97
* label of the tab
@@ -12,11 +10,11 @@ export interface TabControllerItemProps {
1210
/**
1311
* custom label style
1412
*/
15-
labelStyle?: TextStyle;
13+
labelStyle?: StyleProp<TextStyle>;
1614
/**
1715
* custom selected label style
1816
*/
19-
selectedLabelStyle?: TextStyle;
17+
selectedLabelStyle?: StyleProp<TextStyle>;
2018
/**
2119
* the default label color
2220
*/
@@ -49,12 +47,6 @@ export interface TabControllerItemProps {
4947
* Pass to render a trailing element
5048
*/
5149
trailingAccessory?: ReactElement;
52-
/**
53-
* maximun number of lines the label can break
54-
*/
55-
/**
56-
* whether the tab will have a divider on its right
57-
*/
5850
/**
5951
* A fixed width for the item
6052
*/
@@ -88,15 +80,10 @@ export interface TabControllerItemProps {
8880
* Used as a testing identifier
8981
*/
9082
testID?: string;
91-
/**
92-
* disables icon's tint color
93-
*/
94-
disableIconTintColor?: boolean;
9583
}
9684
interface Props extends TabControllerItemProps {
9785
index: number;
9886
targetPage: any;
99-
state: State;
10087
currentPage: Reanimated.Adaptable<number>;
10188
onLayout?: (event: LayoutChangeEvent, index: number) => void;
10289
}
@@ -105,22 +92,5 @@ interface Props extends TabControllerItemProps {
10592
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.tsx
10693
* @notes: Must be rendered as a direct child of TabController.TabBar.
10794
*/
108-
export default class TabBarItem extends PureComponent<Props> {
109-
static displayName: string;
110-
static defaultProps: {
111-
activeOpacity: number;
112-
onPress: (...args: any[]) => void;
113-
};
114-
private itemWidth?;
115-
private itemRef;
116-
constructor(props: Props);
117-
onLayout: (event: LayoutChangeEvent) => void;
118-
onPress: () => void;
119-
getItemStyle(): any[];
120-
getLabelStyle(): (TextStyle | _.Dictionary<Reanimated.Node<number> | Reanimated.Node<string | number> | Reanimated.Node<string | number | boolean> | Reanimated.Node<"normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900"> | undefined> | undefined)[];
121-
getIconStyle(): {
122-
tintColor: Reanimated.Node<string>;
123-
} | undefined;
124-
render(): JSX.Element;
125-
}
95+
export default function TabBarItem({ index, label, labelColor, selectedLabelColor, labelStyle, selectedLabelStyle, icon, badge, leadingAccessory, trailingAccessory, uppercase, activeOpacity, activeBackgroundColor, testID, ignore, style, ...props }: Props): JSX.Element;
12696
export {};
Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import React, { PureComponent } from 'react';
2-
import Reanimated from 'react-native-reanimated';
3-
import _ from 'lodash';
1+
import { PropsWithChildren } from 'react';
42
export interface TabControllerPageProps {
53
/**
64
* The index of the the TabPage
@@ -27,45 +25,4 @@ export interface TabControllerPageProps {
2725
* @description: TabController's TabPage
2826
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.tsx
2927
*/
30-
export default class TabPage extends PureComponent<TabControllerPageProps> {
31-
static displayName: string;
32-
static contextType: React.Context<{}>;
33-
static defaultProps: {
34-
lazy: boolean;
35-
activeOpacity: number;
36-
lazyLoadTime: number;
37-
renderLoading: (...args: any[]) => void;
38-
};
39-
state: {
40-
loaded: boolean;
41-
};
42-
_loaded: Reanimated.Value<number>;
43-
_opacity: Reanimated.Value<0>;
44-
_zIndex: Reanimated.Value<0>;
45-
_pageStyle: ({
46-
position: "absolute";
47-
left: 0;
48-
right: 0;
49-
top: 0;
50-
bottom: 0;
51-
} | {
52-
width: number;
53-
flex: number;
54-
opacity: number;
55-
} | {
56-
opacity: Reanimated.Value<0>;
57-
width?: undefined;
58-
zIndex?: undefined;
59-
} | {
60-
width: any;
61-
opacity?: undefined;
62-
zIndex?: undefined;
63-
} | {
64-
zIndex: Reanimated.Value<0>;
65-
opacity?: undefined;
66-
width?: undefined;
67-
} | undefined)[];
68-
lazyLoad: () => void;
69-
renderCodeBlock: (() => JSX.Element) & _.MemoizedFunction;
70-
render(): JSX.Element;
71-
}
28+
export default function TabPage({ testID, index, lazy, renderLoading, ...props }: PropsWithChildren<TabControllerPageProps>): JSX.Element;

generatedTypes/src/components/tabController/index.d.ts

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import React, { Component } from 'react';
2-
import _ from 'lodash';
3-
import TabBar from './TabBar';
4-
import TabBarItem, { TabControllerItemProps } from './TabBarItem';
5-
import TabPage from './TabPage';
6-
import PageCarousel from './PageCarousel';
1+
import React, { PropsWithChildren } from 'react';
2+
import { TabControllerItemProps } from './TabBarItem';
73
export { TabControllerItemProps };
84
export interface TabControllerProps {
95
/**
@@ -13,11 +9,15 @@ export interface TabControllerProps {
139
/**
1410
* Initial selected index
1511
*/
16-
selectedIndex: number;
12+
initialIndex?: number;
13+
/**
14+
* DEPRECATED: use initialIndex instead
15+
*/
16+
selectedIndex?: number;
1717
/**
1818
* callback for when index has change (will not be called on ignored items)
1919
*/
20-
onChangeIndex?: (index: number) => void;
20+
onChangeIndex?: (index: number, prevIndex: number | null) => void;
2121
/**
2222
* When using TabController.PageCarousel this should be turned on
2323
*/
@@ -27,49 +27,21 @@ export interface TabControllerProps {
2727
*/
2828
carouselPageWidth?: number;
2929
}
30-
interface StateProps {
31-
selectedIndex: number;
32-
asCarousel?: boolean;
33-
pageWidth: number;
34-
items: TabControllerProps['items'];
35-
itemStates: any[];
36-
ignoredItems: any[];
37-
targetPage: any;
38-
currentPage: any;
39-
carouselOffset: any;
40-
containerWidth: any;
41-
registerTabItems: (tabItemsCount: number, ignoredItems: StateProps['ignoredItems']) => void;
42-
onChangeIndex?: (index: number) => void;
43-
}
4430
/**
4531
* @description: A performant solution for a tab controller with lazy load mechanism
4632
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.tsx
4733
* @notes: This component is based on react-native-gesture-handler
4834
* @important: On Android, if using react-native-navigation, make sure to wrap your screen with gestureHandlerRootHOC
4935
* @importantLink: https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html#with-wix-react-native-navigation-https-githubcom-wix-react-native-navigation
50-
* @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/TabController/Default.gif?raw=true, https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/TabController/PageCarousel.gif?raw=true, https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/TabController/CenterSelected.gif?raw=true
5136
*/
52-
declare class TabController extends Component<TabControllerProps, StateProps> {
53-
static displayName: string;
54-
static contextType: React.Context<{}>;
55-
static TabBar: typeof TabBar;
56-
static TabBarItem: typeof TabBarItem;
57-
static TabPage: typeof TabPage;
58-
static PageCarousel: typeof PageCarousel;
59-
static defaultProps: {
60-
selectedIndex: number;
61-
activeOpacity: number;
62-
};
63-
constructor(props: TabControllerProps);
64-
static getDerivedStateFromProps(nextProps: TabControllerProps, prevState: StateProps): {
65-
pageWidth: number;
66-
} | null;
67-
componentDidUpdate(_prevProps: TabControllerProps, prevState: StateProps): void;
68-
get pageWidth(): number;
69-
registerTabItems: (tabItemsCount: number, ignoredItems: StateProps['ignoredItems']) => void;
70-
onPageChange: ([index]: readonly number[]) => void;
71-
renderCodeBlock: (() => JSX.Element) & _.MemoizedFunction;
72-
render(): JSX.Element;
37+
declare function TabController({ initialIndex, selectedIndex, asCarousel, items, onChangeIndex, carouselPageWidth, children }: PropsWithChildren<TabControllerProps>): JSX.Element;
38+
declare namespace TabController {
39+
var TabBar: React.ComponentClass<import("./TabBar").TabControllerBarProps & {
40+
useCustomTheme?: boolean | undefined;
41+
}, any>;
42+
var TabBarItem: typeof import("./TabBarItem").default;
43+
var TabPage: typeof import("./TabPage").default;
44+
var PageCarousel: typeof import("./PageCarousel").default;
7345
}
7446
declare const _default: React.ComponentClass<TabControllerProps & {
7547
useCustomTheme?: boolean | undefined;

generatedTypes/src/components/tabController2/FadedScrollView.d.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

generatedTypes/src/components/tabController2/PageCarousel.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)