Skip to content

Commit 2f23b30

Browse files
manask88facebook-github-bot-7
authored andcommitted
added a property to set a track image to slider ios
Summary: this change will allow the slider to have different track images. Sets an image for the sliderIOS's track. It only supports images that are included as assets. Closes facebook/react-native#3850 Reviewed By: svcscm Differential Revision: D2659680 Pulled By: nicklockwood fb-gh-sync-id: faf6ddea1077b081c1fc05f8f110b669cef9902c
1 parent 8f06150 commit 2f23b30

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

Libraries/Components/SliderIOS/SliderIOS.ios.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
'use strict';
1313

14+
var Image = require('Image');
1415
var NativeMethodsMixin = require('NativeMethodsMixin');
1516
var PropTypes = require('ReactPropTypes');
1617
var React = require('React');
@@ -76,6 +77,11 @@ var SliderIOS = React.createClass({
7677
*/
7778
disabled: PropTypes.bool,
7879

80+
/**
81+
* Sets an image for the track. It only supports images that are included as assets
82+
*/
83+
trackImage: Image.propTypes.source,
84+
7985
/**
8086
* Callback continuously called while the user is dragging the slider.
8187
*/

React/Views/RCTSlider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919
@property (nonatomic, assign) float step;
2020
@property (nonatomic, assign) float lastValue;
2121

22+
@property (nonatomic, strong) UIImage *trackImage;
23+
2224
@end

React/Views/RCTSlider.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,19 @@ - (void)setMaximumValue:(float)maximumValue
3232
super.value = _unclippedValue;
3333
}
3434

35+
- (void)setTrackImage:(UIImage *)trackImage
36+
{
37+
if (trackImage != _trackImage) {
38+
_trackImage = trackImage;
39+
40+
CGFloat width = trackImage.size.width;
41+
42+
UIImage *minimumTrackImage = [trackImage resizableImageWithCapInsets:(UIEdgeInsets){0, width, 0, 0}];
43+
UIImage *maximumTrackImage = [trackImage resizableImageWithCapInsets:(UIEdgeInsets){0, 0, 0, width}];
44+
45+
[super setMinimumTrackImage:minimumTrackImage forState:UIControlStateNormal];
46+
[super setMaximumTrackImage:maximumTrackImage forState:UIControlStateNormal];
47+
}
48+
}
49+
3550
@end

React/Views/RCTSliderManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ - (void)sliderTouchEnd:(RCTSlider *)sender
7676

7777
RCT_EXPORT_VIEW_PROPERTY(value, float);
7878
RCT_EXPORT_VIEW_PROPERTY(step, float);
79+
RCT_EXPORT_VIEW_PROPERTY(trackImage, UIImage);
7980
RCT_EXPORT_VIEW_PROPERTY(minimumValue, float);
8081
RCT_EXPORT_VIEW_PROPERTY(maximumValue, float);
8182
RCT_EXPORT_VIEW_PROPERTY(minimumTrackTintColor, UIColor);

0 commit comments

Comments
 (0)