Giter Club home page Giter Club logo

react-native-circular-slider's Introduction

license Version Twitter Follow

react-native-circular-slider 🔘

React Native component for creating circular slider.

Example app – inspired by Apple's Bedtime ⏰

(It's just an example what you can achieve – with this package you can create any circular slider)

image

Installation

  1. Install library and react-native-svg

    npm i --save react-native-circular-slider react-native-svg
    
  2. Link native code for SVG

    react-native link react-native-svg
    

Usage

Import Circular Slider

import CircularSlider from 'react-native-circular-slider';

Use as follows:

<CircularSlider
  startAngle={this.state.startAngle}
  angleLength={this.state.angleLength}
  onUpdate={({ startAngle, angleLength }) => this.setState({ startAngle, angleLength })}
  segments={5}
  strokeWidth={40}
  radius={145}
  gradientColorFrom="#ff9800"
  gradientColorTo="#ffcf00"
  showClockFace
  clockFaceColor="#9d9d9d"
  bgCircleColor="#171717"
  stopIcon={<G><Path .../></G>}
  startIcon={<G><Path .../></G>}
/>

Configuration

You can configure the passing by following props:

  • startAngle – angle where the slider starts (from 0 to 2π)
  • angleLength - length of the slider (from 0 to 2π)
  • onUpdate({ startAngle, angleLength }) - when slider is moved, onUpdate(data) is triggered, where data is an object of new values of startAngle and angleLength.
  • segments (optional) - SVG doesn't support canonical gradients, so it's imitated by using multiple linear gradients across the slider. In most cases 5 should be fine.
  • strokeWidth (optional) - width of slider
  • radius (optional) - size of the slider
  • gradientColorFrom (optional) - initial gradient color
  • gradientColorTo (optional) - final gradient color
  • showClockFace (optional) - if component should render clock face
  • bgCircleColor (optional) - color of the circle under the slider (pathway for a slider)
  • stopIcon (optional) - SVG Path for a stop icon (see the example)
  • startIcon (optional) - SVG Path for a start icon (see the example)

Working example app

With XCode

You'll find working example in the example directory of this repository. You can run it by:

git clone https://github.com/bgryszko/react-native-circular-slider.git
cd  react-native-circular-slider/example/Bedtime
npm install
open ios/Bedtime.xcodeproj

XCode will open. Click Run button and that's it.

With Exponent

The easiest way to run it is with Exponent: https://getexponent.com/@community/bedtime

If you'd rather build it locally, follow these steps:

  1. Download XDE
  2. Clone the repo and install dependencies
git clone https://github.com/bgryszko/react-native-circular-slider.git
cd  react-native-circular-slider/example-exponent/Bedtime
npm install
  1. Open the project with XDE

Author

Bartosz Gryszko ([email protected])

For new components and updates follow me on twitter.

License

MIT

react-native-circular-slider's People

Contributors

asdafers avatar bartgryszko avatar brentvatne avatar seratonik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-circular-slider's Issues

Unable to use in expo go

I'm developing react native app using expo environment but after installing this package & using it, this error comes into the picture:

Invariant Violation: "RestApp" has not been registered. This can happen if:

  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
  • A module failed to load due to an error and AppRegistry.registerComponent wasn't called.

Cannot read property 'number' of undefined

React Native Environment Info:
    System:
      OS: Linux 4.15 Ubuntu 18.04.2 LTS (Bionic Beaver)
      CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
      Memory: 2.32 GB / 11.63 GB
      Shell: 5.4.2 - /bin/zsh
    Binaries:
      Node: 8.10.0 - /usr/bin/node
      Yarn: 1.17.3 - /usr/bin/yarn
      npm: 3.5.2 - /usr/bin/npm
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.8 => 0.59.8 
    npmGlobalPackages:
      react-native-cli: 2.0.1
import CircularSlider from 'react-native-circular-slider';

image

Touch responsiveness of slider inaccurate after navigating to component using React Navigation

It seems that the circular slider is not registering the correct location of my presses only when the component is mounted after being navigated to using react-navigation. I was able to identify the issue as being the px value obtained by this._circle.measure in setCircleCenter() of the CircularSlider component. The value of px is different if the component is loaded normally versus if it navigated to using react-navigation. In order to solve this, I simply hardcoded the value for px with the value that is obtained when the component loads normally. However, I am not sure if this solution is going to scale well. Does anyone know of any other solution to this problem that I can attempt? Thanks!

Cant use other icon images?

Hi,
I tried using
stopIcon = require('../Images/img1.png') startIcon = require('../Images/img1.png')
but that gives an error. Probably because they are non-SVG images. Any fix for that? To use normal images there?

Also, your component is too exposed. I cant just use the main tags and start using it. I have to import those math functions along. It would be better if you subdivide it in such a way that a user can just use your component tags and give it his wanted values and start using it.
All the angle calculation should be behind the doors as well and the onUpdate function should just be a callback to change something else in the app and not run the basic working of the component itself.

Awesome component btw, really need to use it in my next project. I would be really glad and thankful if you could improve these functionalities.

Slider doesn't accurately react to touch.

I was messing around with the slider code and noticed that often when you are moving it around the circle it will not properly adjust itself to the exact position it should be in.

Images below show the error being reproduced in an android emulator and i have also tried compiling to native android and running again, still the same issue.

Basically what is happening is that at 12 o'clock the button correctly follows the mouse movements but as i move around the circle it does not perfectly follow the touch position onscreen. i feel this is a maths error since it starts correctly at the 12 position and ill be diving into trying to fix the issue myself after i do some other work but i thought id run it past here in case i can get a nice point to somewhere to start, anything is appreciated.

The red lines in the images are the mouse position. All the movements in the screenshots are counter clockwise bar the 12 0'clock position image so you can tell where the onTouchEnd position is.

screen shot 2017-08-14 at 09 32 39
screen shot 2017-08-14 at 09 32 58
screen shot 2017-08-14 at 09 33 04
screen shot 2017-08-14 at 09 33 15
screen shot 2017-08-14 at 09 33 56

update needed

Hi,
can you update it to latest version of react native ? we got many warn and errors when using current version .

thanks

[Android] Error while updating property 'd' in shadow node of type: RNSVGPath

I tried the example app in Android (copy index.ios.js & paste into index.android.js) and after touching the slider it throws an error described below.
circular-slider

Error while updating property 'd' in shadow node of type: RNSVGPath
updateShadowNodeProp
ViewManagersPropertyCache.java:110
setProperty
ViewManagerPropertyUpdater.java:148
updateProps
ViewManagerPropertyUpdater.java:52
updateProperties
ReactShadowNode.java:246
updateView
UIImplementation.java:216
updateView
UIManagerModule.java:245
invoke
Method.java:-2
invoke
BaseJavaModule.java:318
invoke
JavaModuleWrapper.java:158
run
NativeRunnable.java:-2
handleCallback
Handler.java:739
dispatchMessage
Handler.java:95
dispatchMessage
MessageQueueThreadHandler.java:31
loop
Looper.java:148
run
MessageQueueThreadImpl.java:196
run
Thread.java:818

Become a maintainer of this package

I'll be happy accept help maintaining this package & give write rights to people that would like to help fixing recent bugs / updating package to the newest react / native version, reviewing and merging PRs etc.

Feature Request: Change Color of Start/Stop circles

Thanks for this great component.

I would love to have a prop to set the color of the start/stop circles. This way they don't have to be the same color as the background circle.

Happy to submit a PR if it would help

Full 2*PI clockwise position : the circle is not colored

Hello,
For the circle, I managed to set a max value and a step value.
If i push the end thumb to the end of the circle (max value : 2*PI), the gradient is null even if the angle is not 0.

screen

Is there a way to push the gradient up to the max value?

Press events do not fire on Android

I think it's really a react-native svg issue [363] (software-mansion/react-native-svg#363) but thought I would leave it here since I tried this out on Android Nexus 5X and no touch events are captured by the component. If you put a breakpoint in CircularSlider.js (line 238 or so) in the G for either of the ends you will see that PressIn handler is never fired.

RN version 47, Expo version 19

Slider does not respond using ScrollView

Thank you for this great component!
I would like to integrate it within a ScrollView, unfortunately I cannot slide the slider anymore after doing that.

Thank you for you help!

How to animate the circular progress to be full after one minute

i am using this function to change the this.state.timeLoader2 with setState
but the problem is on every device its acting different
i need to animate the circular progress like a loader to be full after one minute

      startCircleAnimation(number,stop) {
         if (number > 920 || stop > 9200) {
            return
        }
        Animated.timing(this.state.timeLoader, {
            toValue: totalTime / 920 * number,
            duration: 50,

        }).start(() => {

            this.setState({
                timeLoader2: this.state.timeLoader._value
            }, () => {
                this._startCircleAnimation(number + 1, stop + 10)
            });

        })
    }
 <CircularProgress
                        startAngle={0}
                        angleLength={this.state.timeLoader2}
                        segments={5}
                        strokeWidth={3}
                        radius={calcSize(100)}
                        gradientColorFrom="#2A818E"
                        gradientColorTo="#30ABA5"
                        onUpdate={({startAngle, angleLength}) => console.log(startAngle, angleLength)}
                        clockFaceColor="#9d9d9d"
                        bgCircleColor="#D3D3D3"
/>

any idea how to accomplish that ? thanks !

How can I limit the travel range of an icon?

I'm trying to repurpose the circular slider as a temperature thermostat. Is there a way I can limit the travel of one icon to only traveling along a half circle? Or better yet that only a half of a bgCircle gets rendered?

Project status ?

There is many old issues and the package isn't updated to the latest version of react-native causing a lot of problems

is the project dead ?

The example app with Exponent cannot be found!!!

I've tried to run the example app with Exponent , either by scanning QR code or by typing exp://exp.host/@community/bedtime inside of Expo.
But unfortunately the example app seems not compatible with the latest version of Exponent(SDK versions 14.0.0+)

Ticks do not line up correctly with numbers

Hi all the functionality works for the slider however the ticks do not line up with the numbers as seen here. Was wondering why in the demo photo they were but here they are not.
Thanks Afshawn

Simulator Screen Shot - iPhone Xʀ - 2019-07-19 at 12 45 31

Example not working

When I follow the instructions on the example I get a red screen and:
undefined is not an object (evaluating 'RNFSManager.RNFSFileTypeRegular')

24 Hour Option?

From what I can tell it's limited to a maximum of 12 hour time range, correct?

If so, have you thought about allowing up to 24 hours?

I'm a little worried with what that would do to the aesthetic, but I thought I'd post here and get the discussion going a little bit.

Suport for typescript

I recommend support for typescript, in my experience, I tried to use it, but I was not successful.

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.