Skip to content

Commit

Permalink
v3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iRoachie authored Feb 27, 2018
2 parents 15d288a + bbdbe93 commit f5af7a2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/__tests__/__snapshots__/main.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`Main should apply custom fontFamily to tab 1`] = `
<View
barColor="#13897b"
barHeight={48}
onLayout={[Function]}
style={
Array [
Expand All @@ -21,6 +22,7 @@ exports[`Main should apply custom fontFamily to tab 1`] = `
>
<View>
<View
barHeight={48}
style={
Array [
Object {
Expand Down Expand Up @@ -69,6 +71,7 @@ exports[`Main should apply custom fontFamily to tab 1`] = `
undefined,
]
}
tabHeight={48}
>
<Text
accessible={true}
Expand Down Expand Up @@ -133,6 +136,7 @@ exports[`Main should apply custom fontFamily to tab 1`] = `
undefined,
]
}
tabHeight={48}
>
<Text
accessible={true}
Expand Down Expand Up @@ -187,6 +191,7 @@ exports[`Main should apply custom fontFamily to tab 1`] = `
exports[`Main should render without errors 1`] = `
<View
barColor="#13897b"
barHeight={48}
onLayout={[Function]}
style={
Array [
Expand All @@ -205,6 +210,7 @@ exports[`Main should render without errors 1`] = `
>
<View>
<View
barHeight={48}
style={
Array [
Object {
Expand Down Expand Up @@ -253,6 +259,7 @@ exports[`Main should render without errors 1`] = `
undefined,
]
}
tabHeight={48}
>
<Text
accessible={true}
Expand Down Expand Up @@ -315,6 +322,7 @@ exports[`Main should render without errors 1`] = `
undefined,
]
}
tabHeight={48}
>
<Text
accessible={true}
Expand Down
7 changes: 6 additions & 1 deletion src/components/MaterialTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import PropTypes from 'prop-types';
import { Animated, ScrollView, View, Text } from 'react-native';
import type { StyleObj } from '../lib/definitions';
import { Bar, TabTrack } from '../lib/styles';
import values from '../lib/values';
import Tab from './Tab';
import Indicator from './Indicator';

type Props = {
selectedIndex: number,
barColor: string,
barHeight: number,
activeTextColor: string,
indicatorColor: string,
inactiveTextColor: string,
Expand Down Expand Up @@ -42,6 +44,7 @@ export default class MaterialTabs extends React.Component<Props, State> {
static defaultProps = {
selectedIndex: 0,
barColor: '#13897b',
barHeight: values.barHeight,
activeTextColor: '#fff',
indicatorColor: '#fff',
inactiveTextColor: 'rgba(255, 255, 255, 0.7)',
Expand Down Expand Up @@ -149,6 +152,7 @@ export default class MaterialTabs extends React.Component<Props, State> {
<Bar
innerRef={ref => (this.bar = ref)}
barColor={this.props.barColor}
barHeight={this.props.barHeight}
onLayout={event => this.getTabWidth(event.nativeEvent.layout.width)}
>
<ScrollView
Expand All @@ -157,7 +161,7 @@ export default class MaterialTabs extends React.Component<Props, State> {
showsHorizontalScrollIndicator={false}
scrollEnabled={this.props.scrollable}
>
<TabTrack>
<TabTrack barHeight={this.props.barHeight}>
{this.props.items.map((item, idx) => (
<Tab
text={item}
Expand All @@ -167,6 +171,7 @@ export default class MaterialTabs extends React.Component<Props, State> {
active={idx === this.props.selectedIndex}
activeTextColor={this.props.activeTextColor}
textStyle={this.props.textStyle}
tabHeight={this.props.barHeight}
tabWidth={
!this.props.scrollable
? this.state.tabWidth
Expand Down
4 changes: 3 additions & 1 deletion src/components/Tab/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { StyleObj } from '../../lib/definitions';
type TabProps = {
text: string,
tabWidth: number,
tabHeight: number,
stretch: boolean,
activeTextColor: string,
inActiveTextColor: string,
Expand All @@ -22,14 +23,15 @@ const Tab = ({
text,
inActiveTextColor,
tabWidth,
tabHeight,
stretch,
textStyle,
}: TabProps) => {
const color = active ? activeTextColor : inActiveTextColor;

return (
<TabButton onPress={onPress} tabWidth={tabWidth} stretch={stretch}>
<TabBody>
<TabBody tabHeight={tabHeight}>
<TabText color={color} style={textStyle}>
{text.toUpperCase()}
</TabText>
Expand Down
7 changes: 5 additions & 2 deletions src/components/Tab/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import styled from 'styled-components/native';
import { Platform } from 'react-native';
import Button from '../Touchable';
import values from '../../lib/values';

type TabBodyProps = {
tabHeight: number,
};

export const TabBody = styled.View`
height: ${values.barHeight};
height: ${(props: TabBodyProps) => props.tabHeight};
align-items: center;
justify-content: center;
padding-horizontal: 12px;
Expand Down
7 changes: 7 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ interface TabsProps {
*/
barColor?: string;

/**
* Height of the tab bar
*
* Default is 48
*/
barHeight?: number;

/**
* Color of the text for the selected tab
*
Expand Down
10 changes: 7 additions & 3 deletions src/lib/styles.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
// @flow

import styled from 'styled-components/native';
import values from './values';

type BarProps = {
barColor: string,
barHeight: number,
};

type TabProps = {
barHeight: number,
}

const Bar = styled.View`
background-color: ${(props: BarProps) => props.barColor};
height: ${values.barHeight};
height: ${(props: BarProps) => props.barHeight};
`;

const TabTrack = styled.View`
flex-direction: row;
height: 46;
height: ${(props: BarProps) => props.barHeight - 2};
`;

export { Bar, TabTrack };

0 comments on commit f5af7a2

Please sign in to comment.