Skip to content

Commit 67e82f1

Browse files
committed
Merge pull request #16 from APSL/iss_13
fixes #13 Added support for TouchableNativeFeedback
2 parents fdd7fc7 + a6b6ea5 commit 67e82f1

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

Button.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@ var {
99
PropTypes,
1010
ActivityIndicatorIOS,
1111
ProgressBarAndroid,
12+
TouchableNativeFeedback,
1213
Platform
1314
} = React;
1415
var StyleSheetPropType = require('react-native/Libraries/StyleSheet/StyleSheetPropType');
1516
var TextStylePropTypes = require('react-native/Libraries/Text/TextStylePropTypes');
1617

1718
var Button = React.createClass({
1819
propTypes: Object.assign({},
19-
TouchableOpacity.propTypes,
2020
{textStyle: StyleSheetPropType(TextStylePropTypes),
2121
children: PropTypes.string.isRequired,
2222
isLoading: PropTypes.bool,
2323
isDisabled: PropTypes.bool,
24-
activityIndicatorColor: PropTypes.string},
24+
activityIndicatorColor: PropTypes.string,
25+
onPress: PropTypes.func,
26+
onLongPress: PropTypes.func,
27+
onPressIn: PropTypes.func,
28+
onPressOut: PropTypes.func},
2529
),
2630

2731
_renderInnerText: function () {
@@ -42,6 +46,7 @@ var Button = React.createClass({
4246
height: 20,
4347
}, styles.spinner]}
4448
styleAttr='Inverse'
49+
color={this.props.activityIndicatorColor || 'black'}
4550
/>
4651
);
4752
}
@@ -54,27 +59,37 @@ var Button = React.createClass({
5459
},
5560

5661
render: function () {
57-
// Extract TouchableOpacity props
62+
// Extract Touchable props
5863
var touchableProps = {
5964
onPress: this.props.onPress,
6065
onPressIn: this.props.onPressIn,
6166
onPressOut: this.props.onPressOut,
6267
onLongPress: this.props.onLongPress
6368
};
64-
6569
if (this.props.isDisabled === true || this.props.isLoading === true) {
6670
return (
6771
<View style={[styles.button, this.props.style, styles.opacity]}>
6872
{this._renderInnerText()}
6973
</View>
7074
);
7175
} else {
72-
return (
73-
<TouchableOpacity {...touchableProps}
74-
style={[styles.button, this.props.style]}>
75-
{this._renderInnerText()}
76-
</TouchableOpacity>
77-
);
76+
if (Platform.OS !== 'android') {
77+
return (
78+
<TouchableOpacity {...touchableProps}
79+
style={[styles.button, this.props.style]}>
80+
{this._renderInnerText()}
81+
</TouchableOpacity>
82+
);
83+
} else {
84+
return (
85+
<TouchableNativeFeedback {...touchableProps}
86+
background={TouchableNativeFeedback.Ripple()}>
87+
<Text style={[styles.button, this.props.style]}>
88+
{this._renderInnerText()}
89+
</Text>
90+
</TouchableNativeFeedback>
91+
);
92+
}
7893
}
7994
}
8095
});

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ A React Native button component customizable via ``style`` props.
66
<img src="https://raw.githubusercontent.com/wiki/APSL/react-native-button/button.png" alt="Button component screenshot" width="400">
77
</p>
88

9+
Renders a ``TouchableOpacity`` under iOS and a ``TouchableNativeFeedback`` under Android.
10+
911
## Install
1012

1113
Install the package:
@@ -22,7 +24,7 @@ import Button from 'apsl-react-native-button'
2224

2325
## Usage
2426

25-
Provide ``TouchableOpacity``' props to the component (including ``style``),
27+
Provide ``TouchableWithoutFeedback``' props to the component (including ``style``),
2628
``textStyle``'s ``StyleSheet`` to customize the inner text and a children node
2729
to render. You can also provide the ``isLoading`` prop that will dim the button
2830
and disable it to prevent accidental taps.
@@ -45,7 +47,7 @@ and disable it to prevent accidental taps.
4547
| ``children`` | ``string`` | The ``string`` to render as the text button. |
4648
| ``isLoading`` | ``bool`` | Renders an inactive state dimmed button with a spinner if ``true``. |
4749
| ``isDisabled`` | ``bool`` | Renders an inactive state dimmed button if ``true``. |
48-
| ``activityIndicatorColor`` | ``string`` | **iOS only**. Sets the button of the ``ActivityIndicatorIOS`` in the loading state. |
50+
| ``activityIndicatorColor`` | ``string`` | Sets the button of the ``ActivityIndicatorIOS`` or ``ProgressBarAndroid`` in the loading state. |
4951

5052
Check the included example for more options.
5153

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apsl-react-native-button",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"description": "React Native button component with rounded corners.",
55
"main": "Button.js",
66
"scripts": {
@@ -24,7 +24,4 @@
2424
"url": "https://github.com/APSL/react-native-button/issues"
2525
},
2626
"homepage": "https://github.com/APSL/react-native-button#readme",
27-
"peerDependencies": {
28-
"react-native": ">=0.11.0"
29-
}
3027
}

0 commit comments

Comments
 (0)