@@ -7,6 +7,7 @@ @implementation RNCSlider
77 bool _maximumTrackImageSet;
88 UIImage *_thumbImage;
99 CGFloat _thumbSize;
10+ UIColor *_thumbTintColor;
1011}
1112
1213- (instancetype )init {
@@ -119,7 +120,7 @@ - (UIImage *)maximumTrackImage
119120- (void )setThumbImage : (UIImage *)thumbImage
120121{
121122 _thumbImage = thumbImage;
122- [self updateThumbImage ];
123+ [self refreshThumb ];
123124}
124125
125126- (UIImage *)thumbImage
@@ -130,11 +131,26 @@ - (UIImage *)thumbImage
130131- (void )setThumbSize : (CGFloat)thumbSize
131132{
132133 _thumbSize = thumbSize;
133- [self updateThumbImage ];
134+ [self refreshThumb ];
134135}
135136
136- - (void )updateThumbImage
137+ - (void )setThumbTintColor : (UIColor *) thumbTintColor
137138{
139+ _thumbTintColor = thumbTintColor;
140+ [super setThumbTintColor: thumbTintColor];
141+
142+ [self refreshThumb ];
143+ }
144+
145+ - (void )refreshThumb
146+ {
147+ if (![NSThread isMainThread ]) {
148+ dispatch_async (dispatch_get_main_queue (), ^{
149+ [self refreshThumb ];
150+ });
151+ return ;
152+ }
153+
138154 UIImage *imageToSet = nil ;
139155
140156 if (_thumbSize > 0 ) {
@@ -145,7 +161,7 @@ - (void)updateThumbImage
145161 if (_thumbImage) {
146162 [_thumbImage drawInRect: CGRectMake (0 , 0 , newSize.width, newSize.height)];
147163 } else {
148- UIColor *fillColor = self.thumbTintColor ?: [UIColor whiteColor ];
164+ UIColor *fillColor = _thumbTintColor ?: self.thumbTintColor ?: [UIColor whiteColor ];
149165 CGContextSetFillColorWithColor (context, fillColor.CGColor );
150166 CGContextFillEllipseInRect (context, CGRectMake (0 , 0 , newSize.width , newSize.height ));
151167
@@ -167,6 +183,34 @@ - (void)updateThumbImage
167183 [self setThumbImage: imageToSet forState: UIControlStateHighlighted];
168184 [self setThumbImage: imageToSet forState: UIControlStateSelected];
169185 }
186+
187+ [UIView performWithoutAnimation: ^{
188+ float currentValue = super.value ;
189+ float minimumValue = super.minimumValue ;
190+ float maximumValue = super.maximumValue ;
191+
192+ float eps = (maximumValue - minimumValue) / 1000 .0f ;
193+ if (eps <= 0 ) {
194+ eps = 0 .0001f ;
195+ }
196+
197+ float nudgedValue = currentValue + eps;
198+ if (nudgedValue > maximumValue) {
199+ nudgedValue = currentValue - eps;
200+ }
201+ if (nudgedValue < minimumValue) {
202+ nudgedValue = minimumValue;
203+ }
204+
205+ if (nudgedValue != currentValue) {
206+ [super setValue: nudgedValue animated: NO ];
207+ }
208+ [super setValue: currentValue animated: NO ];
209+
210+ [self setNeedsLayout ];
211+ [self layoutSubviews ];
212+ [self layoutIfNeeded ];
213+ }];
170214}
171215
172216- (void )setInverted : (BOOL )inverted
0 commit comments