Skip to content

Commit f3d2ecc

Browse files
authored
Slider - fix track to properly bring theme (minimum\maximum) color (#818)
1 parent 43940e1 commit f3d2ecc

File tree

1 file changed

+68
-59
lines changed

1 file changed

+68
-59
lines changed

src/components/slider/index.js

Lines changed: 68 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ export default class Slider extends PureBaseComponent {
132132
}
133133
}
134134

135-
generateStyles() {
136-
this.styles = createStyles(this.getThemeProps());
137-
}
138-
139135
UNSAFE_componentWillMount() {
140136
this._panResponder = PanResponder.create({
141137
onMoveShouldSetPanResponder: this.handleMoveShouldSetPanResponder,
@@ -243,8 +239,8 @@ export default class Slider extends PureBaseComponent {
243239
updateThumbStyle(start) {
244240
if (this.thumb && !this.props.disableActiveStyling) {
245241
const {thumbStyle, activeThumbStyle} = this.props;
246-
const style = thumbStyle || this.styles.thumb;
247-
const activeStyle = activeThumbStyle || this.styles.activeThumb;
242+
const style = thumbStyle || styles.thumb;
243+
const activeStyle = activeThumbStyle || styles.activeThumb;
248244

249245
this._thumbStyles.style = !this.props.disabled && (start ? activeStyle : style);
250246
this.thumb.setNativeProps(this._thumbStyles);
@@ -373,11 +369,20 @@ export default class Slider extends PureBaseComponent {
373369
/* Renders */
374370

375371
render() {
376-
const {containerStyle, thumbStyle, trackStyle, renderTrack, disabled, thumbTintColor} = this.getThemeProps();
372+
const {
373+
containerStyle,
374+
thumbStyle,
375+
trackStyle,
376+
renderTrack,
377+
disabled,
378+
thumbTintColor,
379+
minimumTrackTintColor = ACTIVE_COLOR,
380+
maximumTrackTintColor = DEFAULT_COLOR
381+
} = this.getThemeProps();
377382

378383
return (
379384
<View
380-
style={[this.styles.container, containerStyle]}
385+
style={[styles.container, containerStyle]}
381386
onLayout={this.onContainerLayout}
382387
accessible
383388
accessibilityLabel={'Slider'}
@@ -389,22 +394,33 @@ export default class Slider extends PureBaseComponent {
389394
onAccessibilityAction={this.onAccessibilityAction}
390395
>
391396
{_.isFunction(renderTrack) ? (
392-
<View style={[this.styles.track, trackStyle]} onLayout={this.onTrackLayout}>
397+
<View
398+
style={[styles.track, {backgroundColor: maximumTrackTintColor}, trackStyle]}
399+
onLayout={this.onTrackLayout}
400+
>
393401
{renderTrack()}
394402
</View>
395403
) : (
396404
<View>
397405
<View
398-
style={[this.styles.track, trackStyle, disabled && this.styles.trackDisabled]}
406+
style={[
407+
styles.track,
408+
trackStyle,
409+
{
410+
backgroundColor: disabled ? INACTIVE_COLOR : maximumTrackTintColor
411+
}
412+
]}
399413
onLayout={this.onTrackLayout}
400414
/>
401415
<View
402416
ref={this.setMinTrackRef}
403417
style={[
404-
this.styles.track,
418+
styles.track,
405419
trackStyle,
406-
this.styles.minimumTrack,
407-
disabled && {backgroundColor: DEFAULT_COLOR}
420+
styles.minimumTrack,
421+
{
422+
backgroundColor: disabled ? DEFAULT_COLOR : minimumTrackTintColor
423+
}
408424
]}
409425
/>
410426
</View>
@@ -413,60 +429,53 @@ export default class Slider extends PureBaseComponent {
413429
ref={this.setThumbRef}
414430
onLayout={this.onThumbLayout}
415431
style={[
416-
this.styles.thumb,
432+
styles.thumb,
417433
thumbStyle,
418434
{
419435
backgroundColor: disabled ? DEFAULT_COLOR : thumbTintColor || ACTIVE_COLOR
420436
}
421437
]}
422438
/>
423-
<View style={this.styles.touchArea} {...this._panResponder.panHandlers}/>
439+
<View style={styles.touchArea} {...this._panResponder.panHandlers}/>
424440
</View>
425441
);
426442
}
427443
}
428444

429-
function createStyles({minimumTrackTintColor = ACTIVE_COLOR, maximumTrackTintColor = DEFAULT_COLOR}) {
430-
return StyleSheet.create({
431-
container: {
432-
height: THUMB_SIZE + SHADOW_RADIUS,
433-
justifyContent: 'center'
434-
},
435-
track: {
436-
height: TRACK_SIZE,
437-
borderRadius: TRACK_SIZE / 2,
438-
backgroundColor: maximumTrackTintColor,
439-
overflow: 'hidden'
440-
},
441-
trackDisabled: {
442-
backgroundColor: INACTIVE_COLOR
443-
},
444-
minimumTrack: {
445-
position: 'absolute',
446-
backgroundColor: minimumTrackTintColor
447-
},
448-
thumb: {
449-
position: 'absolute',
450-
width: THUMB_SIZE,
451-
height: THUMB_SIZE,
452-
borderRadius: THUMB_SIZE / 2,
453-
borderWidth: BORDER_WIDTH,
454-
borderColor: Colors.white,
455-
shadowColor: Colors.rgba(Colors.black, 0.3),
456-
shadowOffset: {width: 0, height: 0},
457-
shadowOpacity: 0.9,
458-
shadowRadius: SHADOW_RADIUS,
459-
elevation: 2
460-
},
461-
activeThumb: {
462-
width: THUMB_SIZE + 16,
463-
height: THUMB_SIZE + 16,
464-
borderRadius: (THUMB_SIZE + 16) / 2,
465-
borderWidth: BORDER_WIDTH + 6
466-
},
467-
touchArea: {
468-
...StyleSheet.absoluteFillObject,
469-
backgroundColor: 'transparent'
470-
}
471-
});
472-
}
445+
const styles = StyleSheet.create({
446+
container: {
447+
height: THUMB_SIZE + SHADOW_RADIUS,
448+
justifyContent: 'center'
449+
},
450+
track: {
451+
height: TRACK_SIZE,
452+
borderRadius: TRACK_SIZE / 2,
453+
overflow: 'hidden'
454+
},
455+
minimumTrack: {
456+
position: 'absolute'
457+
},
458+
thumb: {
459+
position: 'absolute',
460+
width: THUMB_SIZE,
461+
height: THUMB_SIZE,
462+
borderRadius: THUMB_SIZE / 2,
463+
borderWidth: BORDER_WIDTH,
464+
borderColor: Colors.white,
465+
shadowColor: Colors.rgba(Colors.black, 0.3),
466+
shadowOffset: {width: 0, height: 0},
467+
shadowOpacity: 0.9,
468+
shadowRadius: SHADOW_RADIUS,
469+
elevation: 2
470+
},
471+
activeThumb: {
472+
width: THUMB_SIZE + 16,
473+
height: THUMB_SIZE + 16,
474+
borderRadius: (THUMB_SIZE + 16) / 2,
475+
borderWidth: BORDER_WIDTH + 6
476+
},
477+
touchArea: {
478+
...StyleSheet.absoluteFillObject,
479+
backgroundColor: 'transparent'
480+
}
481+
});

0 commit comments

Comments
 (0)