Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit 0216880

Browse files
committed
added disabled prop to NavButton
1 parent 10e5382 commit 0216880

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,24 @@ import { NavButton } from 'react-native-nav'
242242

243243
###### Props
244244

245+
*disabled*
246+
247+
Setting this to true will disable the button and use the `disabledStyle` to style the button.
248+
249+
```javascript
250+
<NavButton disabled>
251+
// Pass any React element(s) here
252+
</NavButton>
253+
```
254+
245255
*style*
246256

247-
The best option is to use the `Stylesheet` object in `React Native` to create your styles
257+
The best option is to use the `Stylesheet` object in `React Native` to create your styles.
248258

249259
```javascript
250260
style = StyleSheet.create({
251261
title: {
252-
// NavButton styles here (all text styles are valid)
262+
// NavButton styles here (all view styles are valid)
253263

254264
// default iOS styles:
255265
marginLeft: 0,
@@ -260,6 +270,20 @@ style = StyleSheet.create({
260270
})
261271
```
262272

273+
*disabledStyle*
274+
275+
The best option is to use the `Stylesheet` object in `React Native` to create your styles.
276+
277+
```javascript
278+
style = StyleSheet.create({
279+
title: {
280+
// disabled NavButton styles here (all view styles are valid)
281+
282+
// no default styles
283+
},
284+
})
285+
```
286+
263287
*onPress*
264288

265289
`onPress` takes a function that will be executed when the button is pressed. Example:

components/NavButton.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,37 @@ import React from 'react-native'
33
const { Platform, TouchableOpacity, View, PropTypes } = React
44
import styles from '../styles'
55

6-
function NavButton({ style, onPress, children }: Object): React.Element {
7-
let navBarStyles = []
6+
function NavButton({ style, onPress, children, disabled, disabledStyle }: Object): React.Element {
7+
let navButtonStyles = []
88
if (Platform.OS === 'ios') {
9-
navBarStyles = [styles.navBarButtonIOS, style]
9+
navButtonStyles = [styles.navBarButtonIOS]
1010
} else if (Platform.OS === 'android') {
11-
navBarStyles = [styles.navBarButtonAndroid, style]
11+
navButtonStyles = [styles.navBarButtonAndroid]
12+
}
13+
if (disabled) {
14+
navButtonStyles.push(disabledStyle)
15+
} else {
16+
navButtonStyles.push(style)
1217
}
1318

14-
const getTouchable = () => (
15-
<TouchableOpacity onPress={onPress}>
16-
<View style={navBarStyles}>
17-
{children}
18-
</View>
19-
</TouchableOpacity>
20-
)
19+
const getTouchable = (): React.Element => {
20+
if (disabled) {
21+
return (
22+
<TouchableOpacity>
23+
<View style={navButtonStyles}>
24+
{children}
25+
</View>
26+
</TouchableOpacity>
27+
)
28+
}
29+
return (
30+
<TouchableOpacity onPress={onPress}>
31+
<View style={navButtonStyles}>
32+
{children}
33+
</View>
34+
</TouchableOpacity>
35+
)
36+
}
2137

2238
return getTouchable()
2339
}
@@ -26,10 +42,14 @@ NavButton.propTypes = {
2642
children: PropTypes.node,
2743
onPress: PropTypes.func,
2844
style: View.propTypes.style,
45+
disabled: PropTypes.bool,
46+
disabledStyle: View.PropTypes.style,
2947
}
3048

3149
NavButton.defaultProps = {
3250
style: {},
51+
disabledStyle: {},
52+
disabled: false,
3353
}
3454

3555
export { NavButton }

0 commit comments

Comments
 (0)