Skip to content

Commit d831ef0

Browse files
Nick NesterovNick Nesterov
authored andcommitted
added: disabled props of the onTab function
1 parent dcf1afe commit d831ef0

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Property | Type | Description
2121
`tabs` | required array | The array consists of objects which must have an id inside an object.
2222
`activeTab` | required object | The object must have an id.
2323
`onTab` | required function | The function returns new active tab.
24+
`disabled` | bool | Disable `onTab` function.
2425
`styles` | object | An object of react native styles. More details below.
2526

2627

@@ -35,7 +36,7 @@ Property | Type | Description
3536
`activeTabText` | Text.propTypes.style | Styles for a text of active tab.
3637
`underline` | View.propTypes.style | Styles for a moving underline.
3738

38-
## Usage:
39+
## Usage:
3940

4041
```jsx
4142
import NativeTabs from 'native-tabs';
@@ -70,7 +71,7 @@ class SomeComponent extends React.Component{
7071
});
7172
}
7273
render() {
73-
return <NativeTabs tabs={items}
74+
return <NativeTabs tabs={items}
7475
styles={{
7576
tabs: styles.tabs,
7677
tab: styles.tab,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "native-tabs",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "React Native Tabs",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from "react";
22
import PropTypes from "prop-types";
3-
import { Animated, StyleSheet, Text, TouchableOpacity, View } from "react-native";
3+
import { Animated, StyleSheet, Text, TouchableOpacity, View, ViewPropTypes } from "react-native";
44

55
export default class NativeTabs extends Component {
66
constructor(props) {
@@ -30,7 +30,7 @@ export default class NativeTabs extends Component {
3030
this.activeTab = c;
3131
}
3232
onTab(tab) {
33-
this.props.onTab(tab);
33+
if (!this.props.disabled) this.props.onTab(tab);
3434
}
3535
getUnderlineStyle() {
3636
const t = this.state.underlineOffsetAm.getTranslateTransform();
@@ -107,16 +107,21 @@ NativeTabs.propTypes = {
107107
id: PropTypes.any
108108
}).isRequired,
109109
onTab: PropTypes.func,
110+
disabled: PropTypes.bool,
110111
styles: PropTypes.shape({
111-
tabs: View.propTypes.style,
112+
tabs: ViewPropTypes.style,
112113
tab: TouchableOpacity.propTypes.style,
113114
tabText: Text.propTypes.style,
114115
activeTab: TouchableOpacity.propTypes.style,
115116
activeTabText: Text.propTypes.style,
116-
underline: View.propTypes.style
117+
underline: ViewPropTypes.style
117118
})
118119
}
119120

121+
NativeTabs.defaultProps = {
122+
disabled: false
123+
}
124+
120125
const styles = StyleSheet.create({
121126
tabs: {
122127
position: "relative",

0 commit comments

Comments
 (0)