Skip to content

Commit 72fb3e5

Browse files
authored
Merge pull request #22 from chenmo230/master
show方法中添加callback回调
2 parents 6fd5a5f + 88acf7b commit 72fb3e5

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ npm-debug.log*
77
pids
88
*.pid
99
*.seed
10+
.DS_Store
1011

1112
# Directory for instrumented libs generated by jscoverage/JSCover
1213
lib-cov

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ Then you can use it like this:
5757

5858
That's it, you're ready to go!
5959

60+
show a toast, and execute callback function when toast close it:
61+
62+
```javascript
63+
this.refs.toast.show('hello world!', 500, () => {
64+
// something you want to do at close
65+
});
66+
```
67+
6068
Show a toast forever until you manually close it:
6169
```javascript
6270
this.refs.toast.show('hello world!', DURATION.FOREVER);
@@ -148,7 +156,7 @@ textStyle | View.propTypes.style | true | {color:'white'} | Custom style te
148156

149157
Method | Type | Optional | Description
150158
----------------- | -------- | -------- | -----------
151-
show(text, duration) | function | false | show a toast,unit is millisecond
159+
show(text, duration, callback) | function | false | show a toast,unit is millisecond,and do callback
152160
close() | function | - | start the close timer
153161

154162

index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ import {
1717
ViewPropTypes as RNViewPropTypes,
1818
} from 'react-native'
1919

20+
import PropTypes from 'prop-types';
2021
const ViewPropTypes = RNViewPropTypes || View.propTypes;
21-
22-
export const DURATION = {
23-
LENGTH_LONG: 2000,
22+
export const DURATION = {
2423
LENGTH_SHORT: 500,
2524
FOREVER: 0,
2625
};
@@ -39,9 +38,10 @@ export default class Toast extends Component {
3938
}
4039
}
4140

42-
show(text, duration) {
41+
show(text, duration, callback) {
4342
this.duration = typeof duration === 'number' ? duration : DURATION.LENGTH_SHORT;
44-
43+
44+
this.callback = callback;
4545
this.setState({
4646
isShow: true,
4747
text: text,
@@ -78,6 +78,9 @@ export default class Toast extends Component {
7878
isShow: false,
7979
});
8080
this.isShow = false;
81+
if(typeof this.callback === 'function') {
82+
this.callback();
83+
}
8184
});
8285
}, delay);
8386
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"bugs": {
2828
"url": "https://github.com/crazycodeboy/react-native-easy-toast/issues"
2929
},
30+
"dependencies": {
31+
"prop-types": "^15.6.0"
32+
},
3033
"peerDependencies": {
3134
"react-native": ">=0.20.0",
3235
"prop-types": "^15.5.7"

0 commit comments

Comments
 (0)