Skip to content

Commit a45d78d

Browse files
committed
Merge pull request #18 from APSL/iss_17
solves #17
2 parents cc7441d + 4e3279b commit a45d78d

36 files changed

+1207
-220
lines changed

.eslintrc

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
{
2+
"parser": "babel-eslint",
3+
4+
"ecmaFeatures": {
5+
"jsx": true
6+
},
7+
8+
"env": {
9+
"es6": true,
10+
"jasmine": true,
11+
"node": 1,
12+
},
13+
14+
"plugins": [
15+
"react"
16+
],
17+
18+
"globals": {
19+
"__DEV__": true,
20+
"__dirname": false,
21+
"__fbBatchedBridgeConfig": false,
22+
"cancelAnimationFrame": false,
23+
"clearImmediate": true,
24+
"clearInterval": false,
25+
"clearTimeout": false,
26+
"console": false,
27+
"document": false,
28+
"escape": false,
29+
"exports": false,
30+
"fetch": false,
31+
"global": false,
32+
"jest": false,
33+
"Map": true,
34+
"module": false,
35+
"navigator": false,
36+
"process": false,
37+
"Promise": true,
38+
"requestAnimationFrame": true,
39+
"require": false,
40+
"Set": true,
41+
"setImmediate": true,
42+
"setInterval": false,
43+
"setTimeout": false,
44+
"window": false,
45+
"XMLHttpRequest": false,
46+
"pit": false,
47+
"FormData": true,
48+
},
49+
50+
"rules": {
51+
"comma-dangle": 0,
52+
"no-cond-assign": 1,
53+
"no-console": 0,
54+
"no-constant-condition": 0,
55+
"no-control-regex": 1,
56+
"no-debugger": 1,
57+
"no-dupe-keys": 1,
58+
"no-empty": 0,
59+
"no-empty-character-class": 1,
60+
"no-ex-assign": 1,
61+
"no-extra-boolean-cast": 1,
62+
"no-extra-parens": 0,
63+
"no-extra-semi": 1,
64+
"no-func-assign": 1,
65+
"no-inner-declarations": 0,
66+
"no-invalid-regexp": 1,
67+
"no-negated-in-lhs": 1,
68+
"no-obj-calls": 1,
69+
"no-regex-spaces": 1,
70+
"no-reserved-keys": 0,
71+
"no-sparse-arrays": 1,
72+
"no-unreachable": 1,
73+
"use-isnan": 1,
74+
"valid-jsdoc": 0,
75+
"valid-typeof": 1,
76+
77+
"block-scoped-var": 0,
78+
"complexity": 0,
79+
"consistent-return": 0,
80+
"curly": 1,
81+
"default-case": 0,
82+
"dot-notation": 1,
83+
"eqeqeq": 1,
84+
"guard-for-in": 0,
85+
"no-alert": 1,
86+
"no-caller": 1,
87+
"no-div-regex": 1,
88+
"no-else-return": 0,
89+
"no-empty-label": 1,
90+
"no-eq-null": 0,
91+
"no-eval": 1,
92+
"no-extend-native": 1,
93+
"no-extra-bind": 1,
94+
"no-fallthrough": 1,
95+
"no-floating-decimal": 1,
96+
"no-implied-eval": 1,
97+
"no-labels": 1,
98+
"no-iterator": 1,
99+
"no-lone-blocks": 1,
100+
"no-loop-func": 0,
101+
"no-multi-str": 0,
102+
"no-native-reassign": 0,
103+
"no-new": 1,
104+
"no-new-func": 1,
105+
"no-new-wrappers": 1,
106+
"no-octal": 1,
107+
"no-octal-escape": 1,
108+
"no-proto": 1,
109+
"no-redeclare": 0,
110+
"no-return-assign": 1,
111+
"no-script-url": 1,
112+
"no-self-compare": 1,
113+
"no-sequences": 1,
114+
"no-unused-expressions": 0,
115+
"no-void": 1,
116+
"no-warning-comments": 0,
117+
"no-with": 1,
118+
"radix": 1,
119+
"vars-on-top": 0,
120+
"wrap-iife": 0,
121+
"yoda": 1,
122+
123+
"strict": 0,
124+
125+
"no-catch-shadow": 1,
126+
"no-delete-var": 1,
127+
"no-label-var": 1,
128+
"no-shadow": 1,
129+
"no-shadow-restricted-names": 1,
130+
"no-undef": 2,
131+
"no-undefined": 0,
132+
"no-undef-init": 1,
133+
"no-unused-vars": [1, {"vars": "all", "args": "none"}],
134+
"no-use-before-define": 0,
135+
"handle-callback-err": 1,
136+
"no-mixed-requires": 1,
137+
"no-new-require": 1,
138+
"no-path-concat": 1,
139+
"no-process-exit": 0,
140+
"no-restricted-modules": 1,
141+
"no-sync": 0,
142+
143+
"key-spacing": 0,
144+
"comma-spacing": 0,
145+
"no-multi-spaces": 0,
146+
"brace-style": 0,
147+
"camelcase": 0,
148+
"consistent-this": [1, "self"],
149+
"eol-last": 1,
150+
"func-names": 0,
151+
"func-style": 0,
152+
"new-cap": 0,
153+
"new-parens": 1,
154+
"no-nested-ternary": 0,
155+
"no-array-constructor": 1,
156+
"no-lonely-if": 0,
157+
"no-new-object": 1,
158+
"no-spaced-func": 1,
159+
"semi-spacing": 1,
160+
"no-ternary": 0,
161+
"no-trailing-spaces": 1,
162+
"no-underscore-dangle": 0,
163+
"no-mixed-spaces-and-tabs": 1,
164+
"quotes": [1, "single", "avoid-escape"],
165+
"quote-props": 0,
166+
"semi": 0,
167+
"sort-vars": 0,
168+
"space-after-keywords": 1,
169+
"space-in-brackets": 0,
170+
"space-in-parens": 0,
171+
"space-infix-ops": 1,
172+
"space-return-throw-case": 1,
173+
"space-unary-ops": [1, { "words": true, "nonwords": false }],
174+
"max-nested-callbacks": 0,
175+
"one-var": 0,
176+
"wrap-regex": 0,
177+
178+
"max-depth": 0,
179+
"max-len": 0,
180+
"max-params": 0,
181+
"max-statements": 0,
182+
"no-bitwise": 1,
183+
"no-plusplus": 0,
184+
185+
"react/display-name": 0,
186+
"react/jsx-boolean-value": 0,
187+
"react/jsx-quotes": [1, "single", "avoid-escape"],
188+
"react/jsx-no-undef": 1,
189+
"react/jsx-sort-props": 0,
190+
"react/jsx-uses-react": 0,
191+
"react/jsx-uses-vars": 1,
192+
"react/no-did-mount-set-state": [1, "allow-in-func"],
193+
"react/no-did-update-set-state": [1, "allow-in-func"],
194+
"react/no-multi-comp": 0,
195+
"react/no-unknown-property": 0,
196+
"react/prop-types": 0,
197+
"react/react-in-jsx-scope": 0,
198+
"react/self-closing-comp": 1,
199+
"react/wrap-multilines": 0
200+
}
201+
}

