mirror of
https://github.com/zhigang1992/react-native-segmented-control-tab.git
synced 2026-04-28 12:25:14 +08:00
Added new allowFontScaling prop to pass to the Text components.
This commit is contained in:
@@ -4,12 +4,11 @@ import {
|
||||
Text,
|
||||
View
|
||||
} from 'react-native';
|
||||
|
||||
import SegmentedControlTab from 'react-native-segmented-control-tab'
|
||||
import SegmentedControlTab from 'react-native-segmented-control-tab';
|
||||
|
||||
class ExampleMain extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
super(props);
|
||||
this.state = {
|
||||
selectedIndex: 0,
|
||||
selectedIndices: [0],
|
||||
|
||||
@@ -77,6 +77,7 @@ activeTabBadgeContainerStyle | external style can be passed to override the defa
|
||||
tabBadgeStyle | external style can be passed to override the default style of the badge text | base styles added in SegmentedControlTab.js | object(styles)
|
||||
activeTabBadgeStyle | external style can be passed to override the default style of the active badge text | base styles added in SegmentedControlTab.js | object(styles)
|
||||
onTabPress | call-back function when a tab is selected | () => {} | func
|
||||
allowFontScaling | whether the segment & badge text should allow font scaling (default matches React Native default) | true | bool
|
||||
|
||||
## Custom styling
|
||||
```javascript
|
||||
@@ -86,6 +87,7 @@ onTabPress | call-back function when a tab is selected | () => {} | func
|
||||
activeTabStyle={styles.activeTabStyle}
|
||||
activeTabTextStyle={styles.activeTabTextStyle}
|
||||
selectedIndex={1}
|
||||
allowFontScaling={false}
|
||||
values={['First', 'Second', 'Third']}
|
||||
onPress= {index => this.setState({selected:index})}
|
||||
/>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import React, { Component } from 'react'
|
||||
import React, { Component } from 'react';
|
||||
import {
|
||||
View,
|
||||
ViewPropTypes,
|
||||
TouchableOpacity,
|
||||
StyleSheet,
|
||||
Text
|
||||
} from 'react-native'
|
||||
} from 'react-native';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const handleTabPress = (index, multiple, selectedIndex, onTabPress) => {
|
||||
@@ -24,7 +24,8 @@ const TabOption = ({
|
||||
tabTextStyle, activeTabTextStyle,
|
||||
tabBadgeContainerStyle, activeTabBadgeContainerStyle,
|
||||
tabBadgeStyle, activeTabBadgeStyle,
|
||||
onTabPress, textNumberOfLines
|
||||
onTabPress, textNumberOfLines,
|
||||
allowFontScaling,
|
||||
}) => {
|
||||
return (
|
||||
<TouchableOpacity style={[
|
||||
@@ -41,6 +42,7 @@ const TabOption = ({
|
||||
tabTextStyle,
|
||||
isTabActive ? [styles.activeTabTextStyle, activeTabTextStyle] : {}]}
|
||||
numberOfLines={textNumberOfLines}
|
||||
allowFontScaling={allowFontScaling}
|
||||
ellipsizeMode="tail">
|
||||
{text}
|
||||
</Text>
|
||||
@@ -53,7 +55,8 @@ const TabOption = ({
|
||||
<Text style={[
|
||||
styles.tabBadgeStyle,
|
||||
tabBadgeStyle,
|
||||
isTabActive ? [styles.activeTabBadgeStyle, activeTabBadgeStyle] : {}]}>
|
||||
isTabActive ? [styles.activeTabBadgeStyle, activeTabBadgeStyle] : {}]}
|
||||
allowFontScaling={allowFontScaling}>
|
||||
{badge}
|
||||
</Text>
|
||||
</View> : false
|
||||
@@ -70,7 +73,8 @@ const SegmentedControlTab = ({
|
||||
tabTextStyle, activeTabTextStyle,
|
||||
tabBadgeContainerStyle, activeTabBadgeContainerStyle,
|
||||
tabBadgeStyle, activeTabBadgeStyle,
|
||||
onTabPress, textNumberOfLines
|
||||
onTabPress, textNumberOfLines,
|
||||
allowFontScaling,
|
||||
}) => {
|
||||
|
||||
const firstTabStyle = [{ borderRightWidth: values.length == 2 ? 1 : 0, borderTopLeftRadius: borderRadius, borderBottomLeftRadius: borderRadius }]
|
||||
@@ -100,7 +104,9 @@ const SegmentedControlTab = ({
|
||||
tabBadgeContainerStyle={tabBadgeContainerStyle}
|
||||
activeTabBadgeContainerStyle={activeTabBadgeContainerStyle}
|
||||
tabBadgeStyle={tabBadgeStyle}
|
||||
activeTabBadgeStyle={activeTabBadgeStyle} />
|
||||
activeTabBadgeStyle={activeTabBadgeStyle}
|
||||
allowFontScaling={allowFontScaling}
|
||||
/>
|
||||
);
|
||||
})
|
||||
}
|
||||
@@ -125,8 +131,9 @@ SegmentedControlTab.propTypes = {
|
||||
tabBadgeStyle: Text.propTypes.style,
|
||||
activeTabBadgeStyle: Text.propTypes.style,
|
||||
borderRadius: PropTypes.number,
|
||||
textNumberOfLines: PropTypes.number
|
||||
}
|
||||
textNumberOfLines: PropTypes.number,
|
||||
allowFontScaling: PropTypes.bool,
|
||||
};
|
||||
|
||||
SegmentedControlTab.defaultProps = {
|
||||
values: ['One', 'Two', 'Three'],
|
||||
@@ -145,8 +152,9 @@ SegmentedControlTab.defaultProps = {
|
||||
tabBadgeStyle: {},
|
||||
activeTabBadgeStyle: {},
|
||||
borderRadius: 5,
|
||||
textNumberOfLines: 1
|
||||
}
|
||||
textNumberOfLines: 1,
|
||||
allowFontScaling: true,
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
tabsContainerStyle: {
|
||||
@@ -190,6 +198,6 @@ const styles = StyleSheet.create({
|
||||
activeTabBadgeStyle: {
|
||||
color: 'black'
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
export default SegmentedControlTab
|
||||
|
||||
Reference in New Issue
Block a user