Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ import Counter from 'react-native-counter';
/>
```

# Reset from parent view

```javascript
import Counter from 'react-native-counter';

<Counter
...
ref={counter => this.counter = counter}
/>

// Example method restarting the counter
resetCounter() {
this.counter.reset();
}
```

The easing prop is a string corresponding to one of any function from [eases](https://github.com/mattdesl/eases).

# License
Expand Down
13 changes: 13 additions & 0 deletions src/Counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,23 @@ export default class Counter extends Component {

componentDidMount() {
this.startTime = Date.now();
this.umount = false
requestAnimationFrame(this.animate.bind(this));
}

componentWillUnmount() {
this.umount = true
}

reset() {
this.startTime = Date.now();
this.stop = false
requestAnimationFrame(this.animate.bind(this));
}

animate() {
if(this.umount) return;

const { onComplete } = this.props;

if (this.stop) {
Expand Down