Button.js

+71-50
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,38 @@ var {
1212
TouchableNativeFeedback,
1313
Platform
1414
} = React;
15-
var StyleSheetPropType = require('react-native/Libraries/StyleSheet/StyleSheetPropType');
16-
var TextStylePropTypes = require('react-native/Libraries/Text/TextStylePropTypes');
1715

1816
var Button = React.createClass({
1917
propTypes: Object.assign({},
20-
{textStyle: StyleSheetPropType(TextStylePropTypes),
21-
children: PropTypes.string.isRequired,
22-
isLoading: PropTypes.bool,
23-
isDisabled: PropTypes.bool,
24-
activityIndicatorColor: PropTypes.string,
25-
onPress: PropTypes.func,
26-
onLongPress: PropTypes.func,
27-
onPressIn: PropTypes.func,
28-
onPressOut: PropTypes.func},
18+
{
19+
textStyle: Text.propTypes.style,
20+
children: PropTypes.string.isRequired,
21+
isLoading: PropTypes.bool,
22+
isDisabled: PropTypes.bool,
23+
activityIndicatorColor: PropTypes.string,
24+
onPress: PropTypes.func,
25+
onLongPress: PropTypes.func,
26+
onPressIn: PropTypes.func,
27+
onPressOut: PropTypes.func,
28+
background: (TouchableNativeFeedback.propTypes) ? TouchableNativeFeedback.propTypes.background : PropTypes.any,
29+
},
2930
),
3031

31-
_renderInnerText: function () {
32+
statics: {
33+
isAndroid: (Platform.OS === 'android'),
34+
},
35+
36+
_renderInnerTextAndroid: function () {
3237
if (this.props.isLoading) {
33-
if (Platform.OS !== 'android') {
34-
return (
35-
<ActivityIndicatorIOS
36-
animating={true}
37-
size='small'
38-
style={styles.spinner}
39-
color={this.props.activityIndicatorColor || 'black'}
40-
/>
41-
);
42-
} else {
43-
return (
44-
<ProgressBarAndroid
45-
style={[{
46-
height: 20,
47-
}, styles.spinner]}
48-
styleAttr='Inverse'
49-
color={this.props.activityIndicatorColor || 'black'}
50-
/>
51-
);
52-
}
38+
return (
39+
<ProgressBarAndroid
40+
style={[{
41+
height: 20,
42+
}, styles.spinner]}
43+
styleAttr='Inverse'
44+
color={this.props.activityIndicatorColor || 'black'}
45+
/>
46+
);
5347
}
5448
return (
5549
<Text style={[styles.textButton, this.props.textStyle]}>
@@ -58,36 +52,63 @@ var Button = React.createClass({
5852
);
5953
},
6054

55+
_renderInnerTextiOS: function () {
56+
if (this.props.isLoading) {
57+
return (
58+
<ActivityIndicatorIOS
59+
animating={true}
60+
size='small'
61+
style={styles.spinner}
62+
color={this.props.activityIndicatorColor || 'black'}
63+
/>
64+
);
65+
}
66+
return (
67+
<Text style={[styles.textButton, this.props.textStyle]}>
68+
{this.props.children}
69+
</Text>
70+
);
71+
},
72+
73+
_renderInnerText: function () {
74+
if (Button.isAndroid) {
75+
return this._renderInnerTextAndroid()
76+
}
77+
return this._renderInnerTextiOS()
78+
},
79+
6180
render: function () {
62-
// Extract Touchable props
63-
var touchableProps = {
64-
onPress: this.props.onPress,
65-
onPressIn: this.props.onPressIn,
66-
onPressOut: this.props.onPressOut,
67-
onLongPress: this.props.onLongPress
68-
};
6981
if (this.props.isDisabled === true || this.props.isLoading === true) {
7082
return (
7183
<View style={[styles.button, this.props.style, styles.opacity]}>
7284
{this._renderInnerText()}
7385
</View>
7486
);
7587
} else {
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 {
88+
// Extract Touchable props
89+
var touchableProps = {
90+
onPress: this.props.onPress,
91+
onPressIn: this.props.onPressIn,
92+
onPressOut: this.props.onPressOut,
93+
onLongPress: this.props.onLongPress
94+
};
95+
if (Button.isAndroid) {
96+
touchableProps = Object.assign(touchableProps, {
97+
background: this.props.background || TouchableNativeFeedback.SelectableBackground()
98+
});
8499
return (
85-
<TouchableNativeFeedback {...touchableProps}
86-
background={TouchableNativeFeedback.Ripple()}>
100+
<TouchableNativeFeedback {...touchableProps}>
87101
<Text style={[styles.button, this.props.style]}>
88-
{this._renderInnerText()}
102+
{this._renderInnerTextAndroid()}
89103
</Text>
90104
</TouchableNativeFeedback>
105+
)
106+
} else {
107+
return (
108+
<TouchableOpacity {...touchableProps}
109+
style={[styles.button, this.props.style]}>
110+
{this._renderInnerTextiOS()}
111+
</TouchableOpacity>
91112
);
92113
}
93114
}

0 commit comments

Comments
 (0)