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 https://github.com/facebook/react-native/pull/3850

Reviewed By: svcscm

Differential Revision: D2659680

Pulled By: nicklockwood

fb-gh-sync-id: faf6ddea1077b081c1fc05f8f110b669cef9902c
This commit is contained in:
Manuel Nakamurakare 2015-11-17 08:43:13 -08:00 committed by facebook-github-bot-7
parent 8f0615080b
commit 2f23b30624
4 changed files with 24 additions and 0 deletions

View File

@ -11,6 +11,7 @@
*/ */
'use strict'; 'use strict';
var Image = require('Image');
var NativeMethodsMixin = require('NativeMethodsMixin'); var NativeMethodsMixin = require('NativeMethodsMixin');
var PropTypes = require('ReactPropTypes'); var PropTypes = require('ReactPropTypes');
var React = require('React'); var React = require('React');
@ -76,6 +77,11 @@ var SliderIOS = React.createClass({
*/ */
disabled: PropTypes.bool, disabled: PropTypes.bool,
/**
* Sets an image for the track. It only supports images that are included as assets
*/
trackImage: Image.propTypes.source,
/** /**
* Callback continuously called while the user is dragging the slider. * Callback continuously called while the user is dragging the slider.
*/ */

View File

@ -19,4 +19,6 @@
@property (nonatomic, assign) float step; @property (nonatomic, assign) float step;
@property (nonatomic, assign) float lastValue; @property (nonatomic, assign) float lastValue;
@property (nonatomic, strong) UIImage *trackImage;
@end @end

View File

@ -32,4 +32,19 @@
super.value = _unclippedValue; super.value = _unclippedValue;
} }
- (void)setTrackImage:(UIImage *)trackImage
{
if (trackImage != _trackImage) {
_trackImage = trackImage;
CGFloat width = trackImage.size.width;
UIImage *minimumTrackImage = [trackImage resizableImageWithCapInsets:(UIEdgeInsets){0, width, 0, 0}];
UIImage *maximumTrackImage = [trackImage resizableImageWithCapInsets:(UIEdgeInsets){0, 0, 0, width}];
[super setMinimumTrackImage:minimumTrackImage forState:UIControlStateNormal];
[super setMaximumTrackImage:maximumTrackImage forState:UIControlStateNormal];
}
}
@end @end

View File

@ -76,6 +76,7 @@ static void RCTSendSliderEvent(RCTSlider *sender, BOOL continuous)
RCT_EXPORT_VIEW_PROPERTY(value, float); RCT_EXPORT_VIEW_PROPERTY(value, float);
RCT_EXPORT_VIEW_PROPERTY(step, float); RCT_EXPORT_VIEW_PROPERTY(step, float);
RCT_EXPORT_VIEW_PROPERTY(trackImage, UIImage);
RCT_EXPORT_VIEW_PROPERTY(minimumValue, float); RCT_EXPORT_VIEW_PROPERTY(minimumValue, float);
RCT_EXPORT_VIEW_PROPERTY(maximumValue, float); RCT_EXPORT_VIEW_PROPERTY(maximumValue, float);
RCT_EXPORT_VIEW_PROPERTY(minimumTrackTintColor, UIColor); RCT_EXPORT_VIEW_PROPERTY(minimumTrackTintColor, UIColor);