Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a property to set a track image to slider ios #3850

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions Libraries/Components/SliderIOS/SliderIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
'use strict';

var Image = require('Image');
var NativeMethodsMixin = require('NativeMethodsMixin');
var PropTypes = require('ReactPropTypes');
var React = require('React');
Expand Down Expand Up @@ -76,6 +77,11 @@ var SliderIOS = React.createClass({
*/
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.
*/
Expand Down
12 changes: 12 additions & 0 deletions React/Views/RCTSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,16 @@ - (void)setMaximumValue:(float)maximumValue
super.value = _unclippedValue;
}

-(void)setTrackImage: (UIImage *) sliderTrackImage
{

NSInteger width = sliderTrackImage.size.width;

UIImage *sliderLeftTrackImage = [sliderTrackImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, width, 0, 0)];
UIImage *setMaximumTrackImage = [sliderTrackImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, width)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to make these separate properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the result you want to achieve. If your goal is to have a simple track image, I would say this is the best way. If we make these separate properties, it will give more flexibility on what can be achieved, but it will make having a simple track image more complicated


[super setMinimumTrackImage:sliderLeftTrackImage forState:UIControlStateNormal];
[super setMaximumTrackImage:setMaximumTrackImage forState:UIControlStateNormal];
}

@end
1 change: 1 addition & 0 deletions React/Views/RCTSliderManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ - (void)sliderTouchEnd:(RCTSlider *)sender

RCT_EXPORT_VIEW_PROPERTY(value, float);
RCT_EXPORT_VIEW_PROPERTY(step, float);
RCT_EXPORT_VIEW_PROPERTY(trackImage, UIImage);
RCT_EXPORT_VIEW_PROPERTY(minimumValue, float);
RCT_EXPORT_VIEW_PROPERTY(maximumValue, float);
RCT_EXPORT_VIEW_PROPERTY(minimumTrackTintColor, UIColor);
Expand Down