-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: tab-bar support custom icon close #158
- Loading branch information
Showing
34 changed files
with
126 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import React from 'react'; | ||
import { ImageRequireSource, ImageURISource } from 'react-native'; | ||
|
||
export interface TabBarProps { | ||
barTintColor?: string; | ||
tintColor?: string; | ||
unselectedTintColor?: string; | ||
|
||
/** default: false */ | ||
animated?: boolean; | ||
/** default: false */ | ||
swipeable?: boolean; | ||
/** rn android only**/ | ||
styles?: any; | ||
} | ||
export type TabIcon = React.ReactElement<any> | { uri: string }; | ||
export interface TabBarItemProps { | ||
export type TabBarIcon = | ||
| ImageURISource | ||
| ImageURISource[] | ||
| ImageRequireSource | ||
| React.ReactNode; | ||
export interface TabBarItemProps { | ||
badge?: string | number; | ||
onPress?: () => void; | ||
selected?: boolean; | ||
icon?: TabIcon; | ||
selectedIcon?: TabIcon; | ||
icon?: TabBarIcon; | ||
selectedIcon?: TabBarIcon; | ||
title: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,80 @@ | ||
import { Platform } from 'react-native'; | ||
import TabBarAndroid from './tabbar.android'; | ||
import TabBarIOS from './tabbar.ios'; | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
import { WithTheme } from '../style'; | ||
import { TabBarProps } from './PropsType'; | ||
import TabBarStyles, { TabBarStyle } from './style/index'; | ||
import TabBarItem from './TabBarItem'; | ||
|
||
export default (Platform.OS === 'ios' ? TabBarIOS : TabBarAndroid); | ||
export interface TabBarNativeProps extends TabBarProps { | ||
styles?: TabBarStyle; | ||
} | ||
|
||
class TabBar extends React.Component<TabBarNativeProps, any> { | ||
static defaultProps = { | ||
barTintColor: 'white', | ||
tintColor: '#108ee9', | ||
unselectedTintColor: '#888', | ||
}; | ||
|
||
static Item = TabBarItem; | ||
|
||
getPanes(styles: ReturnType<typeof TabBarStyles>, content: boolean) { | ||
const { tintColor, unselectedTintColor, children } = this.props; | ||
// ios 规则: selected 为多个则只选中最后一个, selected 为 0 个则选中第一个; | ||
let selectedIndex = 0; | ||
[].concat(children as any).forEach((child: any, idx: number) => { | ||
if (child.props.selected) { | ||
selectedIndex = idx; | ||
} | ||
}); | ||
const newChildren: any[] = []; | ||
React.Children.map(children, (child: any, idx) => { | ||
if (content) { | ||
newChildren.push( | ||
<View | ||
key={idx} | ||
style={[ | ||
styles.contentItem, | ||
idx === selectedIndex ? styles.contentItemSelected : undefined, | ||
]} | ||
> | ||
{child.props.children} | ||
</View>, | ||
); | ||
} else { | ||
newChildren.push( | ||
React.cloneElement(child, { | ||
key: idx, | ||
tintColor, | ||
unselectedTintColor, | ||
styles, | ||
}), | ||
); | ||
} | ||
}); | ||
|
||
return newChildren; | ||
} | ||
|
||
render() { | ||
return ( | ||
<WithTheme styles={this.props.styles} themeStyles={TabBarStyles}> | ||
{styles => ( | ||
<View style={styles.tabbar}> | ||
<View style={styles.content}>{this.getPanes(styles, true)}</View> | ||
<View | ||
style={[ | ||
styles.tabs, | ||
{ backgroundColor: this.props.barTintColor }, | ||
]} | ||
> | ||
{this.getPanes(styles, false)} | ||
</View> | ||
</View> | ||
)} | ||
</WithTheme> | ||
); | ||
} | ||
} | ||
|
||
export default TabBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.