0.5.1 • Published 7 months ago

rn-video-slider v0.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

rn-video-slider

A dedicated progress slider for video player's custom user interfaces in React-Native. It can also be used in audio players because why not? 😎

Why this module?

  • superior performance thanks to Reanimated library
  • clean and simple implementation that makes it easy to extend
  • integrated buffer indicator for online streams
  • fully written in Typescript
  • easiest way to use
  • RTL support

Installation

This module uses react-native-reanimated and react-native-gesture-handler as peer dependencies. make sure You have installed them correctly. You may also install react-native-video. Check out these links to proceed their installation process:

Once you are done with above, add the main package with one of below commands:

using npm

npm i rn-video-slider

using yarn

yarn add rn-video-slider

That will be it.

Usage

import {Dimensions} from "react-native";
import Slider, {ISlider} from "rn-video-slider";

const ControlSet = () => {

  const sliderRef = React.createRef<ISlider>();
  //call below function in video progress callback
  //sliderRef.current?.setProgress(0.5);

  const _onSlide = (value: number) => {
    //seek your video with value
  };
  
  //this simply means 80% of screen's width
  const sliderWdith = Dimensions.get('window').width * 0.8;

  return (
    <Slider
      ref={sliderRef}
      width={sliderWdith}
      onSlide={_onSlide}
    />
  )
}

Note: You can see the Component in action by cloning this repo and building its test app. Just head over to testapp directory, install the dependencies and run it on Android or IOS.

Properties

Here is the list of properties that you can set or override.

NameTypeRequiredDefault ValueDescription
widthnumberYesundefinedwidth of slider track
heightnumberNo3height of slider track
thumbSizenumberNo12diameter of sliding thumb
thumbColorstringNo#FFFFFFcolor of sliding thumb
progressColorstringNo#FFFFFFcolor of progress indicator
bufferProgressColorstringNorgba(255,255,255,0.5)color of buffer progress indicator
trackColorstringNorgba(255,255,255,0.2)color of underlying view
rootStyleViewStyleNoundefinedstyle addon for root view
isRTLbooleanNoI18nManager.isRTLoverrides direction of movement. setting to "true" makes the slider go from right to left.
tapActivebooleanNotrueactivates tap gesture. when set to "true", onSlide function fires on receiving single taps.
initialProgressnumberNo0sets the initial progress value.
bufferInitialProgressnumberNo0sets the initial buffer progress value.

Note: Root view has a default padding equal to 10. Override it in root style if you need to.

Callbacks properties

Here is the list of callbacks to use.

NameParamsDescription
onSlidevalueCalled when the slider is being moved by receiving a pan or tap gesture. It passes a "value" which is a number that changes from 0 to 1.
onSlideStartvalueCalled when the thumb or track is being tapped or held by touch. It passes the current progress as "value".
onSlideStopvalueCalled when the thumb or track is released. It passes the current progress as "value".

Methods

Here is the list of methods that can be called via reference.

NameParamsDescription
setProgressvalueAnimates main progress slider based on given value
setColdProgressvalueSets main progress level without any animation
setBufferProgressvalueSets progress level of the buffer indicator

Note: progress values are a float from 0 to 1

Known issues

Tapping the Slider on Android will cause it to bounce back and forward sometimes. I've seen this issue being reported in community as well, yet I haven't found a certain solution to fix it. It's also not clear to me that whether it should be fixed at this side or Exoplayer's side.

TODO list

  • workaround bouncing issue on Android (maybe)
  • add hovering bubble feature
  • add in-code docs
  • ensure fabric support
  • more and better demo gifs
  • cleanups and refactors
  • bump test-app dependencies up
  • write a better example
  • fix delay between thumb and track while sliding fast
  • implement tap to seek feature
  • replace the deprecated useAnimatedGestureHandler with newer API
  • add style prop for root view

Contributions

If you have any idea to improve or fix something, open an issue and state it in details. You will always be welcomed.

Compatability

  • react-native-reanimated: 2.x, 3.x
  • react-native-gesture-handler: 2.x

Acknowledgement

The idea behind this is from react-native-reanimated-slider. Since the mentioned module is written with Reanimated v1 API, and hasn't been updated for a long time, I decided to remake it.

License

MIT License

0.5.0

7 months ago

0.5.1

7 months ago

0.4.1

10 months ago

0.3.2

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

2 years ago