Skip to content

Commit ef52341

Browse files
authored
Merge pull request #98 from moAlobaidi/feature/touch-feedback
add touch events
2 parents c8f4489 + ab4acf3 commit ef52341

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/slider.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ export type AwesomeSliderProps = {
198198
bubbleContainerStyle?: StyleProp<ViewStyle>;
199199

200200
/**
201-
* By this, you know the slider status as quickly as possible.(This is useful when you doing video-palyer’s scrubber.)
201+
* By this, you know the slider status as quickly as possible.(This is useful when you doing video-player's scrubber.)
202202
*/
203203
isScrubbing?: Animated.SharedValue<boolean>;
204204
/**
205-
* On tap slider event.(This is useful when you doing video-palyer’s scrubber.)
205+
* On tap slider event.(This is useful when you doing video-player's scrubber.)
206206
*/
207207
onTap?: () => void;
208208
/**
@@ -319,6 +319,16 @@ export type AwesomeSliderProps = {
319319
* @default true
320320
*/
321321
isRTL?: boolean;
322+
323+
/**
324+
* Callback called when the user touches the slider
325+
*/
326+
onTouchStart?: () => void;
327+
328+
/**
329+
* Callback called when the user releases touch from the slider
330+
*/
331+
onTouchEnd?: () => void;
322332
};
323333
const defaultTheme: SliderThemeType = {
324334
minimumTrackTintColor: palette.Main,
@@ -382,6 +392,8 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
382392
snapThreshold = 0,
383393
snapThresholdMode = 'absolute',
384394
isRTL = I18nManager.isRTL,
395+
onTouchStart,
396+
onTouchEnd,
385397
}) {
386398
const step = propsStep || steps;
387399

@@ -755,6 +767,9 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
755767
isTouchInThumbRange.value =
756768
Math.abs(x - thumbPosition.value) <= thumbTouchSize;
757769
}
770+
if (onTouchStart) {
771+
runOnJS(onTouchStart)();
772+
}
758773
})
759774
.onStart(() => {
760775
if (disable) {
@@ -818,6 +833,11 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
818833
if (onSlidingComplete) {
819834
runOnJS(onSlidingComplete)(shareValueToSeconds());
820835
}
836+
})
837+
.onFinalize(() => {
838+
if (onTouchEnd) {
839+
runOnJS(onTouchEnd)();
840+
}
821841
});
822842

823843
if (activeOffsetX) {
@@ -866,6 +886,8 @@ export const Slider: FC<AwesomeSliderProps> = memo(function Slider({
866886
disableTrackPress,
867887
isRTL,
868888
width,
889+
onTouchStart,
890+
onTouchEnd,
869891
]);
870892
const onSingleTapEvent = useMemo(
871893
() =>

0 commit comments

Comments
 (0)