Code Monkey home page Code Monkey logo

rn-video-slider's Introduction

rn-video-slider

A dedicated progress slider for video players in React-native.

Demonstration

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}
    />
  )
}

Properties

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

Name Type Required Default Value Description
width number Yes undefined width of slider track
height number No 3 height of slider track
thumbSize number No 12 diameter of sliding thumb
thumbColor string No #FFFFFF color of sliding thumb
progressColor string No #FFFFFF color of progress indicator
bufferProgressColor string No rgba(255,255,255,0.5) color of buffer progress indicator
trackColor string No rgba(255,255,255,0.2) color of underlying view
rootStyle ViewStyle No undefined style addon for root view
isRTL boolean No I18nManager.isRTL overrides direction of movement. setting to "true" makes the slider go from right to left.
tapActive boolean No true activates tap gesture. when set to "true", onSlide function fires on receiving single taps.

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.

Name Params Description
onSlide value Called 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.
onSlideStart value Called when the thumb or track is being tapped or held by touch. It passes the current progress as "value".
onSlideStop value Called 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.

Name Params Description
setProgress value Animates main progress slider based on given value
setColdProgress value Sets main progress level without any animation
setBufferProgress value Sets progress level of the buffer indicator

Note: progress values are a float from 0 to 1

TODO

  • write necessary tests
  • add expansion feature
  • more and better demo gifs
  • 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 period, I decided to remake it.

License

MIT License

rn-video-slider's People

Contributors

armata99 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.