Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions Example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

var React = require('react');
var ReactNative = require('react-native');
var Slider = require('../src/Slider');
var Slider = require('../src/Slider').default;
var {
AppRegistry,
StyleSheet,
Text,
ScrollView,
View,
SliderIOS,
} = ReactNative;

var DEFAULT_VALUE = 0.2;
Expand All @@ -18,6 +17,7 @@ var SliderContainer = React.createClass({
getInitialState() {
return {
value: DEFAULT_VALUE,
rightValue: 0.8
};
},

Expand All @@ -27,8 +27,9 @@ var SliderContainer = React.createClass({
return (
<View>
<View style={styles.titleContainer}>
<Text style={styles.caption} numberOfLines={1}>{this.props.caption}</Text>
<Text style={styles.value} numberOfLines={1}>{value}</Text>
<Text style={styles.caption}>{this.props.caption}</Text>
<Text style={styles.value} numberOfLines={1}>{this.state.value}</Text>
<Text style={styles.rightValue} numberOfLines={1}>{this.state.rightValue ? ` - ${this.state.rightValue}` : null}</Text>
</View>
{this._renderChildren()}
</View>
Expand All @@ -38,11 +39,11 @@ var SliderContainer = React.createClass({
_renderChildren() {
return React.Children.map(this.props.children, (child) => {
if (child.type === Slider
|| child.type === ReactNative.Slider) {
var value = this.state.value;
|| child.type === ReactNative.Slider) {
return React.cloneElement(child, {
value: value,
onValueChange: (val) => this.setState({value: val}),
value: child.props.value || this.state.value,
rightValue: child.props.rightValue || this.state.rightValue,
onValueChange: (val,val2) => this.setState({value: val, rightValue: child.props.multiTouch ? val2 : null }),
});
} else {
return child;
Expand Down Expand Up @@ -71,73 +72,88 @@ var SliderExample = React.createClass({
<Slider
minimumValue={-10}
maximumValue={42}
minimumTrackTintColor='#1fb28a'
maximumTrackTintColor='#d3d3d3'
trackHighlightColor='#1fb28a'
trackColor='#d3d3d3'
thumbTintColor='#1a9274'
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style'>
<Slider
trackStyle={iosStyles.track}
thumbStyle={iosStyles.thumb}
minimumTrackTintColor='#1073ff'
maximumTrackTintColor='#b7b7b7'
trackHighlightColor='#1073ff'
trackColor='#b7b7b7'
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style #2'>
<Slider
trackStyle={customStyles2.track}
thumbStyle={customStyles2.thumb}
minimumTrackTintColor='#30a935'
trackHighlightColor='#30a935'
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style #3'>
<Slider
trackStyle={customStyles3.track}
thumbStyle={customStyles3.thumb}
minimumTrackTintColor='#eecba8'
trackHighlightColor='#eecba8'
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style #4'>
<Slider
trackStyle={customStyles4.track}
thumbStyle={customStyles4.thumb}
minimumTrackTintColor='#d14ba6'
trackHighlightColor='#d14ba6'
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style #5'>
<Slider
trackStyle={customStyles5.track}
thumbStyle={customStyles5.thumb}
minimumTrackTintColor='#ec4c46'
trackHighlightColor='#ec4c46'
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style #6'>
<Slider
trackStyle={customStyles6.track}
thumbStyle={customStyles6.thumb}
minimumTrackTintColor='#e6a954'
trackHighlightColor='#e6a954'
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style #7'>
<Slider
trackStyle={customStyles7.track}
thumbStyle={customStyles7.thumb}
minimumTrackTintColor='#2f2f2f'
trackHighlightColor='#2f2f2f'
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style #8 and thumbTouchSize'>
<Slider
style={customStyles8.container}
trackStyle={customStyles8.track}
thumbStyle={customStyles8.thumb}
minimumTrackTintColor='#31a4db'
trackHighlightColor='#31a4db'
thumbTouchSize={{width: 50, height: 40}}
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with 2 touches'>
<Slider
style={customStyles8.container}
trackStyle={customStyles8.track}
thumbStyle={customStyles8.thumb}
trackHighlightColor='#e6a954'
trackColor='#b7b7b7'
thumbTouchSize={{width: 50, height: 40}}
multiTouch={true}
value={1}
rightValue={80}
step={1}
maximumValue={100}
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style #9 and thumbImage'>
<Slider
minimumTrackTintColor='#13a9d6'
trackHighlightColor='#13a9d6'
thumbImage={require('./img/thumb.png')}
thumbStyle={customStyles9.thumb}
thumbTintColor='#0c6692'
Expand All @@ -161,7 +177,7 @@ var styles = StyleSheet.create({
alignItems: 'center',
},
caption: {
//flex: 1,
flex: 3,
},
value: {
flex: 1,
Expand Down
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,32 @@ Try this example [live on Expo Snack](https://snack.expo.io/HkbAqpbwb).

## Props

Prop | Type | Optional | Default | Description
--------------------- | -------- | -------- | ------------------------- | -----------
value | number | Yes | 0 | Initial value of the slider
disabled | bool | Yes | false | If true the user won't be able to move the slider
minimumValue | number | Yes | 0 | Initial minimum value of the slider
maximumValue | number | Yes | 1 | Initial maximum value of the slider
step | number | Yes | 0 | Step value of the slider. The value should be between 0 and maximumValue - minimumValue)
minimumTrackTintColor | string | Yes | '#3f3f3f' | The color used for the track to the left of the button
maximumTrackTintColor | string | Yes | '#b3b3b3' | The color used for the track to the right of the button
thumbTintColor | string | Yes | '#343434' | The color used for the thumb
thumbTouchSize | object | Yes | `{width: 40, height: 40}` | The size of the touch area that allows moving the thumb. The touch area has the same center as the visible thumb. This allows to have a visually small thumb while still allowing the user to move it easily.
onValueChange | function | Yes | | Callback continuously called while the user is dragging the slider
onSlidingStart | function | Yes | | Callback called when the user starts changing the value (e.g. when the slider is pressed)
onSlidingComplete | function | Yes | | Callback called when the user finishes changing the value (e.g. when the slider is released)
style | [style](http://facebook.github.io/react-native/docs/view.html#style) | Yes | | The style applied to the slider container
trackStyle | [style](http://facebook.github.io/react-native/docs/view.html#style) | Yes | | The style applied to the track
thumbStyle | [style](http://facebook.github.io/react-native/docs/view.html#style) | Yes | | The style applied to the thumb
thumbImage | [source](http://facebook.github.io/react-native/docs/image.html#source) | Yes | | Sets an image for the thumb.
debugTouchArea | bool | Yes | false | Set this to true to visually see the thumb touch rect in green.
animateTransitions | bool | Yes | false | Set to true if you want to use the default 'spring' animation
animationType | string | Yes | 'timing' | Set to 'spring' or 'timing' to use one of those two types of animations with the default [animation properties](https://facebook.github.io/react-native/docs/animations.html).
animationConfig | object | Yes | undefined | Used to configure the animation parameters. These are the same parameters in the [Animated library](https://facebook.github.io/react-native/docs/animations.html).
Prop | Type | Optional | Default | Description
--------------------- | -------- | -------- | ------------------------- | -----------
value | number | Yes | 0 | Initial value of the slider
rightValue | number | Yes | 0 | Initial value of the right slider if multi touch
disabled | bool | Yes | false | If true the user won't be able to move the slider
minimumValue | number | Yes | 0 | Initial minimum value of the slider
maximumValue | number | Yes | 1 | Initial maximum value of the slider
step | number | Yes | 0 | Step value of the slider. The value should be between 0 and maximumValue - minimumValue)
minimumTrackTintColor(deprecated) | string | Yes | '#3f3f3f' | The color used for the track to the left of the button
maximumTrackTintColor(deprecated) | string | Yes | '#b3b3b3' | The color used for the track to the right of the button
trackColor | string | Yes | '#b3b3b3' | The color used for the track
trackHighlightColor | string | Yes | '#b3b3b3' | The color used for the track to the right of the button in single, in between buttons in multi
thumbTintColor | string | Yes | '#343434' | The color used for the thumb
thumbTouchSize | object | Yes | `{width: 40, height: 40}` | The size of the touch area that allows moving the thumb. The touch area has the same center as the visible thumb. This allows to have a visually small thumb while still allowing the user to move it easily.
onValueChange | function | Yes | | Callback continuously called while the user is dragging the slider
onSlidingStart | function | Yes | | Callback called when the user starts changing the value (e.g. when the slider is pressed)
onSlidingComplete | function | Yes | | Callback called when the user finishes changing the value (e.g. when the slider is released)
style | [style](http://facebook.github.io/react-native/docs/view.html#style) | Yes | | The style applied to the slider container
trackStyle | [style](http://facebook.github.io/react-native/docs/view.html#style) | Yes | | The style applied to the track
thumbStyle | [style](http://facebook.github.io/react-native/docs/view.html#style) | Yes | | The style applied to the thumb
thumbImage | [source](http://facebook.github.io/react-native/docs/image.html#source) | Yes | | Sets an image for the thumb.
debugTouchArea | bool | Yes | false | Set this to true to visually see the thumb touch rect in green.
multiTouch | bool | Yes | false | Set to true if you want 2 sliders
animateTransitions | bool | Yes | false | Set to true if you want to use the default 'spring' animation
animationType | string | Yes | 'timing' | Set to 'spring' or 'timing' to use one of those two types of animations with the default [animation properties](https://facebook.github.io/react-native/docs/animations.html).
animationConfig | object | Yes | undefined | Used to configure the animation parameters. These are the same parameters in the [Animated library](https://facebook.github.io/react-native/docs/animations.html).


---
Expand Down
Loading