Skip to content

Commit

Permalink
Merge pull request #273 from wyndow/add-rangeslider-hitslop
Browse files Browse the repository at this point in the history
feat(Thumb): Add optional hitSlop to Thumb for RangeSlider and Slider
  • Loading branch information
xinthink authored Dec 17, 2016
2 parents 30c2de8 + 7556e62 commit f65c613
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
10 changes: 10 additions & 0 deletions lib/internal/Thumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ class Thumb extends Component {
},
]}
{ ...this._panResponder.panHandlers }
hitSlop={{
top: this.props.touchPadding,
left: this.props.touchPadding,
bottom: this.props.touchPadding,
right: this.props.touchPadding,
}}
>
<View
style={{ // the inner circle
Expand Down Expand Up @@ -213,12 +219,16 @@ Thumb.propTypes = {

// Radius of thumb component
radius: PropTypes.number,

// Padding for the hitSlop on the Thumb component
touchPadding: PropTypes.number,
};

// ## <section id='defaults'>Defaults</section>
Thumb.defaultProps = {
radius: 6,
disabledColor: DEFAULT_UPPER_TRACK_COLOR,
touchPadding: 0,
};

// ## Public interface
Expand Down
18 changes: 12 additions & 6 deletions lib/mdl/RangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,10 @@ class RangeSlider extends Component {
trackMarginH={this._trackMarginH}
enabledColor={lowerTrackColor}
disabledColor={upperTrackColor}
onGrant = {this._beginMove}
onMove = {this._updateValueByTouch}
onEnd = {this._endMove}
onGrant={this._beginMove}
onMove={this._updateValueByTouch}
onEnd={this._endMove}
touchPadding={this.props.thumbPadding}
style={{
top: this._thumbRadiiWithBorder * (THUMB_SCALE_RATIO - 1) + TRACK_EXTRA_MARGIN_V,
}}
Expand All @@ -341,9 +342,10 @@ class RangeSlider extends Component {
trackMarginH={this._trackMarginH}
enabledColor={lowerTrackColor}
disabledColor={upperTrackColor}
onGrant = {this._beginMove}
onMove = {this._updateValueByTouch}
onEnd = {this._endMove}
onGrant={this._beginMove}
onMove={this._updateValueByTouch}
onEnd={this._endMove}
touchPadding={this.props.thumbPadding}
style={{
top: this._thumbRadiiWithBorder * (THUMB_SCALE_RATIO - 1) + TRACK_EXTRA_MARGIN_V,
}}
Expand Down Expand Up @@ -407,6 +409,9 @@ RangeSlider.propTypes = {
// Radius of the thumb of the RangeSlider
thumbRadius: PropTypes.number,

// Padding for the hitSlop on the RangeSlider thumb
thumbPadding: PropTypes.number,

// Color of the lower part of the track, it's also the color of the thumb
lowerTrackColor: PropTypes.string,

Expand All @@ -428,6 +433,7 @@ RangeSlider.propTypes = {

// ## <section id='defaults'>Defaults</section>
RangeSlider.defaultProps = {
thumbPadding: 0,
thumbRadius: 6,
trackSize: 2,
min: 0,
Expand Down
5 changes: 5 additions & 0 deletions lib/mdl/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class Slider extends Component {
// Radius of the thumb of the Slider
thumbRadius: PropTypes.number,

// Padding for the hitSlop on the Slider thumb
thumbPadding: PropTypes.number,

// Color of the lower part of the track, it's also the color of the thumb
lowerTrackColor: PropTypes.string,

Expand All @@ -74,6 +77,7 @@ class Slider extends Component {

// ## <section id='defaults'>Defaults</section>
static defaultProps = {
thumbPadding: 0,
thumbRadius: 6,
trackSize: 2,
min: 0,
Expand Down Expand Up @@ -340,6 +344,7 @@ class Slider extends Component {
trackMarginH={this._trackMarginH}
enabledColor={lowerTrackColor}
disabledColor={upperTrackColor}
touchPadding={this.props.thumbPadding}
style={{
top: this._thumbRadiiWithBorder * (THUMB_SCALE_RATIO - 1) + TRACK_EXTRA_MARGIN_V,
}}
Expand Down

0 comments on commit f65c613

Please sign in to comment.