Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-awesome-slider

Package Overview
Dependencies
Maintainers
0
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-awesome-slider

Slider component written using Reanimated v2, high performance/fps, also be used for video/audio scrubber.

  • 2.5.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

React Native Awesome Slider

Reanimated v2 version npm npm runs with expo

An awesome React Native Slider component powered by Reanimated v2 and react-native-gesture-handler.

🔗 Watch video


Installation

First you have to follow installation instructions of Reanimated v2 and react-native-gesture-handler

If you react-native-gesture-handler version >= 2:

yarn add react-native-awesome-slider

else:

yarn add react-native-awesome-slider@1

Example usage

Basic use:

import { useSharedValue } from 'react-native-reanimated';
import { Slider } from 'react-native-awesome-slider';

export const Example = () => {
  const progress = useSharedValue(30);
  const min = useSharedValue(0);
  const max = useSharedValue(100);
  return (
    <Slider
      style={styles.container}
      progress={progress}
      minimumValue={min}
      maximumValue={max}
    />
  );
};
Change slider theme color?

Use the Theme object.

<Slider
  theme={{
    disableMinTrackTintColor: '#fff',
    maximumTrackTintColor: '#fff',
    minimumTrackTintColor: '#000',
    cacheTrackTintColor: '#333',
    bubbleBackgroundColor: '#666',
    heartbeatColor: '#999',
  }}
/>

For more usage, please view Example.

Add pan haptic feedback?
  1. You need add haptics feedback lib to you project.
  1. Add onHapticFeedback callback to you slider component.
<Slider
  onHapticFeedback={() => {
    ReactNativeHapticFeedback.trigger('impactLight', {
      enableVibrateFallback: true,
      ignoreAndroidSystemSettings: false,
    });
  }}
/>
  1. Set haptic mode, if you open 'step' prop, you need set hapticMode=HapticModeEnum.STEP, otherwise set to hapticMode=HapticModeEnum.BOTH.

  2. ✅ Finish!

Why use this library?

  • Pure javascript slider implementations usually rely on react-native's gesture events which may inadvertently trigger 'swipe to go back' events as you pan the slider. ❌
  • Native sliders rely on state updates, which can cause performance issues. ❌

react-native-awesome-slider relies on reanimated's ShareValue ability to run code directly in the UIThread to enhance performance, and react-native-gesture-handle won't interfere with your swiping gestures. ✨

Features

  • 100% written in TypeScript.
  • 100% built upon react-native-reanimated and react-native-gesture-handler.
  • Supports Tap & Pan triggering.
  • Support for a discrete slider.
  • Support haptic feedback.
  • and more...

TODO list

  • Support step props
  • Optimize bubble & thumb
  • Rewrite using react-native-gesture-handler v2
  • Support marks props
  • Web Support

Configuration

The <Slider/> component has the following configuration properties:

NameTypeDescriptionRequiredDefault Value
themeobjectThe slider theme color { // Color to fill the progress in the seekbar minimumTrackTintColor: string, // Color to fill the background in the seekbar maximumTrackTintColor: string, // Color to fill the cache in the seekbar cacheTrackTintColor: string, // Color to fill the bubble backgrouundColor disableMinTrackTintColor: string, // Disabled color to fill the progress in the seekbar bubbleBackgroundColor: string // Color to fill the heartbeat animation in the seekbar heartbeatColor: string }
styleViewStyle
borderColorstringColor of the border of the slider, also you can use containerStyle .transparent
bubble(number) => stringGet the current value of the slider as you slide it, and returns a string to be used inside the bubble.(number) => string
progressAnimated.SharedValue<number>Current value of the slider0
cacheAnimated.SharedValue<number>Cache value of the slider0
minimumValueAnimated.SharedValue<number>An Animated.SharedValue from react-native-reanimated library which is the minimum value of the slider.undefined
maximumValueAnimated.SharedValue<number>An Animated.SharedValue from react-native-reanimated library which is the maximum value of the slider.undefined
onSlidingStart() => voidCallback called when the sliding interaction startsundefined
onValueChange(number) => voidCallback called when the slider value changesundefined
onSlidingComplete(number) => voidCallback called when the sliding interaction stops. The updated slider value will be passed as argumentundefined
renderBubble() => React.ReactNodeA custom bubble component that will be rendered while sliding.See the <Bubble/> component
setBubbleText(string) => voidThis function will be called while sliding and can be used to update the text in a custom bubble component.current slider value
bubbleTranslateYnumberValue to pass to the container of the bubble as translateY7
renderThumb() => React.ReactNodeRender custom thumb image. If you need to customize thumb, you also need to set the thumb widthReactNode
renderMark({ index }: { index: number }) => React.ReactNodeRender custom mark element. If you need to customize mark, you also need to set the mark widthReactNode
thumbWidthnumberThumb elements width15
disablebooleanDisable user interaction with the sliderfalse
disableTapEventbooleanEnable tap event change value. Defaults to `true`true
bubbleMaxWidthnumberThe maximum width of the bubble component100
bubbleTextStyleTextStyleBubble text style
bubbleContainerStyleViewStyleBubble container text style
isScrubbingAnimated.SharedValue<boolean>callback slider is scrubbing statusundefined
onTap() => voidA callback for when the slider is tapped.(Useful for video-player scrubbing.)undefined
thumbScaleValueAnimated.SharedValue<number>Control thumb’s transform-scale animation.undefined
sliderHeightnumberThe height of the slider component30
containerStyleViewStylestyles to be applied to the slider container component{ width: '100%', height: 5, borderRadius: 2, borderColor: borderColor, overflow: 'hidden', borderWidth: 1, backgroundColor: maximumTrackTintColor, },
panHitSlopobjectpan gesture hit slop`{ top: 8, left: 0, bottom: 8, right: 0,} `
stepnumber(integer)Step value of the slider. The value should be between 0 and maximumValue - minimumValue)undefined
stepsnumber(integer)Count of segmented sliders.undefined
snapToStepbooleanEnables or disables step snappingtrue
markWidthnumberStep mark width, if you need custom mark style, you must be fix this width4
marksStyleViewStyleStep mark style{width: {markWidth}, height: 4, backgroundColor: '#fff', position: 'absolute', top: 2}
onHapticFeedbackfunctionHaptic feedback callbackundefined
hapticModeenumhaptic feedback modeHapticModeEnum.NONE
panDirectionValueenumCurrent swipe directionundefined
disableTrackFollowbooleanDisable track follow thumb.(Commonly used in video audio players)false
bubbleWidthnumberBubble width, If you set this value, bubble positioning left & right will be clamp.0
activeOffsetXnumber | number[]Range along X axis (in points) where fingers travels without activation of gesture. Moving outside of this range implies activation of gesture.undefined
activeOffsetYnumber | number[]Range along Y axis (in points) where fingers travels without activation of gesture. Moving outside of this range implies activation of gesture.undefined
failOffsetXnumber | number[]When the finger moves outside this range (in points) along X axis and gesture hasn't yet activated it will fail recognizing the gesture. Range can be given as an array or a single numberundefined
failOffsetYnumber | number[]When the finger moves outside this range (in points) along Y axis and gesture hasn't yet activated it will fail recognizing the gesture. Range can be given as an array or a single numberundefined
heartbeatbooleanWhen 'heartbeat' is set to true, the progress bar color will animate back and forth between its current color and the color specified for the heartbeat. useful for loading stateundefined

Keywords

FAQs

Package last updated on 30 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc