Skip to content

Commit

Permalink
update styles for react-native.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang740 committed Sep 5, 2017
1 parent a7559bf commit 5422b34
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 56 deletions.
2 changes: 0 additions & 2 deletions examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { Models, Tabs, DefaultTabBar } from '../src';

const en = location.search.indexOf('en') !== -1;

class BasicDemo extends React.Component<{}, any> {

constructor(props: any) {
Expand Down
4 changes: 2 additions & 2 deletions examples/react-native/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const renderContent = (tab: Models.TabData, index: number) =>
</ScrollView>
;

const SwipeoutExample = () => (
const TabsExample = () => (
<View style={{ flex: 1 }}>
<Tabs tabs={[
{ title: 'First Tab' },
Expand All @@ -37,5 +37,5 @@ const SwipeoutExample = () => (
</View>
);

export const Demo = SwipeoutExample;
export const Demo = TabsExample;
export const title = 'Simple';
6 changes: 3 additions & 3 deletions examples/react-native/scrolltabbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Tabs, Models } from '../../src';
import React from 'react';

const renderContent = (tab: Models.TabData, index: number) =>
<ScrollView>
<ScrollView style={{ backgroundColor: '#fff' }}>
{
[1, 2, 3, 4, 5, 6, 7, 8].map(i => <View key={`${index}_${i}`}
style={{
Expand All @@ -23,7 +23,7 @@ const renderContent = (tab: Models.TabData, index: number) =>
</ScrollView>
;

const SwipeoutExample = () => (
const TabsExample = () => (
<View style={{ flex: 1 }}>
<Tabs tabs={[
{ title: 'First Tab' },
Expand All @@ -42,5 +42,5 @@ const SwipeoutExample = () => (
</View>
);

export const Demo = SwipeoutExample;
export const Demo = TabsExample;
export const title = 'Scroll TabBar';
2 changes: 0 additions & 2 deletions examples/scroll-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { Models, Tabs, DefaultTabBar } from '../src';

const en = location.search.indexOf('en') !== -1;

const tabData = [
{ title: 'tit 1' },
{ title: 'tit 2' },
Expand Down
2 changes: 0 additions & 2 deletions examples/single-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { Models, Tabs, DefaultTabBar } from '../src';

const en = location.search.indexOf('en') !== -1;

const tabData = [
{ title: 't1' },
{ title: 't2' },
Expand Down
2 changes: 0 additions & 2 deletions examples/sticky.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import ReactDOM from 'react-dom';
import { StickyContainer, Sticky } from 'react-sticky';
import { Models, Tabs, DefaultTabBar } from '../src';

const en = location.search.indexOf('en') !== -1;

class BasicDemo extends React.Component<{}, {
}> {

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rmc-tabs",
"version": "0.5.0",
"version": "0.5.1",
"description": "React Mobile Tabs Component(web & react-native)",
"keywords": [
"react",
Expand Down
38 changes: 9 additions & 29 deletions src/DefaultTabBar.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from 'react-native';
import { TabBarPropsType } from './PropsType';
import { Models } from './Models';
import Styles from './Styles.native';

const WINDOW_WIDTH = Dimensions.get('window').width;

Expand All @@ -20,7 +21,7 @@ export interface PropsType extends TabBarPropsType {
page?: number;

scrollValue?: any;
style?: RN.ViewStyle;
styles?: typeof Styles;
tabStyle?: RN.ViewStyle;
tabsContainerStyle?: RN.ViewStyle;
/** default: false */
Expand All @@ -44,6 +45,7 @@ export class DefaultTabBar extends React.PureComponent<PropsType, StateType> {
tabBarActiveTextColor: '#108ee9',
tabBarTextStyle: {},
dynamicTabUnderlineWidth: false,
styles: Styles,
} as PropsType;

_tabsMeasurements: any[] = [];
Expand Down Expand Up @@ -139,6 +141,7 @@ export class DefaultTabBar extends React.PureComponent<PropsType, StateType> {
tabBarInactiveTextColor: inactiveTextColor,
tabBarTextStyle: textStyle,
activeTab, goToTab, renderTab,
styles = Styles
} = this.props;
const isTabActive = activeTab === index;
const textColor = isTabActive ? activeTextColor : inactiveTextColor;
Expand All @@ -154,7 +157,7 @@ export class DefaultTabBar extends React.PureComponent<PropsType, StateType> {
onLayout={onLayoutHandler}
>
<View style={{
...Styles.tab,
...styles.TabBar.tab,
...this.props.tabStyle,
width,
}}>
Expand Down Expand Up @@ -182,7 +185,8 @@ export class DefaultTabBar extends React.PureComponent<PropsType, StateType> {
tabs, page = 1,
tabBarUnderlineStyle,
tabBarActiveTextColor,
tabBarBackgroundColor, style,
tabBarBackgroundColor,
styles = Styles,
tabsContainerStyle
} = this.props;

Expand All @@ -203,9 +207,8 @@ export class DefaultTabBar extends React.PureComponent<PropsType, StateType> {

return <View
style={{
...Styles.container,
...Styles.TabBar.container,
backgroundColor: tabBarBackgroundColor,
...style,
}}
onLayout={this.onContainerLayout}
>
Expand All @@ -221,7 +224,7 @@ export class DefaultTabBar extends React.PureComponent<PropsType, StateType> {
>
<View
style={{
...Styles.tabs,
...styles.TabBar.tabs,
...tabsContainerStyle,
}}
ref={'tabContainer'}
Expand Down Expand Up @@ -265,26 +268,3 @@ export class DefaultTabBar extends React.PureComponent<PropsType, StateType> {
this.updateView({ value: this.props.scrollValue._value, });
}
}

const Styles = {
container: {
height: 43.5,
} as RN.ViewStyle,
tabs: {
flex: 1,
flexDirection: 'row',
height: 43.5,
backgroundColor: '#fff',
justifyContent: 'space-around'
} as RN.ViewStyle,
tab: {
height: 43.5,
alignItems: 'center',
justifyContent: 'center',
paddingTop: 0,
paddingBottom: 0,
paddingRight: 2,
paddingLeft: 2,
flexDirection: 'row'
} as RN.ViewStyle,
};
39 changes: 39 additions & 0 deletions src/Styles.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as RN from 'react-native';

export default {
Tabs: {
container: {
flex: 1,
} as RN.ViewStyle,
topTabBarSplitLine: {
borderBottomColor: '#eee',
borderBottomWidth: 1,
} as RN.ViewStyle,
bottomTabBarSplitLine: {
borderTopColor: '#eee',
borderTopWidth: 1,
} as RN.ViewStyle,
},
TabBar: {
container: {
height: 43.5,
},
tabs: {
flex: 1,
flexDirection: 'row',
height: 43.5,
backgroundColor: '#fff',
justifyContent: 'space-around',
} as RN.ViewStyle,
tab: {
height: 43.5,
alignItems: 'center',
justifyContent: 'center',
paddingTop: 0,
paddingBottom: 0,
paddingRight: 2,
paddingLeft: 2,
flexDirection: 'row'
} as RN.ViewStyle,
},
};
27 changes: 14 additions & 13 deletions src/Tabs.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PropsType as BasePropsType } from './PropsType';
import { Tabs as Component, StateType as BaseStateType } from './Tabs.base';
import { DefaultTabBar } from './DefaultTabBar';
import { StaticContainer } from './StaticContainer';
import Styles from './Styles.native';

const TabPane = (Props: any) => {
const { shouldUpdate, ...props } = Props;
Expand All @@ -25,6 +26,7 @@ const TabPane = (Props: any) => {
export interface PropsType extends BasePropsType {
children?: any;
style?: RN.ViewStyle;
styles?: typeof Styles;
}
export interface StateType extends BaseStateType {
scrollX: Animated.Value;
Expand Down Expand Up @@ -77,7 +79,7 @@ export class Tabs extends Component<PropsType, StateType> {
const { tabs } = this.props;
const { currentTab, containerWidth } = this.state;

return <ScrollView
return <ScrollView key="$content"
horizontal
pagingEnabled
automaticallyAdjustContentInsets={false}
Expand Down Expand Up @@ -154,7 +156,7 @@ export class Tabs extends Component<PropsType, StateType> {
}

render() {
const { tabBarPosition } = this.props;
const { tabBarPosition, styles = Styles } = this.props;
const { scrollX, scrollValue, containerWidth } = this.state;
// let overlayTabs = (this.props.tabBarPosition === 'overlayTop' || this.props.tabBarPosition === 'overlayBottom');
let overlayTabs = false;
Expand All @@ -176,18 +178,17 @@ export class Tabs extends Component<PropsType, StateType> {
// };
}

const content = [
<View key="$tabbar" style={tabBarPosition === 'top' ? styles.Tabs.topTabBarSplitLine : styles.Tabs.bottomTabBarSplitLine}>
{this.renderTabBar(tabBarProps, DefaultTabBar)}
</View>,
this.renderContent()
];

return <View style={{
...Styles.container, ...this.props.style,
...styles.Tabs.container, ...this.props.style,
}} onLayout={this.handleLayout}>
{tabBarPosition === 'top' && this.renderTabBar(tabBarProps, DefaultTabBar)}
{this.renderContent()}
{(tabBarPosition === 'bottom' || overlayTabs) && this.renderTabBar(tabBarProps, DefaultTabBar)}
{tabBarPosition === 'top' ? content : content.reverse()}
</View>;
}
}

const Styles = {
container: {
flex: 1,
} as RN.ViewStyle,
};
}
4 changes: 4 additions & 0 deletions src/index.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { Models } from './Models';
export { PropsType as PropsType, TabBarPropsType } from './PropsType';
export { Tabs } from './Tabs';
export { DefaultTabBar } from './DefaultTabBar';

0 comments on commit 5422b34

Please sign in to comment.