Add thumb image

This commit is contained in:
Jan Maršíček
2016-06-10 15:37:59 +02:00
parent 0a6cdef992
commit b80a78de41
10 changed files with 39 additions and 2 deletions

View File

@@ -135,6 +135,14 @@ var SliderExample = React.createClass({
thumbTouchSize={{width: 50, height: 40}}
/>
</SliderContainer>
<SliderContainer caption='<Slider/> with custom style #9 and thumbImage'>
<Slider
minimumTrackTintColor='#13a9d6'
thumbImage={require('./img/thumb.png')}
thumbStyle={customStyles9.thumb}
thumbTintColor='#0c6692'
/>
</SliderContainer>
</ScrollView>
);
},
@@ -281,7 +289,7 @@ var customStyles7 = StyleSheet.create({
var customStyles8 = StyleSheet.create({
container: {
height: 20,
height: 30,
},
track: {
height: 2,
@@ -299,4 +307,15 @@ var customStyles8 = StyleSheet.create({
}
});
var customStyles9 = StyleSheet.create({
thumb: {
width: 30,
height: 30,
shadowColor: 'black',
shadowOffset: {width: 0, height: 1},
shadowOpacity: 0.5,
shadowRadius: 1,
}
});
AppRegistry.registerComponent('Example', () => SliderExample);

BIN
Example/img/thumb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

BIN
Example/img/thumb@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

BIN
Example/img/thumb@3x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

View File

@@ -92,6 +92,7 @@ onSlidingComplete | function | Yes | | Callba
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.
---

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 122 KiB

View File

@@ -7,6 +7,7 @@ import React, {
import {
Animated,
Image,
StyleSheet,
PanResponder,
View
@@ -126,6 +127,11 @@ var Slider = React.createClass({
*/
thumbStyle: View.propTypes.style,
/**
* Sets an image for the thumb.
*/
thumbImage: Image.propTypes.source,
/**
* Set this to true to visually see the thumb touch rect in green.
*/
@@ -192,6 +198,7 @@ var Slider = React.createClass({
minimumTrackTintColor,
maximumTrackTintColor,
thumbTintColor,
thumbImage,
styles,
style,
trackStyle,
@@ -233,7 +240,9 @@ var Slider = React.createClass({
{backgroundColor: thumbTintColor, marginTop: -(trackSize.height + thumbSize.height) / 2},
mainStyles.thumb, thumbStyle, {left: thumbLeft, ...valueVisibleStyle}
]}
/>
>
{this._renderThumbImage()}
</Animated.View>
<View
style={[defaultStyles.touchArea, touchOverflowStyle]}
{...this._panResponder.panHandlers}>
@@ -439,6 +448,14 @@ var Slider = React.createClass({
pointerEvents='none'
/>
);
},
_renderThumbImage() {
var {thumbImage} = this.props;
if (!thumbImage) return;
return <Image source={thumbImage} />;
}
});