Skip to content

Instantly share code, notes, and snippets.

@blaues0cke
Created April 5, 2017 13:25
Show Gist options
  • Save blaues0cke/be0d1f71ed342ebb1863eadb6a0e7d0e to your computer and use it in GitHub Desktop.
Save blaues0cke/be0d1f71ed342ebb1863eadb6a0e7d0e to your computer and use it in GitHub Desktop.
react-native-tabs <Text> as own component
/**
* Created by thomaskekeisen on 16/03/2017.
*/
// @formatter:off
import I18n from 'react-native-i18n';
import React from 'react';
import Styles from '../styles/Styles';
import { Text } from 'react-native';
// @formatter:on
class TabTitleText extends React.Component {
getStyleWithPosition(style) {
if (this.props.position) {
if (this.props.position == 'left') {
style.push(Styles.stylesheet.tabBarInPageTabLeft);
}
if (this.props.position == 'right') {
style.push(Styles.stylesheet.tabBarInPageTabRight);
}
}
return style;
};
getSelectedTextStyle() {
let style = [Styles.stylesheet.tabBarInPageTabSelected];
return this.getStyleWithPosition(style);
};
getStyle() {
if (this.props.selected) {
return this.getSelectedTextStyle();
}
return this.getTextStyle();
}
getTextStyle() {
let style = [Styles.stylesheet.tabBarInPageTab];
return this.getStyleWithPosition(style);
};
render() {
return (
<Text
name={this.props.name}
style={ this.getStyle() }
>
{ I18n.t(this.props.i18n || this.props.name) }
</Text>
);
}
}
module.exports = TabTitleText;
import TabTitleText from '../components/TabTitleText';
// ...
<Tabs selected={ this.props.tabBar.tabIndex }
onSelect={ (tab) => {
this.tabShouldChange(tab.props.name);
}}
style={ Styles.stylesheet.tabBarInPage }
>
<TabTitleText name="map" position="left"/>
<TabTitleText name="list" position="right"/>
</Tabs>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment