Skip to content

Commit 23ce1bf

Browse files
authored
TabBar refactor (#1076)
* TabBar - use ScrollBar component, deprecate 'badge' prop (use 'badgeProps' prop instead). TabBarItem - add 'backgroundColor' prop. * Adjustments for Tablet * removing borderwidth * tabletmargins example * remove `useTabletWide` prop * edit comment * removing tabletMargins prop * moving 'darkTheme' prop from TabBarItem to TabBar * passing 'gradientMargins' to ScrollBar * Adding 'containerView' as component container * TabBar - adding 'testID' prop; TabBarItem - removing UNSAFE method, using LogService for deprecation warning, fixing typography * TabBar - removing UNSAFE method * remove redundant prop * applying 'containerWidth' to container * Adding 'fullWidth' to container * replace BaseComponent with asBaseComponent HOC * TabBarItem to asBaseComponent HOC; updating types * fix TabBarItem in TabBar * moving inline styles to stylesheet * bug fix * bug fix * TS errors and generatedTypes
1 parent 8c796b8 commit 23ce1bf

File tree

4 files changed

+379
-428
lines changed

4 files changed

+379
-428
lines changed

demo/src/screens/componentScreens/TabBarScreen.tsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class TabBarScreen extends Component {
3737
do {
3838
index = Math.floor(Math.random() * this.tabbar.props.children.length);
3939
} while (index === this.state.selectedIndex);
40-
40+
4141
this.setState({selectedIndex: index});
4242
}
4343
};
@@ -82,7 +82,7 @@ export default class TabBarScreen extends Component {
8282
removeTab = () => {
8383
const index = this.state.selectedIndex;
8484
const newTabs = this.state.currentTabs;
85-
85+
8686
if (newTabs.length >= 0) {
8787
newTabs.splice(index, 1);
8888
}
@@ -92,7 +92,7 @@ export default class TabBarScreen extends Component {
9292
/** Actions */
9393
getTabs(showAddTab: boolean) {
9494
const tabs = _.map(this.state.currentTabs, tab => this.renderTabs(tab));
95-
95+
9696
if (showAddTab) {
9797
tabs.push(this.renderAddTabsTab());
9898
} else {
@@ -126,15 +126,20 @@ export default class TabBarScreen extends Component {
126126
<ScrollView style={{overflow: 'visible'}} showsVerticalScrollIndicator={false}>
127127
<View bg-dark80>
128128
<TabBar style={styles.tabbar} selectedIndex={0} enableShadow>
129-
<TabBar.Item
130-
label="single tab"
129+
<TabBar.Item
130+
label="single tab"
131131
labelStyle={{color: Colors.green30, fontWeight: 'bold', textTransform: 'capitalize'}}
132132
/>
133133
</TabBar>
134134

135-
<TabBar style={styles.tabbar} selectedIndex={0} enableShadow>
136-
<TabBar.Item label="Fixed" uppercase style={{backgroundColor: Colors.blue80}}/>
137-
<TabBar.Item label="Tab" badge={{label: '100'}} uppercase style={{backgroundColor: Colors.blue80}}/>
135+
<TabBar
136+
style={styles.tabbar}
137+
selectedIndex={0}
138+
enableShadow
139+
// tabletMargins={{portrait: 0, landscape: 0}}
140+
>
141+
<TabBar.Item label="Fixed" uppercase backgroundColor={Colors.blue80}/>
142+
<TabBar.Item label="Tab" badgeProps={{label: '100'}} uppercase style={{backgroundColor: Colors.blue80}}/>
138143
<TabBar.Item label="Bar" uppercase style={{backgroundColor: Colors.blue80}}/>
139144
</TabBar>
140145

@@ -146,7 +151,7 @@ export default class TabBarScreen extends Component {
146151

147152
<TabBar style={styles.tabbar} selectedIndex={0} ref={r => (this.tabbar = r)} enableShadow>
148153
<TabBar.Item label="Scroll"/>
149-
<TabBar.Item label="View" badge={{size: 'pimpleSmall'}}/>
154+
<TabBar.Item label="View" badgeProps={{size: 'pimpleSmall'}}/>
150155
<TabBar.Item label="tab"/>
151156
<TabBar.Item label="bar"/>
152157
<TabBar.Item label="Container"/>
@@ -169,13 +174,20 @@ export default class TabBarScreen extends Component {
169174
{this.getTabs(true)}
170175
</TabBar>
171176

172-
<Button
173-
size={Button.sizes.small}
174-
margin-20
175-
label={`Change index: ${this.state.selectedIndex}`}
176-
onPress={this.changeIndex}
177-
/>
178-
<TabBar style={styles.tabbar} selectedIndex={this.state.selectedIndex} enableShadow backgroundColor={Colors.green70}>
177+
<View center>
178+
<Button
179+
size={Button.sizes.small}
180+
margin-20
181+
label={`Change index: ${this.state.selectedIndex}`}
182+
onPress={this.changeIndex}
183+
/>
184+
</View>
185+
<TabBar
186+
style={styles.tabbar}
187+
selectedIndex={this.state.selectedIndex}
188+
enableShadow
189+
backgroundColor={Colors.green70}
190+
>
179191
<TabBar.Item label="LONG LABEL"/>
180192
<TabBar.Item label="ACTIVE"/>
181193
<TabBar.Item label="INACTIVE"/>
@@ -187,7 +199,7 @@ export default class TabBarScreen extends Component {
187199
<TabBar.Item label="MODE"/>
188200
</TabBar>
189201

190-
<View row>
202+
<View center row>
191203
<Button size={Button.sizes.small} margin-20 label={`Change Labels`} onPress={this.changeLabels}/>
192204
<Button size={Button.sizes.small} margin-20 label={`Change Color`} onPress={this.changeColors}/>
193205
</View>
Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
2-
import { Animated, ViewStyle, TextStyle } from 'react-native';
3-
import { BaseComponentInjectedProps } from '../../commons/new';
2+
import { Animated, StyleProp, ViewStyle, TextStyle } from 'react-native';
43
import { BadgeProps } from '../badge';
5-
export declare type TabBarItemProps = BaseComponentInjectedProps & {
4+
interface Props {
65
/**
76
* icon of the tab
87
*/
@@ -22,19 +21,20 @@ export declare type TabBarItemProps = BaseComponentInjectedProps & {
2221
/**
2322
* custom label style
2423
*/
25-
labelStyle?: TextStyle;
24+
labelStyle?: StyleProp<TextStyle>;
2625
/**
2726
* Badge component props to display next the item label
2827
*/
2928
badge?: BadgeProps;
29+
badgeProps?: BadgeProps;
3030
/**
3131
* maximum number of lines the label can break
3232
*/
3333
maxLines?: number;
3434
/**
3535
* custom selected tab label style
3636
*/
37-
selectedLabelStyle: TextStyle;
37+
selectedLabelStyle?: StyleProp<TextStyle>;
3838
/**
3939
* whether the tab is selected or not
4040
*/
@@ -47,14 +47,18 @@ export declare type TabBarItemProps = BaseComponentInjectedProps & {
4747
* A fixed width for the item
4848
*/
4949
width?: number;
50+
/**
51+
* tabBar's background color
52+
*/
53+
backgroundColor?: string;
5054
/**
5155
* ignore of the tab
5256
*/
5357
ignore?: boolean;
5458
/**
5559
* callback for when pressing a tab
5660
*/
57-
onPress?: (props: any) => void;
61+
onPress?: () => void;
5862
/**
5963
* whether to change the text to uppercase
6064
*/
@@ -63,78 +67,17 @@ export declare type TabBarItemProps = BaseComponentInjectedProps & {
6367
* Apply background color on press for TouchableOpacity
6468
*/
6569
activeBackgroundColor?: string;
66-
indicatorStyle?: ViewStyle;
70+
accessibilityLabel?: string;
71+
indicatorStyle?: StyleProp<ViewStyle>;
6772
style?: ViewStyle;
6873
testID?: string;
69-
};
70-
export declare type State = {
71-
indicatorOpacity?: Animated.Value;
72-
};
73-
declare const _default: React.ComponentClass<BaseComponentInjectedProps & {
74-
/**
75-
* icon of the tab
76-
*/
77-
icon?: number | undefined;
78-
/**
79-
* icon tint color
80-
*/
81-
iconColor?: string | undefined;
82-
/**
83-
* icon selected tint color
84-
*/
85-
iconSelectedColor?: string | undefined;
86-
/**
87-
* label of the tab
88-
*/
89-
label?: string | undefined;
90-
/**
91-
* custom label style
92-
*/
93-
labelStyle?: TextStyle | undefined;
94-
/**
95-
* Badge component props to display next the item label
96-
*/
97-
badge?: BadgeProps | undefined;
98-
/**
99-
* maximum number of lines the label can break
100-
*/
101-
maxLines?: number | undefined;
102-
/**
103-
* custom selected tab label style
104-
*/
105-
selectedLabelStyle: TextStyle;
106-
/**
107-
* whether the tab is selected or not
108-
*/
109-
selected?: boolean | undefined;
110-
/**
111-
* whether the tab will have a divider on its right
112-
*/
113-
showDivider?: boolean | undefined;
114-
/**
115-
* A fixed width for the item
116-
*/
117-
width?: number | undefined;
118-
/**
119-
* ignore of the tab
120-
*/
121-
ignore?: boolean | undefined;
122-
/**
123-
* callback for when pressing a tab
124-
*/
125-
onPress?: ((props: any) => void) | undefined;
126-
/**
127-
* whether to change the text to uppercase
128-
*/
129-
uppercase?: boolean | undefined;
130-
/**
131-
* Apply background color on press for TouchableOpacity
132-
*/
133-
activeBackgroundColor?: string | undefined;
134-
indicatorStyle?: ViewStyle | undefined;
135-
style?: ViewStyle | undefined;
136-
testID?: string | undefined;
137-
} & {
74+
}
75+
interface State {
76+
indicatorOpacity: Animated.Value;
77+
selected?: boolean;
78+
}
79+
export declare type TabBarItemProps = Props;
80+
declare const _default: React.ComponentClass<Props & {
13881
useCustomTheme?: boolean | undefined;
13982
}, any> & State;
14083
export default _default;

0 commit comments

Comments
 (0)