|
| 1 | +# react-native-circular-slider :radio_button: |
| 2 | + |
| 3 | +React Native component for creating circle slider. |
| 4 | + |
| 5 | +## Example app – inspired by Apple's Bedtime :alarm_clock: |
| 6 | +(It's just an example what you can achieve – with this package you can create any circular slider) |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +1. Install library and react-native-svg |
| 13 | + |
| 14 | + ``` |
| 15 | + npm i --save react-native-circular-slider react-native-svg |
| 16 | + ``` |
| 17 | +2. Link native code for SVG |
| 18 | + |
| 19 | + ``` |
| 20 | + react-native link react-native-svg |
| 21 | + ``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +Import Circle Slider |
| 26 | + |
| 27 | +```js |
| 28 | +import { CircularSlider } from 'react-native-circular-slider'; |
| 29 | +``` |
| 30 | + |
| 31 | +Use as follows: |
| 32 | + |
| 33 | +```jsx |
| 34 | +<CircularSlider |
| 35 | + startAngle={this.state.startAngle} |
| 36 | + angleLength={this.state.angleLength} |
| 37 | + onUpdate={({ startAngle, angleLength }) => this.setState({ startAngle, angleLength })} |
| 38 | + segments={5} |
| 39 | + strokeWidth={40} |
| 40 | + radius={145} |
| 41 | + gradientColorFrom="#ff9800" |
| 42 | + gradientColorTo="#ffcf00" |
| 43 | + showClockFace |
| 44 | + clockFaceColor="#9d9d9d" |
| 45 | + bgCircleColor="#171717" |
| 46 | + stopIcon={<G><Path .../></G>} |
| 47 | + startIcon={<G><Path .../></G>} |
| 48 | +/> |
| 49 | +``` |
| 50 | + |
| 51 | + |
| 52 | +## Configuration |
| 53 | + |
| 54 | +You can configure the passing by following props: |
| 55 | + |
| 56 | +- **startAngle** – angle where the slider starts (from 0 to 2π) |
| 57 | +- **angleLength** - length of the slider (from 0 to 2π) |
| 58 | +- **onUpdate({ startAngle, angleLength })** - when slider is moved, onUpdate(data) is triggered, where data is an object of new values of startAngle and angleLength. |
| 59 | +- **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. |
| 60 | +- **strokeWidth (optional)** - width of slider |
| 61 | +- **radius (optional)** - size of the slider |
| 62 | +- **gradientColorFrom (optional)** - initial gradient color |
| 63 | +- **gradientColorTo (optional)** - final gradient color |
| 64 | +- **showClockFace (optional)** - if component should render clock face |
| 65 | +- **bgCircleColor (optional)** - color of the circle under the slider (pathway for a slider) |
| 66 | +- **stopIcon (optional)** - SVG Path for a stop icon (see the example) |
| 67 | +- **startIcon (optional)** - SVG Path for a start icon (see the example) |
| 68 | + |
| 69 | + |
| 70 | +## Working example app |
| 71 | + |
| 72 | +You can find working example in the `example` directory of this repository. You can run it by: |
| 73 | + |
| 74 | +```sh |
| 75 | +git clone https://github.com/bgryszko/react-native-circular-slider.git |
| 76 | +cd react-native-circular-slider/example/Bedtime |
| 77 | +npm install |
| 78 | +open ios/Bedtime.xcodeproj |
| 79 | +``` |
| 80 | +XCode will open. Click Run button and that's it. |
| 81 | + |
| 82 | + |
| 83 | +## License |
| 84 | + |
| 85 | +MIT |
0 commit comments