Skip to content

Commit 4cb7752

Browse files
christopherdrofacebook-github-bot-0
authored andcommitted
Add option for both min/max track image.
Summary: This is a followup to PR facebook#3850 but now separates min/max track images into different properties. Closes facebook#4476 Add examples for `minimumTrackTintColor`, `maximumTrackTintColor`, `minimumTrackImage`, `maximumTrackImage` to UIExplorer. Closes facebook#4586 Reviewed By: svcscm Differential Revision: D2779193 Pulled By: nicklockwood fb-gh-sync-id: 0510a0f496816baacdd0d4be0f3cd3a63a5a9865
1 parent 41875ee commit 4cb7752

File tree

12 files changed

+100
-27
lines changed

12 files changed

+100
-27
lines changed

Examples/UIExplorer/SliderIOSExample.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,38 @@ exports.examples = [
8484
return <SliderExample step={0.25} />;
8585
}
8686
},
87+
{
88+
title: 'Custom min/max track tint color',
89+
render(): ReactElement {
90+
return (
91+
<SliderExample
92+
minimumTrackTintColor={'red'}
93+
maximumTrackTintColor={'green'}
94+
/>
95+
);
96+
}
97+
},
8798
{
8899
title: 'Custom thumb image',
89100
render(): ReactElement {
90-
return <SliderExample thumbImage={require('image!uie_thumb_big')} />;
101+
return <SliderExample thumbImage={require('./uie_thumb_big.png')} />;
91102
}
92-
}
103+
},
104+
{
105+
title: 'Custom track image',
106+
render(): ReactElement {
107+
return <SliderExample trackImage={require('./slider.png')} />;
108+
}
109+
},
110+
{
111+
title: 'Custom min/max track image',
112+
render(): ReactElement {
113+
return (
114+
<SliderExample
115+
minimumTrackImage={require('./slider-left.png')}
116+
maximumTrackImage={require('./slider-right.png')}
117+
/>
118+
);
119+
}
120+
},
93121
];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
1.36 KB
Loading
1.64 KB
Loading
1.37 KB
Loading
1.63 KB
Loading

Examples/UIExplorer/slider.png

1.53 KB
Loading

Examples/UIExplorer/slider@2x.png

1.94 KB
Loading

Libraries/Components/SliderIOS/SliderIOS.ios.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,24 @@ var SliderIOS = React.createClass({
7878
*/
7979
disabled: PropTypes.bool,
8080

81-
/**
82-
* Sets an image for the track. It only supports images that are included as assets
81+
/**
82+
* Assigns a single image for the track. Only static images are supported.
83+
* The center pixel of the image will be stretched to fill the track.
8384
*/
8485
trackImage: Image.propTypes.source,
8586

87+
/**
88+
* Assigns a minimum track image. Only static images are supported. The
89+
* rightmost pixel of the image will be stretched to fill the track.
90+
*/
91+
minimumTrackImage: Image.propTypes.source,
92+
93+
/**
94+
* Assigns a maximum track image. Only static images are supported. The
95+
* leftmost pixel of the image will be stretched to fill the track.
96+
*/
97+
maximumTrackImage: Image.propTypes.source,
98+
8699
/**
87100
* Sets an image for the thumb. It only supports static images.
88101
*/
@@ -107,28 +120,18 @@ var SliderIOS = React.createClass({
107120
},
108121

109122
render: function() {
123+
let {style, onValueChange, onSlidingComplete, ...props} = this.props;
124+
props.style = [styles.slider, style];
110125

111-
let onValueChange = this.props.onValueChange && ((event: Event) => {
112-
this.props.onValueChange &&
113-
this.props.onValueChange(event.nativeEvent.value);
126+
props.onValueChange = onValueChange && ((event: Event) => {
127+
onValueChange && onValueChange(event.nativeEvent.value);
114128
});
115129

116-
let onSlidingComplete = this.props.onSlidingComplete && ((event: Event) => {
117-
this.props.onSlidingComplete &&
118-
this.props.onSlidingComplete(event.nativeEvent.value);
130+
props.onSlidingComplete = onSlidingComplete && ((event: Event) => {
131+
onSlidingComplete && onSlidingComplete(event.nativeEvent.value);
119132
});
120133

121-
let {style, ...props} = this.props;
122-
style = [styles.slider, style];
123-
124-
return (
125-
<RCTSlider
126-
{...props}
127-
style={style}
128-
onValueChange={onValueChange}
129-
onSlidingComplete={onSlidingComplete}
130-
/>
131-
);
134+
return <RCTSlider {...props}/>;
132135
}
133136
});
134137

React/Views/RCTSlider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
@property (nonatomic, assign) float lastValue;
2121

2222
@property (nonatomic, strong) UIImage *trackImage;
23+
@property (nonatomic, strong) UIImage *minimumTrackImage;
24+
@property (nonatomic, strong) UIImage *maximumTrackImage;
25+
2326
@property (nonatomic, strong) UIImage *thumbImage;
2427

2528

0 commit comments

Comments
 (0)