Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const handleValueChange = useCallback((low, high) => {
| `onValueChanged` | Will be called when a value was changed.<br/>If `disableRange` is set to true, the second argument should be ignored.<br/>`fromUser` will be true if the value was changed by user's interaction. | `(low: number, high: number, fromUser: boolean) => void` | `undefined` |
| `onSliderTouchStart` | Will be called when user starts interaction with slider.<br/>If `disableRange` is set to true, the second argument should be ignored. | `(low: number, high: number) => void` | `undefined` |
| `onSliderTouchEnd` | Will be called when user ends interaction with slider.<br/>If `disableRange` is set to true, the second argument should be ignored. | `(low: number, high: number) => void` | `undefined` |
| `thumbTrackingValue` | If enabled, both the `label` and `notch` will be hidden. Instead, the low and high values will update and move along with the thumb as the user slides it. <br /> You can also customize the appearance of the value by configuring `thumbTrackingValueStyle`. | boolean | `false` |
| `thumbTrackingValueStyle` | only functions when `thumbTrackingValue` is enabled, allowing you to customize its appearance. | TextStyle | Initially, it will be `undefined` if not provided. |

All the other props (e.g. style) will be passed to root container component.

Expand Down
25 changes: 22 additions & 3 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
PanResponderGestureState,
View,
ViewProps,
Text,
TextStyle,
} from 'react-native';

import styles from './styles';
Expand Down Expand Up @@ -41,6 +43,8 @@ export interface SliderProps extends ViewProps {
disableRange?: boolean;
disabled?: boolean;
floatingLabel?: boolean;
thumbTrackingValue?: boolean;
thumbTrackingValueStyle?: TextStyle;
renderLabel?: (value: number) => ReactNode;
renderNotch?: (value: number) => ReactNode;
renderRail: () => ReactNode;
Expand All @@ -58,6 +62,8 @@ const Slider: React.FC<SliderProps> = ({
low: lowProp,
high: highProp,
floatingLabel = false,
thumbTrackingValue = false,
thumbTrackingValueStyle,
allowLabelOverflow = false,
disableRange = false,
disabled = false,
Expand Down Expand Up @@ -297,10 +303,13 @@ const Slider: React.FC<SliderProps> = ({

return (
<View {...restProps}>
<View {...labelContainerProps}>
{!thumbTrackingValue &&
(<View {...labelContainerProps}>
{labelView}
{notchView}
</View>
</View>)
}

<View onLayout={handleContainerLayout} style={styles.controlsContainer}>
<View style={railContainerStyles}>
{renderRail()}
Expand All @@ -309,10 +318,20 @@ const Slider: React.FC<SliderProps> = ({
</Animated.View>
</View>
<Animated.View style={lowStyles} onLayout={handleThumbLayout}>
{thumbTrackingValue && (<Text style={[styles.thumbTrackingValueText, thumbTrackingValueStyle]}>
{inPropsRef.current.low}
</Text>)}
{lowThumb}
</Animated.View>

{!disableRange && (
<Animated.View style={highStyles}>{highThumb}</Animated.View>
<Animated.View style={highStyles}>
{thumbTrackingValue && (<Text style={[styles.thumbTrackingValueText, thumbTrackingValueStyle]}>
{inPropsRef.current.high}
</Text>)}

{highThumb}
</Animated.View>
)}
<View
{...panHandlers}
Expand Down
3 changes: 3 additions & 0 deletions styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ export default StyleSheet.create({
touchableArea: {
...StyleSheet.absoluteFillObject,
},
thumbTrackingValueText: {
color: 'black',
}
});