You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This component has a peer dependency on `react-native-svg`. Read the [full documentation](https://github.com/vydimitrov/react-countdown-circle-timer/tree/master/packages/mobile#react-native-countdown-circle-timer) for the installation guide, as well as demos and use cases.
37
-
38
-
## Demo
39
-
40
-
### React
41
-
42
-
Check the [CodeSandbox](https://codesandbox.io/s/stoic-cache-e7cie?fontsize=14&hidenavigation=1&theme=dark) demo to get started.
Both the React and React Native packages export a hook `useCountdown`, which accepts the same props as the component and returns all props needed to render your own circle.
| duration | number |_required_| Countdown duration in seconds |
103
-
| colors | string \| string[]|_required_|`colors` prop is either:<br> - Single valid color in any format or URL to a gradient<br> - Array of colors in HEX format. At least 2 colors should be provided |
104
-
| colorsTime | number[]| - | Indicates the time when a color should switch to the next color. The first number is the countdown duration and the last one is 0 or goal. Works only when `colors` is an array of HEX colors |
105
-
| isPlaying | boolean | false | Play or pause animation |
106
-
| initialRemainingTime | number | - | Set the initial remaining time if it is different than the duration |
107
-
| updateInterval | number | 0 | Update interval in seconds. Determines how often the timer updates. When set to 0 the value will update on each key frame |
108
-
| size | number | 180 | Width and height of the SVG element |
| trailColor | string | #d9d9d9 | Circle trail color - takes any valid color format |
114
-
| isSmoothColorTransition | boolean | true | Indicates if the colors should smoothly transition to the next color |
115
-
| children | (props: { remainingTime: number, elapsedTime: number, color: string }) => ReactNode | - | Render function to customize the time/content in the center of the circle |
| onUpdate | (remainingTime: number) => void | - | On remaining time update event handler |
118
-
119
-
## Browser support
120
-
121
-
The component and hook support [all modern browsers](https://caniuse.com/?search=es6) targeting `es6`. Internet Explorer (IE) is not longer supported.
122
-
123
-
## Recipes
124
-
125
-
### Changing `duration` prop
126
-
127
-
Once the component is mounted the `duration` prop can be changed the the timer will respect the new duration. In case the new duration is bigger than the previous one then the timer will continue to the new duration. In case the new duration is smaller then the previous one then the timer will ne over. If you want to restart the timer when the duration changes then pass a new `key` prop to `CountdownCircleTimer` component and the timer will start over with the new values provided.
128
-
129
-
### Restart/Reset timer at any given time
130
-
131
-
Pass a `key` prop to `CountdownCircleTimer` and change the `key` when the timer should be restarted. Check [this demo](https://codesandbox.io/s/tender-bogdan-qd35m) to find out one possible implementation.
132
-
133
-
### Repeat timer when countdown is completed
134
-
135
-
Return an object from `onComplete` handler, which indicates if the animation should be repeated. Example:
### Set the initial remaining time different then the duration provided
152
-
153
-
Pass the remaining time to `initialRemainingTime` prop. Example:
154
-
155
-
```jsx
156
-
constUrgeWithPleasureComponent= () => (
157
-
<CountdownCircleTimer
158
-
isPlaying
159
-
duration={60}
160
-
initialRemainingTime={15}
161
-
colors="#A30000"
162
-
/>
163
-
)
164
-
```
165
-
166
-
In the example above, the countdown will start at 15 seconds (one quarter before it's done) and it will animate for 15 seconds until reaches 0.
167
-
168
-
### Time formatting functions
169
-
170
-
`children` prop of `CountdownCircleTimer` component will receive as a prop `remainingTime` in seconds. Below are a few functions that can be used to get different time formatting:
- Wrapper the timer in an element and add the following attribute `aria-label={your-aria-label}`
200
-
- Add the following element with `role="timer"` to your `children` function that will make the screen reader read the remaining time while the timer is running.
201
-
202
-
```jsx
203
-
constchildren= ({ remainingTime }) => (
204
-
<div role="timer" aria-live="assertive">
205
-
{remainingTime} seconds
206
-
</div>
207
-
)
208
-
```
209
-
210
-
#### React Native
211
-
212
-
- Wrapper the timer in an `View` element and add the following attributes `accessible={true} accessibilityLabel={your-aria-abel}`
213
-
- Add the following `Text` element to your `children` function that will make the screen reader read the remaining time while the timer is running.
214
-
215
-
```jsx
216
-
constchildren= ({ remainingTime }) => (
217
-
<Text
218
-
accessibilityRole="timer"
219
-
accessibilityLiveRegion="assertive"
220
-
importantForAccessibility="yes"
221
-
>
222
-
{remainingTime} seconds
223
-
</Text>
224
-
)
225
-
```
226
-
227
-
### Add gradient
228
-
229
-
Define the SVG gradient outside the Timer component and pass the gradient ID to the Timer component as a single color:
Check the [CodeSandbox](https://codesandbox.io/s/silly-night-d3s70?fontsize=14&hidenavigation=1&theme=dark) demo to find out how you can implement it yourself
:zap: Performance optimized with single `requestAnimationFrame` loop to animate color and progress
13
15
:rainbow: Transition between colors during the countdown
14
16
:european_castle: Fully customizable content in the center of the circle
15
17
:rocket: Support iOS and Android
16
18
17
-
## Installation
19
+
## Install
18
20
19
21
```
20
22
yarn add react-native-countdown-circle-timer
21
23
```
22
24
23
25
This component has a peer dependency on `react-native-svg` to draw the countdown circle. `react-native-svg` has to be installed and linked into your project.
24
26
25
-
## Demo
27
+
## Usage
26
28
27
29
### Component
28
30
@@ -90,7 +92,7 @@ const {
90
92
91
93
Once the component is mounted the `duration` prop can be changed the the timer will respect the new duration. In case the new duration is bigger than the previous one then the timer will continue to the new duration. In case the new duration is smaller then the previous one then the timer will ne over. If you want to restart the timer when the duration changes then pass a new `key` prop to `CountdownCircleTimer` component and the timer will start over with the new values provided.
92
94
93
-
### Restart/Reset timer at any given time
95
+
### Restart timer at any given time
94
96
95
97
Pass a `key` prop to `CountdownCircleTimer` and change the `key` when the timer should be restarted. Check [this demo](https://codesandbox.io/s/tender-bogdan-qd35m) to find out one possible implementation.
96
98
@@ -187,6 +189,6 @@ Define the SVG gradient outside the Timer component and pass the gradient ID to
:zap: Performance optimized with single `requestAnimationFrame` loop to animate color and progress
13
15
:rainbow: Transition between colors during the countdown
14
16
:european_castle: Fully customizable content in the center of the circle
15
17
16
-
## Installation
18
+
## Install
17
19
18
20
```
19
21
yarn add react-countdown-circle-timer
20
22
```
21
23
22
-
## Demo
24
+
## Usage
23
25
24
26
### Component
25
27
@@ -90,7 +92,7 @@ The component and hook support [all modern browsers](https://caniuse.com/?search
90
92
91
93
Once the component is mounted the `duration` prop can be changed the the timer will respect the new duration. In case the new duration is bigger than the previous one then the timer will continue to the new duration. In case the new duration is smaller then the previous one then the timer will ne over. If you want to restart the timer when the duration changes then pass a new `key` prop to `CountdownCircleTimer` component and the timer will start over with the new values provided.
92
94
93
-
### Restart/Reset timer at any given time
95
+
### Restart timer at any given time
94
96
95
97
Pass a `key` prop to `CountdownCircleTimer` and change the `key` when the timer should be restarted. Check [this demo](https://codesandbox.io/s/tender-bogdan-qd35m) to find out one possible implementation.
0 commit comments