Skip to content

Commit

Permalink
switch to prop-types to support RN >= 0.44 (#66)
Browse files Browse the repository at this point in the history
* switch to prop-types to support RN >= 0.44

* remove Unnecessary semicolon

* fix failing tests and devDependencies
  • Loading branch information
antt001 authored and alvaromb committed Jul 26, 2017
1 parent aea8c48 commit 80ef3e7
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 76 deletions.
29 changes: 14 additions & 15 deletions Button.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import React, { PropTypes } from 'react';
import React, { Component } from 'react';
import {
View,
TouchableOpacity,
Expand All @@ -10,10 +10,11 @@ import {
TouchableNativeFeedback,
Platform
} from 'react-native';
import PropTypes from 'prop-types';
import isEqual from 'lodash.isequal';

const Button = React.createClass({
propTypes: {
class Button extends Component {
static propTypes = {
textStyle: Text.propTypes.style,
disabledStyle: Text.propTypes.style,
children: PropTypes.oneOfType([
Expand All @@ -35,13 +36,11 @@ const Button = React.createClass({
onPressIn: PropTypes.func,
onPressOut: PropTypes.func,
background: (TouchableNativeFeedback.propTypes) ? TouchableNativeFeedback.propTypes.background : PropTypes.any,
},
}

statics: {
isAndroid: (Platform.OS === 'android'),
},
static isAndroid = (Platform.OS === 'android')

_renderChildren: function() {
_renderChildren() {
let childElements = [];
React.Children.forEach(this.props.children, (item) => {
if (typeof item === 'string' || typeof item === 'number') {
Expand All @@ -59,16 +58,16 @@ const Button = React.createClass({
}
});
return (childElements);
},
}

shouldComponentUpdate: function (nextProps, nextState) {
shouldComponentUpdate(nextProps, nextState) {
if (!isEqual(nextProps, this.props)) {
return true;
}
return false;
},
}

_renderInnerText: function () {
_renderInnerText() {
if (this.props.isLoading) {
return (
<ActivityIndicator
Expand All @@ -80,9 +79,9 @@ const Button = React.createClass({
);
}
return this._renderChildren();
},
}

render: function () {
render() {
if (this.props.isDisabled === true || this.props.isLoading === true) {
return (
<View style={[styles.button, this.props.style, (this.props.disabledStyle || styles.opacity)]}>
Expand Down Expand Up @@ -122,7 +121,7 @@ const Button = React.createClass({
);
}
}
});
}

const styles = StyleSheet.create({
button: {
Expand Down
129 changes: 75 additions & 54 deletions __tests__/__snapshots__/Button.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Button Renders 1`] = `
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
isTVSelectable={true}
onLayout={undefined}
onResponderGrant={[Function bound touchableHandleResponderGrant]}
onResponderMove={[Function bound touchableHandleResponderMove]}
onResponderRelease={[Function bound touchableHandleResponderRelease]}
onResponderTerminate={[Function bound touchableHandleResponderTerminate]}
onResponderTerminationRequest={[Function bound touchableHandleResponderTerminationRequest]}
onStartShouldSetResponder={[Function bound touchableHandleStartShouldSetResponder]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
Expand All @@ -22,10 +25,12 @@ exports[`Button Renders 1`] = `
"height": 44,
"justifyContent": "center",
"marginBottom": 10,
"opacity": 1
"opacity": 1,
}
}
testID={undefined}>
testID={undefined}
tvParallaxProperties={undefined}
>
<Text
accessible={true}
allowFontScaling={true}
Expand All @@ -36,11 +41,12 @@ exports[`Button Renders 1`] = `
"backgroundColor": "transparent",
"flex": 1,
"fontSize": 18,
"textAlign": "center"
"textAlign": "center",
},
undefined
undefined,
]
}>
}
>
Button
</Text>
</View>
Expand All @@ -58,14 +64,15 @@ exports[`Button Renders disabled 1`] = `
"flexDirection": "row",
"height": 44,
"justifyContent": "center",
"marginBottom": 10
"marginBottom": 10,
},
undefined,
Object {
"opacity": 0.5
}
"opacity": 0.5,
},
]
}>
}
>
<Text
accessible={true}
allowFontScaling={true}
Expand All @@ -76,11 +83,12 @@ exports[`Button Renders disabled 1`] = `
"backgroundColor": "transparent",
"flex": 1,
"fontSize": 18,
"textAlign": "center"
"textAlign": "center",
},
undefined
undefined,
]
}>
}
>
Disabled button
</Text>
</View>
Expand All @@ -98,24 +106,26 @@ exports[`Button Renders loading 1`] = `
"flexDirection": "row",
"height": 44,
"justifyContent": "center",
"marginBottom": 10
"marginBottom": 10,
},
undefined,
Object {
"opacity": 0.5
}
"opacity": 0.5,
},
]
}>
}
>
<ActivityIndicator
animating={true}
color="black"
hidesWhenStopped={true}
size="small"
style={
Object {
"alignSelf": "center"
"alignSelf": "center",
}
} />
}
/>
</View>
`;

Expand All @@ -126,13 +136,14 @@ exports[`Button Renders with a inner View 1`] = `
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
isTVSelectable={true}
onLayout={undefined}
onResponderGrant={[Function bound touchableHandleResponderGrant]}
onResponderMove={[Function bound touchableHandleResponderMove]}
onResponderRelease={[Function bound touchableHandleResponderRelease]}
onResponderTerminate={[Function bound touchableHandleResponderTerminate]}
onResponderTerminationRequest={[Function bound touchableHandleResponderTerminationRequest]}
onStartShouldSetResponder={[Function bound touchableHandleStartShouldSetResponder]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
Expand All @@ -143,10 +154,12 @@ exports[`Button Renders with a inner View 1`] = `
"height": 44,
"justifyContent": "center",
"marginBottom": 10,
"opacity": 1
"opacity": 1,
}
}
testID={undefined}>
testID={undefined}
tvParallaxProperties={undefined}
>
<View />
</View>
`;
Expand All @@ -158,13 +171,14 @@ exports[`Button Should contain children 1`] = `
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
isTVSelectable={true}
onLayout={undefined}
onResponderGrant={[Function bound touchableHandleResponderGrant]}
onResponderMove={[Function bound touchableHandleResponderMove]}
onResponderRelease={[Function bound touchableHandleResponderRelease]}
onResponderTerminate={[Function bound touchableHandleResponderTerminate]}
onResponderTerminationRequest={[Function bound touchableHandleResponderTerminationRequest]}
onStartShouldSetResponder={[Function bound touchableHandleStartShouldSetResponder]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
Expand All @@ -175,10 +189,12 @@ exports[`Button Should contain children 1`] = `
"height": 44,
"justifyContent": "center",
"marginBottom": 10,
"opacity": 1
"opacity": 1,
}
}
testID={undefined}>
testID={undefined}
tvParallaxProperties={undefined}
>
<Text
accessible={true}
allowFontScaling={true}
Expand All @@ -189,11 +205,12 @@ exports[`Button Should contain children 1`] = `
"backgroundColor": "transparent",
"flex": 1,
"fontSize": 18,
"textAlign": "center"
"textAlign": "center",
},
undefined
undefined,
]
}>
}
>
Press me!
</Text>
</View>
Expand All @@ -206,13 +223,14 @@ exports[`Button Should react to the onPress event 1`] = `
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
isTVSelectable={true}
onLayout={undefined}
onResponderGrant={[Function bound touchableHandleResponderGrant]}
onResponderMove={[Function bound touchableHandleResponderMove]}
onResponderRelease={[Function bound touchableHandleResponderRelease]}
onResponderTerminate={[Function bound touchableHandleResponderTerminate]}
onResponderTerminationRequest={[Function bound touchableHandleResponderTerminationRequest]}
onStartShouldSetResponder={[Function bound touchableHandleStartShouldSetResponder]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
Expand All @@ -223,10 +241,12 @@ exports[`Button Should react to the onPress event 1`] = `
"height": 44,
"justifyContent": "center",
"marginBottom": 10,
"opacity": 1
"opacity": 1,
}
}
testID={undefined}>
testID={undefined}
tvParallaxProperties={undefined}
>
<Text
accessible={true}
allowFontScaling={true}
Expand All @@ -237,11 +257,12 @@ exports[`Button Should react to the onPress event 1`] = `
"backgroundColor": "transparent",
"flex": 1,
"fontSize": 18,
"textAlign": "center"
"textAlign": "center",
},
undefined
undefined,
]
}>
}
>
Press me!
</Text>
</View>
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"Example",
"node_modules/react-native/node_modules/"
],
"preprocessorIgnorePatterns": [
"transformIgnorePatterns": [
"node_modules/(?!react-native|tcomb-form-native|react-native-localization|@exponent/react-native-action-sheet|rnrf-relay-renderer|redux-action-api-utils|frisbee)"
]
},
Expand All @@ -36,7 +36,8 @@
},
"homepage": "https://github.com/APSL/react-native-button#readme",
"dependencies": {
"lodash.isequal": "^4.1.4"
"lodash.isequal": "^4.1.4",
"prop-types": "^15.5.10"
},
"devDependencies": {
"babel-eslint": "^6.0.5",
Expand All @@ -47,11 +48,11 @@
"eslint": "^2.13.1",
"eslint-plugin-react": "^5.2.2",
"eslint-plugin-react-native": "^1.1.0-beta",
"jest": "^15.1.1",
"jest-react-native": "^15.0.0",
"react": "^15.3.2",
"react-native": "^0.34.0",
"react-test-renderer": "^15.3.2",
"jest": "^20.0.0",
"jest-react-native": "^18.0.0",
"react": "^15.4.0",
"react-native": "^0.42.0",
"react-test-renderer": "^15.4.0",
"whatwg-fetch": "^1.0.0"
}
}

0 comments on commit 80ef3e7

Please sign in to comment.