Skip to content

Commit

Permalink
Added eslint config and fixes warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanregisser committed Aug 7, 2015
1 parent 0967611 commit c1e8795
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 25 deletions.
70 changes: 70 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"parser": "babel-eslint",
"env": {
"es6": true
},
"ecmaFeatures": {
"jsx": true
},
"plugins": [
"react"
],
"globals": {
"__DEV__": true,
"__dirname": false,
"__fbBatchedBridgeConfig": false,
"cancelAnimationFrame": false,
"clearImmediate": true,
"clearInterval": false,
"clearTimeout": false,
"console": false,
"document": false,
"escape": false,
"exports": false,
"fetch": false,
"global": false,
"jest": false,
"Map": true,
"module": false,
"navigator": false,
"process": false,
"Promise": true,
"requestAnimationFrame": true,
"require": false,
"Set": true,
"setImmediate": true,
"setInterval": false,
"setTimeout": false,
"window": false,
"XMLHttpRequest": false,
"pit": false
},
"rules": {
"indent": [
2,
2
],
"quotes": [
2,
"single",
"avoid-escape"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
],
"strict": [
2,
"global"
],
"global-strict": 0,
"no-use-before-define": 0,
"comma-dangle": 0,
"no-underscore-dangle": 0,
"eol-last": 1
}
}
9 changes: 4 additions & 5 deletions Example/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var {
AppRegistry,
StyleSheet,
Text,
TouchableHighlight,
ScrollView,
View,
SliderIOS,
Expand All @@ -32,7 +31,7 @@ var SliderContainer = React.createClass({
</View>
{this._renderChildren()}
</View>
)
);
},

_renderChildren() {
Expand All @@ -42,12 +41,12 @@ var SliderContainer = React.createClass({
var value = this.state.value;
return React.addons.cloneWithProps(child, {
value: value,
onValueChange: (value) => this.setState({value: value}),
})
onValueChange: (val) => this.setState({value: val}),
});
} else {
return child;
}
}.bind(this))
}.bind(this));
},
});

Expand Down
38 changes: 18 additions & 20 deletions Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ var {
PropTypes,
StyleSheet,
PanResponder,
Text,
TouchableWithoutFeedback,
View
} = React;

Expand All @@ -25,7 +23,7 @@ Rect.prototype.containsPoint = function(x, y) {
&& y >= this.y
&& x <= this.x + this.width
&& y <= this.y + this.height);
}
};

var Slider = React.createClass({
propTypes: {
Expand Down Expand Up @@ -173,10 +171,10 @@ var Slider = React.createClass({
var minimumTrackStyle = {
position: 'absolute',
width: 300, // needed to workaround a bug for borderRadius
marginTop: - trackSize.height,
marginTop: -trackSize.height,
backgroundColor: minimumTrackTintColor,
...valueVisibleStyle
}
};

if (thumbLeft >= 0 && thumbSize.width >= 0) {
minimumTrackStyle.width = thumbLeft + thumbSize.width / 2;
Expand All @@ -194,7 +192,7 @@ var Slider = React.createClass({
ref={(thumb) => this.thumb = thumb}
onLayout={this._measureThumb}
style={[
{backgroundColor: thumbTintColor, marginTop: - (trackSize.height + thumbSize.height) / 2},
{backgroundColor: thumbTintColor, marginTop: -(trackSize.height + thumbSize.height) / 2},
mainStyles.thumb, thumbStyle, {left: thumbLeft, ...valueVisibleStyle}
]}
/>
Expand All @@ -207,17 +205,17 @@ var Slider = React.createClass({
);
},

_handleStartShouldSetPanResponder: function(e: Object, gestureState: Object): boolean {
_handleStartShouldSetPanResponder: function(e: Object, /*gestureState: Object*/): boolean {
// Should we become active when the user presses down on the thumb?
return this._thumbHitTest(e);
},

_handleMoveShouldSetPanResponder: function(e: Object, gestureState: Object): boolean {
_handleMoveShouldSetPanResponder: function(/*e: Object, gestureState: Object*/): boolean {
// Should we become active when the user moves a touch over the thumb?
return false;
},

_handlePanResponderGrant: function(e: Object, gestureState: Object) {
_handlePanResponderGrant: function(/*e: Object, gestureState: Object*/) {
this.setState({ previousLeft: this._getThumbLeft(this.state.value) },
this._fireChangeEvent.bind(this, 'onSlidingStart'));
},
Expand Down Expand Up @@ -258,12 +256,12 @@ var Slider = React.createClass({
},

_getValue(gestureState: Object) {
var length = this.state.containerSize.width - this.state.thumbSize.width
var length = this.state.containerSize.width - this.state.thumbSize.width;
var thumbLeft = Math.min(length,
Math.max(0, this.state.previousLeft + gestureState.dx));

var ratio = thumbLeft / length;
return ratio * (this.props.maximumValue - this.props.minimumValue) + this.props.minimumValue;
return ratio * (this.props.maximumValue - this.props.minimumValue) + this.props.minimumValue;
},

_fireChangeEvent(event) {
Expand Down Expand Up @@ -292,11 +290,11 @@ var Slider = React.createClass({

var touchOverflowStyle = {};
if (width !== undefined && height !== undefined) {
var verticalMargin = - height / 2;
var verticalMargin = -height / 2;
touchOverflowStyle.marginTop = verticalMargin;
touchOverflowStyle.marginBottom = verticalMargin;

var horizontalMargin = - width / 2;
var horizontalMargin = -width / 2;
touchOverflowStyle.marginLeft = horizontalMargin;
touchOverflowStyle.marginRight = horizontalMargin;
}
Expand All @@ -309,7 +307,7 @@ var Slider = React.createClass({
return touchOverflowStyle;
},

_thumbHitTest(e: object) {
_thumbHitTest(e: Object) {
var nativeEvent = e.nativeEvent;
var thumbTouchRect = this._getThumbTouchRect();
return thumbTouchRect.containsPoint(nativeEvent.locationX, nativeEvent.locationY);
Expand All @@ -321,11 +319,11 @@ var Slider = React.createClass({
var touchOverflowSize = this._getTouchOverflowSize();

return new Rect(
touchOverflowSize.width / 2 + this._getThumbLeft(state.value) + (state.thumbSize.width - props.thumbTouchSize.width) / 2,
touchOverflowSize.height / 2 + (state.containerSize.height - props.thumbTouchSize.height) / 2,
props.thumbTouchSize.width,
props.thumbTouchSize.height
)
touchOverflowSize.width / 2 + this._getThumbLeft(state.value) + (state.thumbSize.width - props.thumbTouchSize.width) / 2,
touchOverflowSize.height / 2 + (state.containerSize.height - props.thumbTouchSize.height) / 2,
props.thumbTouchSize.width,
props.thumbTouchSize.height
);
},

_renderDebugThumbTouchRect() {
Expand All @@ -335,7 +333,7 @@ var Slider = React.createClass({
top: thumbTouchRect.y,
width: thumbTouchRect.width,
height: thumbTouchRect.height,
}
};

return (
<View
Expand Down

0 comments on commit c1e8795

Please sign in to comment.